Skip to content

Commit

Permalink
Merge pull request #47 from visenze/feature/best_images
Browse files Browse the repository at this point in the history
[API-9086] Best images params
  • Loading branch information
thehung111 authored Mar 7, 2023
2 parents a1b574a + 99c4a21 commit e7620cc
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
TargetAttributes = {
BDCA2E0E1DA38B7B004C2EF7 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = NKN6QECX9M;
DevelopmentTeam = 345PN8HV64;
LastSwiftMigration = 1030;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
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.8.7"
s.version = "1.9.0"
s.summary = "A Visual Search API solution (Swift SDK)"

s.description = <<-DESC
Expand Down
12 changes: 8 additions & 4 deletions ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -83,6 +84,7 @@
/* Begin PBXFileReference section */
BD06D1351DA3BDE600EC9B38 /* ViResponseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViResponseData.swift; sourceTree = "<group>"; };
BD06D1371DA3F59A00EC9B38 /* ViRequestSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViRequestSerialization.swift; sourceTree = "<group>"; };
BD283ABA29B7101600912D82 /* ViBestImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViBestImage.swift; sourceTree = "<group>"; };
BD3A860025F22B6400BB71CF /* ViProductSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearch.swift; sourceTree = "<group>"; };
BD50FD611DA8B4220035FD78 /* UIColorExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIColorExtension.swift; path = Helper/UIColorExtension.swift; sourceTree = "<group>"; };
BD5BE9E525F5F778004995D0 /* ViProductSearchResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearchResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +269,7 @@
BD7020EE1E49BB99006BAE40 /* ViFacetItem.swift */,
BD815AA71FC8003800E8DA76 /* ViObjectResult.swift */,
BDD3C4D128C7A56400C0C1A4 /* ViSetInfo.swift */,
BD283ABA29B7101600912D82 /* ViBestImage.swift */,
);
path = Response;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -610,7 +614,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;
Expand All @@ -628,7 +632,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;
Expand All @@ -641,7 +645,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;
Expand All @@ -659,7 +663,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 5 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Request/ViRecParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ open class ViProduct {
public var alternatives: [ViProduct] = []

public var pinned: Bool? = nil

public var bestImages: [ViBestImage] = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 23 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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{
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.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
Expand Down
84 changes: 84 additions & 0 deletions ViSearchSDK/ViSearchSDKTests/ViProductTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}


}
Expand Down

0 comments on commit e7620cc

Please sign in to comment.