From c83877c2546206c7e2f9c7cb74bd5669dccc98ef Mon Sep 17 00:00:00 2001 From: Hung Date: Tue, 7 Mar 2023 14:19:42 +0800 Subject: [PATCH 1/4] bump version --- ViSearchSDK.podspec | 2 +- ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj | 8 ++++---- ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ViSearchSDK.podspec b/ViSearchSDK.podspec index 15a4d72..40f93d0 100644 --- a/ViSearchSDK.podspec +++ b/ViSearchSDK.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.name = "ViSearchSDK" - s.version = "1.8.7" + s.version = "1.9.0" s.summary = "A Visual Search API solution (Swift SDK)" s.description = <<-DESC diff --git a/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj b/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj index 8b0d1a6..5dfb738 100644 --- a/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj +++ b/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj @@ -610,7 +610,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = ""; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = NKN6QECX9M; DYLIB_COMPATIBILITY_VERSION = 1; @@ -628,7 +628,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.8.7; + MARKETING_VERSION = 1.9.0; PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -641,7 +641,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = ""; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = NKN6QECX9M; DYLIB_COMPATIBILITY_VERSION = 1; @@ -659,7 +659,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.8.7; + MARKETING_VERSION = 1.9.0; PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift b/ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift index fcdfdf7..a8a4335 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift @@ -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.8.6" + public var userAgent : String = "visearch-swift-sdk/1.9.0" public static let userAgentHeader : String = "X-Requested-With" // whether to authenticate by appkey or by access/secret key point From 459a321c326576ae211f3ac45df92c433373475b Mon Sep 17 00:00:00 2001 From: Hung Date: Tue, 7 Mar 2023 14:23:48 +0800 Subject: [PATCH 2/4] add show_best_product_images param --- .../Classes/Request/ProductSearch/ViSeachByIdParam.swift | 7 +++++++ ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/ViSearchSDK/ViSearchSDK/Classes/Request/ProductSearch/ViSeachByIdParam.swift b/ViSearchSDK/ViSearchSDK/Classes/Request/ProductSearch/ViSeachByIdParam.swift index a5c0019..aebd732 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Request/ProductSearch/ViSeachByIdParam.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Request/ProductSearch/ViSeachByIdParam.swift @@ -29,6 +29,8 @@ open class ViSearchByIdParam : ViBaseProductSearchParam { public var setLimit: Int? + public var showBestProductImages: Bool? = nil + /// Constructor, checks for non-empty productId /// /// - parameter productId: Product's ID, retrieved from ViProduct if prior search was made @@ -76,6 +78,11 @@ open class ViSearchByIdParam : ViBaseProductSearchParam { dict["set_limit"] = String(setLimit) } + if let showBestProductImages = showBestProductImages { + dict["show_best_product_images"] = showBestProductImages ? "true" : "false" + } + + return dict } } diff --git a/ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift b/ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift index 3b6866e..c67d501 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift @@ -23,6 +23,7 @@ public class ViRecParams: ViSearchParams { public var setLimit: Int? + public var showBestProductImages: Bool? = nil public override init?(imName: String) { super.init(imName: imName) @@ -59,6 +60,10 @@ public class ViRecParams: ViSearchParams { dict["set_limit"] = String(setLimit) } + if let showBestProductImages = showBestProductImages { + dict["show_best_product_images"] = showBestProductImages ? "true" : "false" + } + return dict; } From 3916f5db28754a20ec805cce3b6bcd2b41b8b2ab Mon Sep 17 00:00:00 2001 From: Hung Date: Tue, 7 Mar 2023 14:48:01 +0800 Subject: [PATCH 3/4] add best image response --- Example/Example.xcodeproj/project.pbxproj | 14 +++++------ .../ViSearchSDK.xcodeproj/project.pbxproj | 4 ++++ .../Response/ProductSearch/ViProduct.swift | 2 ++ .../ViProductSearchResponse.swift | 4 ++++ .../Classes/Response/ViBestImage.swift | 15 ++++++++++++ .../Classes/Response/ViImageResult.swift | 2 ++ .../Classes/Response/ViResponseData.swift | 23 +++++++++++++++++++ 7 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 927ad3c..bc3aded 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -416,7 +416,7 @@ TargetAttributes = { BDCA2E0E1DA38B7B004C2EF7 = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = NKN6QECX9M; + DevelopmentTeam = 345PN8HV64; LastSwiftMigration = 1030; ProvisioningStyle = Automatic; }; @@ -706,11 +706,11 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CURRENT_PROJECT_VERSION = 18; - DEVELOPMENT_TEAM = NKN6QECX9M; + CURRENT_PROJECT_VERSION = 19; + DEVELOPMENT_TEAM = 345PN8HV64; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.8.7; + MARKETING_VERSION = 1.9.0; PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -722,11 +722,11 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CURRENT_PROJECT_VERSION = 18; - DEVELOPMENT_TEAM = NKN6QECX9M; + CURRENT_PROJECT_VERSION = 19; + DEVELOPMENT_TEAM = 345PN8HV64; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.8.7; + MARKETING_VERSION = 1.9.0; PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj b/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj index 5dfb738..75bf52e 100644 --- a/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj +++ b/ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ BD06D1361DA3BDE600EC9B38 /* ViResponseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD06D1351DA3BDE600EC9B38 /* ViResponseData.swift */; }; BD06D1381DA3F59A00EC9B38 /* ViRequestSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD06D1371DA3F59A00EC9B38 /* ViRequestSerialization.swift */; }; + BD283ABB29B7101600912D82 /* ViBestImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD283ABA29B7101600912D82 /* ViBestImage.swift */; }; BD3A860125F22B6400BB71CF /* ViProductSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD3A860025F22B6400BB71CF /* ViProductSearch.swift */; }; BD50FD621DA8B4220035FD78 /* UIColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD50FD611DA8B4220035FD78 /* UIColorExtension.swift */; }; BD5BE9E625F5F778004995D0 /* ViProductSearchResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD5BE9E525F5F778004995D0 /* ViProductSearchResponse.swift */; }; @@ -83,6 +84,7 @@ /* Begin PBXFileReference section */ BD06D1351DA3BDE600EC9B38 /* ViResponseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViResponseData.swift; sourceTree = ""; }; BD06D1371DA3F59A00EC9B38 /* ViRequestSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViRequestSerialization.swift; sourceTree = ""; }; + BD283ABA29B7101600912D82 /* ViBestImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViBestImage.swift; sourceTree = ""; }; BD3A860025F22B6400BB71CF /* ViProductSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearch.swift; sourceTree = ""; }; BD50FD611DA8B4220035FD78 /* UIColorExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIColorExtension.swift; path = Helper/UIColorExtension.swift; sourceTree = ""; }; BD5BE9E525F5F778004995D0 /* ViProductSearchResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearchResponse.swift; sourceTree = ""; }; @@ -267,6 +269,7 @@ BD7020EE1E49BB99006BAE40 /* ViFacetItem.swift */, BD815AA71FC8003800E8DA76 /* ViObjectResult.swift */, BDD3C4D128C7A56400C0C1A4 /* ViSetInfo.swift */, + BD283ABA29B7101600912D82 /* ViBestImage.swift */, ); path = Response; sourceTree = ""; @@ -442,6 +445,7 @@ BD5F70582601F1B100132A1F /* ViProductObjectResult.swift in Sources */, BDB76A2626983C6C000C750A /* ViStrategy.swift in Sources */, BD72A3A025FF0FA1005C8BC0 /* ViGroupResult.swift in Sources */, + BD283ABB29B7101600912D82 /* ViBestImage.swift in Sources */, BD65405A1DA63F5200E10162 /* ViSearch.swift in Sources */, BD7DEDAB1DA2B6C400CDF6DE /* ViColorSearchParams.swift in Sources */, BD5BE9F225F61FE0004995D0 /* ViProduct.swift in Sources */, diff --git a/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProduct.swift b/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProduct.swift index f3f1a60..12e2fb6 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProduct.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProduct.swift @@ -34,4 +34,6 @@ open class ViProduct { public var alternatives: [ViProduct] = [] public var pinned: Bool? = nil + + public var bestImages: [ViBestImage] = [] } diff --git a/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProductSearchResponse.swift b/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProductSearchResponse.swift index 9e13dca..c5eb81c 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProductSearchResponse.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Response/ProductSearch/ViProductSearchResponse.swift @@ -241,6 +241,10 @@ open class ViProductSearchResponse : NSObject { item.alternatives = ViProductSearchResponse.parseProductResults(alt) } + if let bestImages = dict["best_images"] as? [Any] { + item.bestImages = ViResponseData.parseBestImages(bestImages) + } + if let score = dict["score"] as? Double { item.score = score } diff --git a/ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift b/ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift new file mode 100644 index 0000000..39ed98c --- /dev/null +++ b/ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift @@ -0,0 +1,15 @@ +// +// ViBestImage.swift +// ViSearchSDK +// +// Created by Hung on 7/3/23. +// Copyright © 2023 Hung. All rights reserved. +// + +import Foundation + +open class ViBestImage: NSObject { + public var type : String? = nil + public var url : String? = nil + public var index : String? = nil +} diff --git a/ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift b/ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift index 1bf6bb0..84d3baa 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift @@ -26,6 +26,8 @@ open class ViImageResult: NSObject { public var pinned: Bool? = nil + public var bestImages: [ViBestImage] = [] + public init?(_ im_name: String) { if im_name.isEmpty{ print("\(type(of: self)).\(#function)[line:\(#line)] - error: im_name is missing") diff --git a/ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift b/ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift index 9b75cd1..530d555 100644 --- a/ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift +++ b/ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift @@ -174,6 +174,25 @@ open class ViResponseData: NSObject { return results } + public static func parseBestImages(_ arr: [Any]) -> [ViBestImage]{ + var results = [ViBestImage]() + for jsonItem in arr { + if let dict = jsonItem as? [String:Any] { + let type = dict["type"] as? String + let url = dict["url"] as? String + let index = dict["index"] as? String + + let item = ViBestImage() + item.type = type + item.url = url + item.index = index + + results.append(item) + } + } + + return results + } public static func parseProductTypes(_ arr: [Any]) -> [ViProductType]{ var results = [ViProductType]() @@ -269,6 +288,10 @@ open class ViResponseData: NSObject { item.alternatives = ViResponseData.parseResults(alternatives) } + if let bestImages = dict["best_images"] as? [Any] { + item.bestImages = ViResponseData.parseBestImages(bestImages) + } + results.append(item) } else{ From 99c4a21f1fc5a92998d22384de29ff32726a0ed4 Mon Sep 17 00:00:00 2001 From: Hung Date: Tue, 7 Mar 2023 15:05:37 +0800 Subject: [PATCH 4/4] update test --- .../ViSearchSDKTests/ViProductTest.swift | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/ViSearchSDK/ViSearchSDKTests/ViProductTest.swift b/ViSearchSDK/ViSearchSDKTests/ViProductTest.swift index ca21321..b4bf443 100644 --- a/ViSearchSDK/ViSearchSDKTests/ViProductTest.swift +++ b/ViSearchSDK/ViSearchSDKTests/ViProductTest.swift @@ -343,6 +343,90 @@ class ViProductTest: XCTestCase { } + func testProductSearchRecBestImagesResponse() { + let urlResponse = URLResponse() + + let json: String = """ + { + "reqid": "01806a667776c6f8a31c28105fd99f", + "status": "OK", + "method": "product/recommendations", + "page": 1, + "limit": 10, + "total": 2, + "product_types": [], + "result": [ + { + "product_id": "dress1", + "main_image_url": "http://test.com/img1.jpg", + "best_images" : [ + { + "type" : "product", + "url" : "url11", + "index" : "0" + }, + { + "type" : "outfit", + "url" : "url21", + "index" : "3" + } + ], + "tags": { + "category": "dress", + "set_id": "set1" + }, + "score": 0.9 + } + + ], + "set_info": [ + { + "set_id": "set1", + "set_score": 1000, + "item_count": 2 + }, + { + "set_id": "set2", + "set_score": 900, + "item_count": 1 + } + ] + } + + """ + + let data = json.data(using: .utf8)! + + let res = ViProductSearchResponse(response: urlResponse, data: data) + + XCTAssertEqual(1, res.result.count) + let r1 = res.result[0] + XCTAssertEqual("set1", r1.tags!["set_id"] as! String) + XCTAssertEqual("dress", r1.tags!["category"] as! String) + + let bestImages = res.result[0].bestImages + XCTAssertEqual(2, bestImages.count) + + let b1 = bestImages[0] + XCTAssertEqual("0", b1.index) + XCTAssertEqual("product", b1.type) + XCTAssertEqual("url11", b1.url) + + let b2 = bestImages[1] + XCTAssertEqual("3", b2.index) + XCTAssertEqual("outfit", b2.type) + XCTAssertEqual("url21", b2.url) + + XCTAssertEqual(2, res.setInfoList.count) + XCTAssertEqual("set1", res.setInfoList[0].setId) + XCTAssertEqual(2, res.setInfoList[0].itemCount) + + XCTAssertTrue(res.setInfoList[0].setScore == 1000) + XCTAssertEqual("set2", res.setInfoList[1].setId) + XCTAssertTrue(res.setInfoList[1].setScore == 900) + XCTAssertEqual(1, res.setInfoList[1].itemCount) + + } }