Versions Compared

Key

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

...

Code Block
languagejava
List filters = new ArrayList<VisilabsTargetFilter>();
HashMap<String,String> properties = new HashMap<String, String>();
properties.put("OM.extra", "Extra Value");
VisilabsTargetFilter f = new VisilabsTargetFilter();
f.setAttribute("attr1");
f.setFilterType("0"); // There are 2 filter types: 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 are 2 filter types: 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);

Talep tamamlandıktan sonra, talebin başarı ya da başarısızlık durumuna bağlı olarak callback fonksiyonu çağrılır, bu nedenle ihtiyaçlarınıza göre callback fonksiyonlarını aşağıda gösterildiği gibi kodlamanız gerekir:

Code Block
languagejava
VisilabsTargetCallbackVisilabsCallback callback = new VisilabsTargetCallbackVisilabsCallback() {
    @Override
    public void success(VisilabsResponse response) {
try{ JSONArray array = response.getArray(); if(array != null) try{
 ArrayList<Product> recommendations = new ArrayList<>(); for (int i = 0; i <JSONArray array = response.lengthgetArray();
i++) { JSONObject obj = (JSONObject)array.get(i); Product product =}catch new(Exception Product(ex);
product.setProductCode(obj.getString("code"));
product.setProductName(obj.getString("title"));
product.setMediumImageUrl(obj.getString("img"));
product.setProductURL(obj.getString("dest_url"));
product.setBrand(obj.getString("brand"));
product.setOriginalPrice(obj.getDouble("price"));
product.setDiscountedPrice(obj.getDouble("dprice"));
product.setCurrency(obj.getString("cur"));
product.setDiscountCurrency(obj.getString("dcur"));
product.setFreeShipping(obj.getBoolean("freeshipping")); 
product.setShippingOnSameDay
(obj.getBoolean("samedayshipping"));
product.setRating(obj.getInt("rating"));
product.setComment(obj.getInt("comment"));
product.setDiscountRate(obj.getDouble("discount")); 
product.setAttr1(obj.getString("attr1"));
product.setAttr2(obj.getString("attr2"));
product.setAttr3(obj.getString("attr3"));
product.setAttr4(obj.getString("attr4"));
product.setAttr5(obj.getString("attr5"));
recommendations.add(product);
} 
}
}catch (Exception ex){
showToast(ex.getMessage());
Log.e(LOG_TAG, ex.getMessage(), ex);
}
}
@Override{
            Log.e(LOG_TAG, ex.getMessage(), ex);
        }
    }
    @Override
    public void fail(VisilabsResponse response) {
showToast(response.getErrorMessage());
        Log.de(LOG_TAG, rawResponseresponse.getErrorMessage());
    }
};

...