Skip to content

Commit

Permalink
Merge pull request #48 from visenze/feature/sti
Browse files Browse the repository at this point in the history
[API-9128] Support new STI response fields
  • Loading branch information
thehung111 authored Apr 12, 2023
2 parents e7620cc + 0b13555 commit e51637b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 22 deletions.
8 changes: 4 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 345PN8HV64;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.2;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -722,11 +722,11 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 19;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 345PN8HV64;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.2;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This SDK contains two sets of APIs that provide accurate, reliable and scalable

For source code and references, please visit the [Github Repository](https://github.com/visenze/visearch-sdk-swift).

> Current stable version: `1.8.7` (Swift 5+)
> Current stable version: `1.9.2` (Swift 5+)
>
> Supported iOS version: iOS 8.x and higher
Expand Down Expand Up @@ -112,7 +112,7 @@ platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'ViSearchSDK', '~>1.8.6'
pod 'ViSearchSDK', '~>1.9.2'
end
...
```
Expand Down
2 changes: 1 addition & 1 deletion ViSearchSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|


s.name = "ViSearchSDK"
s.version = "1.9.0"
s.version = "1.9.2"
s.summary = "A Visual Search API solution (Swift SDK)"

s.description = <<-DESC
Expand Down
8 changes: 4 additions & 4 deletions ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 17;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = NKN6QECX9M;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -632,7 +632,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.2;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -645,7 +645,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 17;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = NKN6QECX9M;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -663,7 +663,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.2;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ open class ViProductObjectResult {
public var total: Int? = nil

public var result: [ViProduct] = []

public var id: String?
public var category: String?
public var name: String?
public var facets : [ViFacet] = []
public var excludedPids: [String] = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ open class ViProductSearchResponse : NSObject {
object.result = ViProductSearchResponse.parseProductResults(res)
}

object.id = dict["id"] as? String
object.category = dict["category"] as? String
object.name = dict["name"] as? String

if let excludedPidList = dict["excluded_pids"] as? [String] {
object.excludedPids = excludedPidList
}

if let facetListJson = dict["facets"] as? [Any] {
object.facets = ViResponseData.parseFacets(facetListJson)
}

results.append(object)
}
}
Expand Down
6 changes: 6 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViObjectResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ open class ViObjectResult: NSObject {
public var result: [ViImageResult] = []
public var facets : [ViFacet] = []

public var id: String?
public var category: String?
public var name: String?
public var excludedImNames: [String] = []


public init(type: String) {
self.type = type
}
Expand Down
9 changes: 9 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ open class ViResponseData: NSObject {
item.facets = ViResponseData.parseFacets(facetListJson)
}

item.id = dict["id"] as? String
item.category = dict["category"] as? String
item.name = dict["name"] as? String

if let excludedImNameList = dict["excluded_im_names"] as? [String] {
item.excludedImNames = excludedImNameList
}


results.append(item)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class ViSearchClient: NSObject, URLSessionDelegate {
public var timeoutInterval : TimeInterval = 10 // how long to timeout request
public var requestSerialization: ViRequestSerialization

public var userAgent : String = "visearch-swift-sdk/1.9.0"
public var userAgent : String = "visearch-swift-sdk/1.9.2"
public static let userAgentHeader : String = "X-Requested-With"

// whether to authenticate by appkey or by access/secret key point
Expand Down
105 changes: 95 additions & 10 deletions ViSearchSDK/ViSearchSDKTests/ViProductObjectResultTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,61 @@ class ViProductObjectResultTest: XCTestCase {
"attributes": {},
"total": 985,
"result": [
{
"product_id": "POMELO2-AF-SG_b28d580ccf5dfd999d1006f15f773bb371542559",
"main_image_url": "http://d3vhkxmeglg6u9.cloudfront.net/img/p/2/2/1/8/0/6/221806.jpg",
"data": {
"link": "https://iprice.sg/r/p/?_id=b28d580ccf5dfd999d1006f15f773bb371542559",
"product_name": "Skrrrrt Cropped Graphic Hoodie Light Grey",
"sale_price": {
"currency": "SGD",
"value": "44.0"
{
"product_id": "POMELO2-AF-SG_b28d580ccf5dfd999d1006f15f773bb371542559",
"main_image_url": "http://d3vhkxmeglg6u9.cloudfront.net/img/p/2/2/1/8/0/6/221806.jpg",
"data": {
"link": "https://iprice.sg/r/p/?_id=b28d580ccf5dfd999d1006f15f773bb371542559",
"product_name": "Skrrrrt Cropped Graphic Hoodie Light Grey",
"sale_price": {
"currency": "SGD",
"value": "44.0"
}
}
}
}
]
}]
""";

private let STI_RESPONSE: String = """
[{
"id": "b0eedf870030ebb7ec637cd2641d0591",
"category": "eyewear",
"box": [
54,
55,
200,
200
],
"total": 111,
"result": [
{
"product_id": "pid1",
"main_image_url": "http://test.jpg",
"pinned" : "true",
"data": {
"link": "https://liink.com",
"product_name": "test name",
"sale_price": {
"currency": "SGD",
"value": "43.0"
}
},
"vs_data" : {
"index_filter.product_tagging" : "others",
"detect" : "glass"
}
}
],
"excluded_pids" : ["pid2", "pid3"],
"facets" : [
{
"key": "category",
"items" : [
{"value" : "Women > Women's Dresses"}
]
}
]
}]
""";
Expand Down Expand Up @@ -80,4 +123,46 @@ class ViProductObjectResultTest: XCTestCase {
XCTAssertEqual(value, "44.0")
}

func testParseSti() {
let results = ViProductSearchResponse.parseObjectResults(STI_RESPONSE)

XCTAssertEqual(results.isEmpty, false)
XCTAssertNotNil(results[0])
XCTAssertEqual(results[0].category, "eyewear")

XCTAssertEqual(results[0].box!.x1, 54)
XCTAssertEqual(results[0].box!.y1, 55)
XCTAssertEqual(results[0].box!.x2, 200)
XCTAssertEqual(results[0].box!.y2, 200)
XCTAssertEqual(results[0].total, 111)
XCTAssertEqual(results[0].result.count, 1)
XCTAssertEqual(results[0].result[0].productId, "pid1")
XCTAssertEqual(results[0].result[0].mainImageUrl, "http://test.jpg")

let data = results[0].result[0].data

let link = data["link"] as! String
XCTAssertEqual(link, "https://liink.com")

let productName = data["product_name"] as! String
XCTAssertEqual(productName, "test name")

let price = data["sale_price"] as! Dictionary<String,String>

let currency = price["currency"]
XCTAssertEqual(currency, "SGD")

let value = price["value"]
XCTAssertEqual(value, "43.0")

let vsData = results[0].result[0].vsData
XCTAssertEqual("others", vsData["index_filter.product_tagging"] as! String)
XCTAssertEqual("glass", vsData["detect"] as! String)

XCTAssertEqual(2, results[0].excludedPids.count)
XCTAssertEqual("pid2", results[0].excludedPids[0])
XCTAssertEqual("pid3", results[0].excludedPids[1])

}

}

0 comments on commit e51637b

Please sign in to comment.