@Test public void canFormRequestWithAllParams() { List<String> interests = new ArrayList<>(); interests.add("interest1"); interests.add("interest2"); RecommendationsRequest request = new RecommendationsRequest.Builder(limit) .pageType(PageType.PRODUCT) .requiredCategory("cat123") .minAvgRating(2.3) .productId("testid") .interests(interests) .build(); String actualUrlString = RecommendationsRequest.toUrlString(BVSDK.getInstance(), adId, request); assertEquals("https: "recommendations/" + "magpie_idfa_testAdId?" + "passKey=apiKeyShopperAd&" + "client=pretendcompany&" + "min_avg_rating=2.3&" + "limit=13&" + "pageType=PRODUCT&" + "required_category=cat123&" + "interests=interest1,interest2&" + "product=pretendcompany/testid", actualUrlString); }
static @Nullable String toUrlString(@NonNull BVSDK bvsdk, String adId, RecommendationsRequest request) { String baseUrl = bvsdk.getBvWorkerData().getRootApiUrls().getShopperMarketingApiRootUrl(); BVUserProvidedData bvUserProvidedData = bvsdk.getBvUserProvidedData(); String apiKey = bvUserProvidedData.getBvConfig().getApiKeyShopperAdvertising(); String clientId = bvUserProvidedData.getBvConfig().getClientId(); String similarityParams = generateSimilarityParams(request.getProductId(), request.getCategoryId(), clientId); String interests = buildListsQueryParam(request.interests); HttpUrl url = HttpUrl.parse(baseUrl); if (url != null) { HttpUrl.Builder builder = url.newBuilder(); builder.addPathSegment(RECOMMENDATIONS_PATH) .addPathSegment("magpie_idfa_" + adId) .addEncodedQueryParameter("passKey", apiKey) .addEncodedQueryParameter("client", clientId) .addEncodedQueryParameter("min_avg_rating", String.valueOf(request.minAvgRating)) .addEncodedQueryParameter("limit", String.valueOf(request.limit)); if (request.pageType != null) { builder.addEncodedQueryParameter("pageType", request.pageType.toString()); } if (request.requiredCategory != null) { builder.addEncodedQueryParameter("required_category", request.requiredCategory); } if (request.interests != null) { builder.addEncodedQueryParameter("interests", interests); } return builder.build().toString() + similarityParams; } return null; }
RecommendationsRequest { static @Nullable String toUrlString(@NonNull BVSDK bvsdk, String adId, RecommendationsRequest request) { String baseUrl = bvsdk.getBvWorkerData().getRootApiUrls().getShopperMarketingApiRootUrl(); BVUserProvidedData bvUserProvidedData = bvsdk.getBvUserProvidedData(); String apiKey = bvUserProvidedData.getBvConfig().getApiKeyShopperAdvertising(); String clientId = bvUserProvidedData.getBvConfig().getClientId(); String similarityParams = generateSimilarityParams(request.getProductId(), request.getCategoryId(), clientId); String interests = buildListsQueryParam(request.interests); HttpUrl url = HttpUrl.parse(baseUrl); if (url != null) { HttpUrl.Builder builder = url.newBuilder(); builder.addPathSegment(RECOMMENDATIONS_PATH) .addPathSegment("magpie_idfa_" + adId) .addEncodedQueryParameter("passKey", apiKey) .addEncodedQueryParameter("client", clientId) .addEncodedQueryParameter("min_avg_rating", String.valueOf(request.minAvgRating)) .addEncodedQueryParameter("limit", String.valueOf(request.limit)); if (request.pageType != null) { builder.addEncodedQueryParameter("pageType", request.pageType.toString()); } if (request.requiredCategory != null) { builder.addEncodedQueryParameter("required_category", request.requiredCategory); } if (request.interests != null) { builder.addEncodedQueryParameter("interests", interests); } return builder.build().toString() + similarityParams; } return null; } }
RecommendationsRequest { static @Nullable String toUrlString(@NonNull BVSDK bvsdk, String adId, RecommendationsRequest request) { String baseUrl = bvsdk.getBvWorkerData().getRootApiUrls().getShopperMarketingApiRootUrl(); BVUserProvidedData bvUserProvidedData = bvsdk.getBvUserProvidedData(); String apiKey = bvUserProvidedData.getBvConfig().getApiKeyShopperAdvertising(); String clientId = bvUserProvidedData.getBvConfig().getClientId(); String similarityParams = generateSimilarityParams(request.getProductId(), request.getCategoryId(), clientId); String interests = buildListsQueryParam(request.interests); HttpUrl url = HttpUrl.parse(baseUrl); if (url != null) { HttpUrl.Builder builder = url.newBuilder(); builder.addPathSegment(RECOMMENDATIONS_PATH) .addPathSegment("magpie_idfa_" + adId) .addEncodedQueryParameter("passKey", apiKey) .addEncodedQueryParameter("client", clientId) .addEncodedQueryParameter("min_avg_rating", String.valueOf(request.minAvgRating)) .addEncodedQueryParameter("limit", String.valueOf(request.limit)); if (request.pageType != null) { builder.addEncodedQueryParameter("pageType", request.pageType.toString()); } if (request.requiredCategory != null) { builder.addEncodedQueryParameter("required_category", request.requiredCategory); } if (request.interests != null) { builder.addEncodedQueryParameter("interests", interests); } return builder.build().toString() + similarityParams; } return null; } private  RecommendationsRequest(Builder builder); }
RecommendationsRequest { static @Nullable String toUrlString(@NonNull BVSDK bvsdk, String adId, RecommendationsRequest request) { String baseUrl = bvsdk.getBvWorkerData().getRootApiUrls().getShopperMarketingApiRootUrl(); BVUserProvidedData bvUserProvidedData = bvsdk.getBvUserProvidedData(); String apiKey = bvUserProvidedData.getBvConfig().getApiKeyShopperAdvertising(); String clientId = bvUserProvidedData.getBvConfig().getClientId(); String similarityParams = generateSimilarityParams(request.getProductId(), request.getCategoryId(), clientId); String interests = buildListsQueryParam(request.interests); HttpUrl url = HttpUrl.parse(baseUrl); if (url != null) { HttpUrl.Builder builder = url.newBuilder(); builder.addPathSegment(RECOMMENDATIONS_PATH) .addPathSegment("magpie_idfa_" + adId) .addEncodedQueryParameter("passKey", apiKey) .addEncodedQueryParameter("client", clientId) .addEncodedQueryParameter("min_avg_rating", String.valueOf(request.minAvgRating)) .addEncodedQueryParameter("limit", String.valueOf(request.limit)); if (request.pageType != null) { builder.addEncodedQueryParameter("pageType", request.pageType.toString()); } if (request.requiredCategory != null) { builder.addEncodedQueryParameter("required_category", request.requiredCategory); } if (request.interests != null) { builder.addEncodedQueryParameter("interests", interests); } return builder.build().toString() + similarityParams; } return null; } private  RecommendationsRequest(Builder builder); int getLimit(); String getProductId(); String getCategoryId(); PageType getPageType(); }
RecommendationsRequest { static @Nullable String toUrlString(@NonNull BVSDK bvsdk, String adId, RecommendationsRequest request) { String baseUrl = bvsdk.getBvWorkerData().getRootApiUrls().getShopperMarketingApiRootUrl(); BVUserProvidedData bvUserProvidedData = bvsdk.getBvUserProvidedData(); String apiKey = bvUserProvidedData.getBvConfig().getApiKeyShopperAdvertising(); String clientId = bvUserProvidedData.getBvConfig().getClientId(); String similarityParams = generateSimilarityParams(request.getProductId(), request.getCategoryId(), clientId); String interests = buildListsQueryParam(request.interests); HttpUrl url = HttpUrl.parse(baseUrl); if (url != null) { HttpUrl.Builder builder = url.newBuilder(); builder.addPathSegment(RECOMMENDATIONS_PATH) .addPathSegment("magpie_idfa_" + adId) .addEncodedQueryParameter("passKey", apiKey) .addEncodedQueryParameter("client", clientId) .addEncodedQueryParameter("min_avg_rating", String.valueOf(request.minAvgRating)) .addEncodedQueryParameter("limit", String.valueOf(request.limit)); if (request.pageType != null) { builder.addEncodedQueryParameter("pageType", request.pageType.toString()); } if (request.requiredCategory != null) { builder.addEncodedQueryParameter("required_category", request.requiredCategory); } if (request.interests != null) { builder.addEncodedQueryParameter("interests", interests); } return builder.build().toString() + similarityParams; } return null; } private  RecommendationsRequest(Builder builder); int getLimit(); String getProductId(); String getCategoryId(); PageType getPageType();  }