Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

SDK

...

Code Block
languagejava
linenumberstrue
List filters = new ArrayList<VisilabsTargetFilter>();
HashMap<String,String> properties = new HashMap<String, String>();
properties.put("OM.exVisitorID", "ID");
properties.put("OM.extra", "Extra Value");
VisilabsTargetFilter f = new VisilabsTargetFilter();
f.setAttribute("attr1");
f.setFilterType("0"); // There isare 2 filter typetypes: Include and Exclude. For Include pass "0", for Exclude pass "1".
f.setValue("value");
filters.add(f);
f = new VisilabsTargetFilter();
f.setAttribute("attr2");
f.setFilterType("1"); // There isare 2 filter typetypes: Include and Exclude. For Include pass "0", for Exclude pass "1".
f.setValue("value");
filters.add(f);
VisilabsTargetRequest targetRequest = Visilabs.CallAPI().buildTargetRequest(zoneID, "productCode", properties, filters);
targetRequest.executeAsync(callback);

...

Product recommendations are array of products with product details like brand, price etc. After you receive the product recommendations you need to display recommended products according to your mobile applications’s requirements. This section outlines how to receive recommendations as an array.

Create a VisilabsTargetRequest object:
Code Block
languageapplescript
titleObjective-C
VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"];
Code Block
languageapplescript
titleSwift
let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode")

There is also an overload of buildTargetRequest method to which you may pass filters and extra parameters.


Code Block
languageapplescript
titleObjective-C
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableArray *filters = [[NSMutableArray alloc] init];
[dic setObject:@"Extra Value" forKey:@"OM.extra"];
[dic setObject:@"ID" forKey:@"OM.exVisitorID"];
VisilabsTargetFilter *filter1 = [[VisilabsTargetFilter alloc] init];
filter1.attribute = @"attr1";
filter1.value =  @"val";
filter1.filterType =  @"01"; // There isare 2 filter typetypes: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter1];
VisilabsTargetFilter *filter2 = [[VisilabsTargetFilter alloc] init];
filter2.attribute = @"attr2";
filter2.value =  @"val";
filter2.filterType =  @"0"; // There isare 2 filter typetypes: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter2];


VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"  withProperties:dic withFilters:filters];
Code Block
languageapplescript
titleSwift
let zoneID = "9"
let dic = NSMutableDictionary()
dic["OM.extra"] = "Extra Value";
dic["OM.exVisitorID"] = "ID";
let filters = NSMutableArray()
let filter1 = VisilabsTargetFilter()
filter1.attribute = "attr1"
filter1.filterType = "1"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter1.value = "val"
filters.add(filter1)
let filter2 = VisilabsTargetFilter()
filter2.attribute = "attr2"
filter2.filterType = "0"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter2.value = "val"
filters.add(filter2)
let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode", withProperties:dic, with:filters)



After the request is completed, depending on the status of the request either success or failure callback function will be called, therefore based on your requirements, you need to code your callback functions as shown below:
Code Block
languageapplescript
titleObjective-C
void (^ successBlock)(VisilabsResponse *) = ^(VisilabsResponse * response) { NSLog(@"Response: %@", response.rawResponseAsString); NSArray *parsedArray = [response responseArray]; if(parsedArray){ for (NSObject * object in parsedArray) { if([object isKindOfClass:[NSDictionary class]]){ NSDictionary *product = (NSDictionary*)object; NSString *title = [product objectForKey:@"title"]; NSString *img = [product objectForKey:@"img"]; NSString *code = [product objectForKey:@"code"]; NSString *destURL = [product objectForKey:@"dest_url"]; NSString *brand = [product objectForKey:@"brand"]; double price = [[product objectForKey:@"price"] doubleValue]; double discountedPrice = [[product objectForKey:@"dprice"] doubleValue]; NSString *currency = [product objectForKey:@"cur"]; NSString *discountCurrency = [product objectForKey:@"dcur"]; int rating = [[product objectForKey:@"rating"] intValue]; int comment = [[product objectForKey:@"comment"] intValue]; double discount = [[product objectForKey:@"discount"] doubleValue]; BOOL freeShipping = [[product objectForKey:@"freeshipping"] boolValue]; BOOL sameDayShipping = [[product objectForKey:@"samedayshipping"] boolValue]; NSString *attr1 = [product objectForKey:@"attr1"]; NSString *attr2 = [product objectForKey:@"attr2"]; NSString *attr3 = [product objectForKey:@"attr3"]; NSString *attr4 = [product objectForKey:@"attr4"]; NSString *attr5 = [product objectForKey:@"attr5"]; } } } }; void (^ failBlock)(VisilabsResponse *) =^(VisilabsResponse * response){ NSLog(@"Failed to call. Response = %@", [actFailRes.error description]); };
Code Block
languageapplescript
titleSwift
let successBlock:(VisilabsResponse!) -> Void = {response in print("Response:\(response.rawResponseAsString)") for object:AnyObject in response.responseArray{ if(object.isKindOfClass(NSDictionary)){ let productObject = object as! NSDictionary; let title = productObject.objectForKey("title") as! String let img = productObject.objectForKey("img") as! String let code = productObject.objectForKey("code") as! String let dest_url = productObject.objectForKey("dest_url") as! String let brand = productObject.objectForKey("brand") as! String let price = productObject.objectForKey("price") as! Double let discountedPrice = productObject.objectForKey("dprice") as! Double let currency = productObject.objectForKey("cur") as! String let discountCurrency = productObject.objectForKey("dcur") as! String let rating = productObject.objectForKey("rating") as! Int let comment = productObject.objectForKey("comment") as! Int let discount = productObject.objectForKey("discount") as! Double let freeShipping =productObject.objectForKey("freeshipping") as! Bool let sameDayShipping=productObject.objectForKey("samedayshipping") as! Bool let attr1 = productObject.objectForKey("attr1") as! String let attr2 = productObject.objectForKey("attr2") as! String let attr3 = productObject.objectForKey("attr3") as! String let attr4 = productObject.objectForKey("attr4") as! String let attr5 = productObject.objectForKey("attr5") as! String } } } let failBlock: (VisilabsResponse!) -> Void = {response in VisilabsHelper.targetLog(response.targetURL) print("Visilabs target call failed.Error=\(response.rawResponseAsString)") }




Parent Topic: Getting Data