Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ Add the following dependency to your pom file
<dependency>
<groupId>com.indix.api</groupId>
<artifactId>indix-api-java</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
</dependency>
```

##Usage :

The client needs to be first instantiated with the appropriate application id and key to be able to use
the different api endpoints. It can be done as follows:
First, the client must be instantiated with the appropriate application key (appKey). It can be done as follows:
```java
String appId = "__app_id__";
String appKey = "__app_key__";
IndixApiClient indixApiClient = IndixApiClientFactory
.newIndixApiClient(appId, appKey);
.newIndixApiClient(appKey);
```

This instance can then used to query the different endpoints and obtain responses. Different types
Expand Down Expand Up @@ -209,5 +207,5 @@ HttpClient client = HttpClientFactory.newHttpClient(HttpClients.custom()
.setSslcontext(SSLTrustCA.trustLetsEncryptRootCA())
.build());
IndixApiClient indixApiClient = IndixApiClientFactory
.newIndixApiClient(appId, appKey, client);
.newIndixApiClient(appKey, client);
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.indix.api</groupId>
<artifactId>indix-api-java</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
<packaging>jar</packaging>
<name>Indix API-V2 Java Client</name>
<description>Java client which is used to access API V2 endpoints</description>
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/indix/client/impl/IndixApiClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@
public class IndixApiClientFactory {

/**
* @param appId application id
* @param appKey application key
* @return {@link IndixApiClient}
*/
public static IndixApiClient newIndixApiClient(String appId, String appKey) {
return new IndixApiClientImpl(appId, appKey);
public static IndixApiClient newIndixApiClient(String appKey) {
return new IndixApiClientImpl(appKey);
}

/**
* Used for mocking http client for testing purpose.
* @param appId application id
* @param appKey application key
* @param httpClient mock http client
* @return {@link IndixApiClient}
*/
public static IndixApiClient newIndixApiClient(String appId, String appKey, HttpClient httpClient) {
return new IndixApiClientImpl(appId, appKey, httpClient);
public static IndixApiClient newIndixApiClient(String appKey, HttpClient httpClient) {
return new IndixApiClientImpl(appKey, httpClient);
}


/**
* Used for setting server scheme and host for testing purpose.
* @param appId application id
* @param appKey application key
* @param scheme http scheme
* @param host api host to be queried
* @return {@link IndixApiClient}
*/
public static IndixApiClient newIndixApiClient(String appId, String appKey, String scheme, String host) {
return new IndixApiClientImpl(appId, appKey, scheme, host);
public static IndixApiClient newIndixApiClient(String appKey, String scheme, String host) {
return new IndixApiClientImpl(appKey, scheme, host);
}
}
21 changes: 7 additions & 14 deletions src/main/java/com/indix/client/impl/IndixApiClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ class IndixApiClientImpl implements IndixApiClient {

// Authorization parameters
//
String appId;
String appKey;

final static Logger logger = LoggerFactory.getLogger(IndixApiClientImpl.class);

// constructors
//
private IndixApiClientImpl(String appId, String appKey, HttpClient httpClient, ObjectMapper jsonMapper,
private IndixApiClientImpl(String appKey, HttpClient httpClient, ObjectMapper jsonMapper,
String scheme, String host) {
this.appId = appId;
this.appKey = appKey;
this.httpClient = httpClient;
this.jsonMapper = jsonMapper;
Expand All @@ -75,27 +73,24 @@ private IndixApiClientImpl(String appId, String appKey, HttpClient httpClient, O
}

/**
* @param appId application id
* @param appKey application key
*/
public IndixApiClientImpl(String appId, String appKey) {
this(appId, appKey, HttpClientFactory.newHttpClient(), getNewObjectMapper(), SCHEME, HOST);
public IndixApiClientImpl(String appKey) {
this(appKey, HttpClientFactory.newHttpClient(), getNewObjectMapper(), SCHEME, HOST);
}

/**
* @param appId application id
* @param appKey application key
*/
public IndixApiClientImpl(String appId, String appKey, String scheme, String host) {
this(appId, appKey, HttpClientFactory.newHttpClient(), getNewObjectMapper(), scheme, host);
public IndixApiClientImpl(String appKey, String scheme, String host) {
this(appKey, HttpClientFactory.newHttpClient(), getNewObjectMapper(), scheme, host);
}

/**
* @param appId application id
* @param appKey application key
*/
public IndixApiClientImpl(String appId, String appKey, HttpClient httpClient) {
this(appId, appKey, httpClient, getNewObjectMapper(), SCHEME, HOST);
public IndixApiClientImpl(String appKey, HttpClient httpClient) {
this(appKey, httpClient, getNewObjectMapper(), SCHEME, HOST);
}

// getter methods
Expand All @@ -114,7 +109,6 @@ private URI buildURI(String resource, Query searchQuery) throws URISyntaxExcepti
.setHost(host)
.setPath(resource)
.setParameters(searchQuery.getParameters())
.addParameter(APP_ID, appId)
.addParameter(APP_KEY, appKey)
.build();
}
Expand Down Expand Up @@ -148,7 +142,6 @@ private String executePOST(String resource, Query searchQuery, File file)
// populate app_id and app_key
//
List<NameValuePair> params = searchQuery.getParameters();
params.add(new BasicNameValuePair(APP_ID, appId));
params.add(new BasicNameValuePair(APP_KEY, appKey));

return httpClient.POST(uri, params, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void getBulkJobId()
MockResourceHttpClient mockHttpClientInstance = new MockResourceHttpClient();
HttpClient mockHttpClient = mockHttpClientInstance.getMockClient("bulkQuery-json-responses0/bulkQueryResponse.json");

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

List<Integer> storeIdList = new ArrayList<Integer>();
storeIdList.add(68);
Expand Down Expand Up @@ -64,7 +64,7 @@ public void getBulkLookupJobId()
MockResourceHttpClient mockHttpClientInstance = new MockResourceHttpClient();
HttpClient mockHttpClient = mockHttpClientInstance.getMockClient("bulkQuery-json-responses0/bulkQueryResponse.json");

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
for (ProductsViewType resource : ProductsViewType.values()) {
Expand Down Expand Up @@ -92,7 +92,7 @@ public void getBulkJobStatus()
MockResourceHttpClient mockHttpClientInstance = new MockResourceHttpClient();
HttpClient mockHttpClient = mockHttpClientInstance.getMockClient("bulkQuery-json-responses0/bulkQueryJobStatus.json");

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
JobQuery jobQuery = QueryFactory.newJobQuery()
Expand All @@ -116,7 +116,7 @@ public void getBulkJobFile()
MockResourceHttpClient mockHttpClientInstance = new MockResourceHttpClient();
HttpClient mockHttpClient = mockHttpClientInstance.getMockClient("bulkQuery-json-responses0/bulkQueryJobOutput.jsonl.tar.gz");

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
JobQuery jobQuery = QueryFactory.newJobQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void handleUnauthorizedException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.UNAUTHORIZED);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand All @@ -42,7 +42,7 @@ public void handleTooManyRequestsException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.TOO_MANY_REQUESTS);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand All @@ -62,7 +62,7 @@ public void handlePaymentRequiredException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.PAYMENT_REQUIRED);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand All @@ -82,7 +82,7 @@ public void handleIndixApiException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.INDIX_API);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand All @@ -102,7 +102,7 @@ public void handleInternalServerException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.INTERNAL_SERVER);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand All @@ -122,7 +122,7 @@ public void handleBadRequestException()
MockExceptionHttpClient mockClientInstance = new MockExceptionHttpClient();
HttpClient mockHttpClient = mockClientInstance.getMockClient(MockExceptionHttpClient.ExceptionName.BAD_REQUEST);

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123", mockHttpClient);
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", mockHttpClient);

try {
SearchQuery searchQuery = QueryFactory.newSearchQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HttpClient getMockHttpClient(String resource)
public void getStores()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("metadata-json-responses0/storesResponse.json"));

try {
Expand All @@ -48,7 +48,7 @@ public void getStores()
public void getBrands()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("metadata-json-responses0/brandsResponse.json"));

try {
Expand All @@ -67,7 +67,7 @@ public void getBrands()
public void getCategories()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("metadata-json-responses0/categoriesResponse.json"));

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public HttpClient getMockHttpClient(String resource)
public void getProductDetailsSummary()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/summaryProductDetailsResponse.json"));

try {
Expand All @@ -46,7 +46,7 @@ public void getProductDetailsSummary()
public void getProductDetailsOffersStandard()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/offersStandardProductDetailsResponse.json"));

try {
Expand All @@ -67,7 +67,7 @@ public void getProductDetailsOffersStandard()
public void getProductDetailsOffersPremium()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/offersPremiumProductDetailsResponse.json"));

try {
Expand All @@ -87,7 +87,7 @@ public void getProductDetailsOffersPremium()
public void getProductDetailsCatalogStandard()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/catalogStandardProductDetailsResponse.json"));

try {
Expand All @@ -107,7 +107,7 @@ public void getProductDetailsCatalogStandard()
public void getProductDetailsCatalogPremium()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/catalogPremiumProductDetailsResponse.json"));

try {
Expand All @@ -129,7 +129,7 @@ public void getProductDetailsCatalogPremium()
public void getProductDetailsUniversal()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand All @@ -151,7 +151,7 @@ public void getProductDetailsUniversal()
public void getProductDetailsSummaryShouldNotFailIfInputHasAdditionalFields()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand All @@ -171,7 +171,7 @@ public void getProductDetailsSummaryShouldNotFailIfInputHasAdditionalFields()
public void getProductDetailsOffersStandardShouldNotFailIfInputHasAdditionalFields()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand All @@ -192,7 +192,7 @@ public void getProductDetailsOffersStandardShouldNotFailIfInputHasAdditionalFiel
public void getProductDetailsOffersPremiumShouldNotFailIfInputHasAdditionalFields()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand All @@ -212,7 +212,7 @@ public void getProductDetailsOffersPremiumShouldNotFailIfInputHasAdditionalField
public void getProductDetailsCatalogStandardShouldNotFailIfInputHasAdditionalFields()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand All @@ -232,7 +232,7 @@ public void getProductDetailsCatalogStandardShouldNotFailIfInputHasAdditionalFie
public void getProductDetailsCatalogPremiumShouldNotFailIfInputHasAdditionalFields()
throws IndixApiException, IOException, URISyntaxException {

IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123", "123",
IndixApiClient indixApiClient = IndixApiClientFactory.newIndixApiClient("123",
getMockHttpClient("productDetails-json-responses0/universalProductDetailsResponse.json"));

try {
Expand Down
Loading