diff --git a/README.md b/README.md index 59b8fd3..335e332 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Add the following dependency to your pom file com.indix.api apiv2-java-client - 1.0.1 + 1.0.2 ``` diff --git a/pom.xml b/pom.xml index 838ca51..5f7e7a6 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.indix.api apiv2-java-client - 1.0.1 + 1.0.2 jar Indix API-V2 Java Client Java client which is used to access API V2 endpoints diff --git a/src/main/java/com/indix/client/IndixApiClient.java b/src/main/java/com/indix/client/IndixApiClient.java index eea5758..3944205 100644 --- a/src/main/java/com/indix/client/IndixApiClient.java +++ b/src/main/java/com/indix/client/IndixApiClient.java @@ -5,5 +5,5 @@ /** * Indix Api Client */ -public interface IndixApiClient extends SearchApi, ProductDetailsApi, MetadataApi, SuggestionsApi, ProductHistoryApi, BulkQueryApi, Closeable { +public interface IndixApiClient extends SearchApi, ProductDetailsApi, MetadataApi, SuggestionsApi, BulkQueryApi, Closeable { } diff --git a/src/main/java/com/indix/client/ProductHistoryApi.java b/src/main/java/com/indix/client/ProductHistoryApi.java deleted file mode 100644 index 111d258..0000000 --- a/src/main/java/com/indix/client/ProductHistoryApi.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.indix.client; - -import com.indix.exception.IndixApiException; -import com.indix.models.productHistoryResponse.ProductHistoryResult; -import com.indix.query.ProductHistoryQuery; - -import java.io.IOException; -import java.net.URISyntaxException; - -public interface ProductHistoryApi { - /** - * Product History - Returns the historical price information recorded for the product - * @param query Instance of {@link ProductHistoryQuery} with appropriate parameters - * @return {@link ProductHistoryResult} - * @throws {@link IndixApiException} - */ - ProductHistoryResult getProductHistory(ProductHistoryQuery query) - throws IndixApiException, IOException, URISyntaxException; -} diff --git a/src/main/java/com/indix/client/impl/IndixApiClientImpl.java b/src/main/java/com/indix/client/impl/IndixApiClientImpl.java index cef5872..7595c8a 100644 --- a/src/main/java/com/indix/client/impl/IndixApiClientImpl.java +++ b/src/main/java/com/indix/client/impl/IndixApiClientImpl.java @@ -1,27 +1,28 @@ package com.indix.client.impl; import com.fasterxml.jackson.core.JsonProcessingException; -import com.indix.client.IndixApiClient; -import com.indix.client.ProductsViewType; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.indix.client.IndixApiClient; +import com.indix.client.ProductsViewType; import com.indix.exception.IndixApiException; import com.indix.exception.InternalServerException; import com.indix.httpClient.HttpClient; import com.indix.httpClient.impl.HttpClientFactory; import com.indix.models.jobs.JobInfo; -import com.indix.models.metadataResult.*; +import com.indix.models.metadataResult.BrandsResult; +import com.indix.models.metadataResult.CategoriesResult; +import com.indix.models.metadataResult.StoresResult; import com.indix.models.productDetailsResult.*; -import com.indix.models.productHistoryResponse.ProductHistoryResult; import com.indix.models.searchResult.*; import com.indix.models.suggestions.SuggestionsResult; +import com.indix.query.*; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; import org.apache.http.message.BasicNameValuePair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.indix.query.*; import java.io.File; import java.io.IOException; @@ -167,10 +168,6 @@ private String buildProductDetailsPath(ProductsViewType resourceView, String mpi return buildPath(buildSearchResourcePath(resourceView), mpid); } - private String buildProductHistoryPath(String mpid) { - return buildPath(PRODUCT_HISTORY_RESOURCE, mpid); - } - private String buildBulkSearchResourcePath(ProductsViewType resourceView) { return buildPath(VERSION, String.valueOf(resourceView), BULK, PRODUCTS_RESOURCE); } @@ -609,32 +606,6 @@ public SuggestionsResult getSuggestions(Query query) } } - /** - * Product History - Returns the historical price information recorded for the product - * - * @param query Instance of {@link ProductHistoryQuery} with appropriate parameters - * @return {@link ProductHistoryResult} - * @throws {@link IndixApiException} - */ - public ProductHistoryResult getProductHistory(ProductHistoryQuery query) - throws IndixApiException, IOException, URISyntaxException { - - String resource = buildProductHistoryPath(query.getMpid()); - try { - String content = executeGET(resource, query); - IndixApiResponse productHistoryIndixApiResponse = jsonMapper.readValue(content, - new TypeReference>() { - }); - return productHistoryIndixApiResponse.getResult(); - } catch (IndixApiException iae) { - logger.error("getProductHistory failed: " + iae.getMessage()); - throw iae; - } catch (JsonProcessingException e) { - logger.error("getProductHistory failed: " + e.getMessage()); - throw new InternalServerException(e); - } - } - /** * Posts a bulk job for the appropriate resource type for search cases * diff --git a/src/main/java/com/indix/client/impl/IndixApiConstants.java b/src/main/java/com/indix/client/impl/IndixApiConstants.java index 65a6069..8f73faa 100644 --- a/src/main/java/com/indix/client/impl/IndixApiConstants.java +++ b/src/main/java/com/indix/client/impl/IndixApiConstants.java @@ -12,7 +12,6 @@ class IndixApiConstants { static final String JOB_VIEW = "jobs"; static final String DOWNLOAD_PATH = "download"; static final String LOOKUP_VIEW = "lookup"; - static final String HISTORY_VIEW = "history"; static final String PRODUCTS_RESOURCE = "products"; static final String STORES_RESOURCE = buildPath(VERSION, "stores"); @@ -20,8 +19,6 @@ class IndixApiConstants { static final String CATEGORIES_RESOURCE = buildPath(VERSION, "categories"); static final String SUGGESTIONS_RESOURCE = buildPath(VERSION, PRODUCTS_RESOURCE, "suggestions"); - public static final String PRODUCT_HISTORY_RESOURCE = buildPath(VERSION, HISTORY_VIEW, PRODUCTS_RESOURCE); - public static final String BULK_JOB_RESOURCE = buildPath(VERSION, BULK, JOB_VIEW); } diff --git a/src/main/java/com/indix/models/product/ProductHistory.java b/src/main/java/com/indix/models/product/ProductHistory.java deleted file mode 100644 index 1a1593d..0000000 --- a/src/main/java/com/indix/models/product/ProductHistory.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.indix.models.product; - -import com.indix.models.product.productAtStore.ProductHistoryAtStore; - -import java.util.Map; - -public class ProductHistory { - - private int categoryId; - private int brandId; - private Map stores; - - public int getCategoryId(){ - return categoryId; - } - - public int getBrandId(){ - return brandId; - } - - public Map getStores() { - return stores; - } - -} diff --git a/src/main/java/com/indix/models/product/productAtStore/ProductHistoryAtStore.java b/src/main/java/com/indix/models/product/productAtStore/ProductHistoryAtStore.java deleted file mode 100644 index 34e9918..0000000 --- a/src/main/java/com/indix/models/product/productAtStore/ProductHistoryAtStore.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.indix.models.product.productAtStore; - -import com.indix.models.product.productAtStore.offer.ProductOfferHistory; - -import java.util.List; - -public class ProductHistoryAtStore { - - private List offers; - private int storeId; - private String storeName; - - - public List getOffers() { - return offers; - } - - public int getStoreId(){ - return storeId; - } - - public String getStoreName(){ - return storeName; - } - -} diff --git a/src/main/java/com/indix/models/product/productAtStore/offer/ProductOfferHistory.java b/src/main/java/com/indix/models/product/productAtStore/offer/ProductOfferHistory.java deleted file mode 100644 index f2dd4a5..0000000 --- a/src/main/java/com/indix/models/product/productAtStore/offer/ProductOfferHistory.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.indix.models.product.productAtStore.offer; - -import java.util.List; - -public class ProductOfferHistory { - - private List timestampHistory; - private List salePriceHistory; - private List listPriceHistory; - private String pid; - private String seller; - - public String getPid(){ - return pid; - } - - /** - * @return The timestamp for when the product's data was crawled on the store's website - * including the historic prices - */ - public List getTimestampHistory(){ - return timestampHistory; - } - - /** - * @return The array of sale prices of the product at this store afetr promotions including historic prices - */ - public List getSalePriceHistory(){ - return salePriceHistory; - } - - /** - * @return The array of list prices of the product at this store including historic prices - */ - public List getListPriceHistory(){ - return listPriceHistory; - } - - public String getSeller(){ - return seller; - } -} diff --git a/src/main/java/com/indix/models/productHistoryResponse/ProductHistoryResult.java b/src/main/java/com/indix/models/productHistoryResponse/ProductHistoryResult.java deleted file mode 100644 index 2d52e55..0000000 --- a/src/main/java/com/indix/models/productHistoryResponse/ProductHistoryResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.indix.models.productHistoryResponse; - -import com.indix.models.product.ProductHistory; - -public class ProductHistoryResult { - - private ProductHistory product; - - public ProductHistory getProduct() { - return product; - } -} diff --git a/src/main/java/com/indix/query/ProductHistoryQuery.java b/src/main/java/com/indix/query/ProductHistoryQuery.java deleted file mode 100644 index a2c6323..0000000 --- a/src/main/java/com/indix/query/ProductHistoryQuery.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.indix.query; - -import org.apache.http.message.BasicNameValuePair; - -public class ProductHistoryQuery extends QueryBase { - String mpid; - - public ProductHistoryQuery() { - super(); - mpid = ""; - } - - /** - * Limits results to products of the geography with this code. Example: 'US', 'GB', etc - * If the user doesn’t pass a value, the default option returns the US countryCode data - */ - public ProductHistoryQuery withCountryCode(String cc) { - parameters.add(new BasicNameValuePair("countryCode", cc)); - return this; - } - - /** - * The product identifier - should be a 32-digit HEX value retrieved via the Product Search API - */ - public ProductHistoryQuery withMpid(String mpid) { - this.mpid = mpid; - return this; - } - - /** - * Limit result to price history of the product at this store - */ - public ProductHistoryQuery withStoreId(int storeId) { - parameters.add(new BasicNameValuePair("storeId", String.valueOf(storeId))); - return this; - } - - public String getMpid() { - return mpid; - } -} diff --git a/src/main/java/com/indix/query/QueryFactory.java b/src/main/java/com/indix/query/QueryFactory.java index 1120eb9..63d747c 100644 --- a/src/main/java/com/indix/query/QueryFactory.java +++ b/src/main/java/com/indix/query/QueryFactory.java @@ -37,13 +37,6 @@ public static BulkProductsQuery newBulkQuery() { return new SearchQuery(); } - /** - * @return {@link ProductHistoryQuery} - */ - public static ProductHistoryQuery newProductHistoryQuery() { - return new ProductHistoryQuery(); - } - /** * @return {@link BulkLookupQuery} */ diff --git a/src/test/java/com/indix/client/IndixApiClientHistoryTest.java b/src/test/java/com/indix/client/IndixApiClientHistoryTest.java deleted file mode 100644 index 252b012..0000000 --- a/src/test/java/com/indix/client/IndixApiClientHistoryTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.indix.client; - - -import com.indix.client.impl.IndixApiClientFactory; -import com.indix.exception.IndixApiException; -import com.indix.httpClient.HttpClient; -import com.indix.models.product.productAtStore.ProductHistoryAtStore; -import com.indix.models.product.productAtStore.offer.ProductOfferHistory; -import org.junit.Test; -import com.indix.query.ProductHistoryQuery; -import com.indix.query.QueryFactory; - -import java.io.IOException; -import java.net.URISyntaxException; - -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class IndixApiClientHistoryTest { - - @Test - public void getProductHistory() - throws IndixApiException, IOException, URISyntaxException { - - MockResourceHttpClient mockHttpClientInstance = new MockResourceHttpClient(); - HttpClient mockHttpClient = mockHttpClientInstance.getMockClient("productHistory-json-responses0/productHistory.json"); - - IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient); - - try { - ProductHistoryQuery productHistoryQuery = QueryFactory.newProductHistoryQuery() - .withCountryCode("US") - .withStoreId(271) - .withMpid("mpid1"); - ProductHistoryAtStore productHistoryRecord = indixApiClient.getProductHistory(productHistoryQuery).getProduct().getStores().get("271"); - ProductOfferHistory productOfferHistory = productHistoryRecord.getOffers().get(0); - - assertThat(productOfferHistory.getListPriceHistory(), hasItems(18.98, 19.98, 20.98)); - assertThat(productOfferHistory.getSalePriceHistory(), hasItems(18.00, 19.00, 20.00)); - assertThat(productOfferHistory.getPid(), is("pid1")); - assertThat(productOfferHistory.getSeller(), is("seller")); - assertThat(productOfferHistory.getTimestampHistory(), hasItems(1395644011000L, 1395415299000L, 1394371160000L)); - - assertThat(productHistoryRecord.getStoreId(), is(111)); - assertThat(productHistoryRecord.getStoreName(), is("storename")); - assertThat(indixApiClient.getProductHistory(productHistoryQuery).getProduct().getBrandId(), is(1547)); - assertThat(indixApiClient.getProductHistory(productHistoryQuery).getProduct().getCategoryId(), is(12345)); - - - } finally { - indixApiClient.close(); - } - } -} diff --git a/src/test/java/com/indix/query/ProductHistoryQueryTest.java b/src/test/java/com/indix/query/ProductHistoryQueryTest.java deleted file mode 100644 index 06de2a4..0000000 --- a/src/test/java/com/indix/query/ProductHistoryQueryTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.indix.query; - -import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class ProductHistoryQueryTest { - - @Test - public void testBasicQuery() { - List expectedValue = new ArrayList(); - expectedValue.add(new BasicNameValuePair("countryCode", "US")); - expectedValue.add(new BasicNameValuePair("storeId", "2345")); - - ProductHistoryQuery productHistoryQuery = QueryFactory.newProductHistoryQuery() - .withCountryCode("US") - .withStoreId(2345) - .withMpid("mpid1"); - List actualParameters = productHistoryQuery.getParameters(); - - assertTrue(actualParameters.containsAll(expectedValue)); - assertEquals("mpid1", productHistoryQuery.getMpid()); - } -}