Skip to content

Commit

Permalink
add new STI response
Browse files Browse the repository at this point in the history
  • Loading branch information
thehung111 committed Apr 12, 2023
1 parent e6cde82 commit 0b13555
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 12 deletions.
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
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
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 0b13555

Please sign in to comment.