70 lines
1.6 KiB
Java
70 lines
1.6 KiB
Java
package de.rwu.easydrop.api.client;
|
|
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
|
|
import de.rwu.easydrop.model.Webshop;
|
|
|
|
/**
|
|
* Sends a buy request to the Amazon API.
|
|
*
|
|
* @since 0.3.0
|
|
*/
|
|
public final class AmazonPurchaser extends AbstractPurchaser {
|
|
/**
|
|
* Name of this data source.
|
|
*/
|
|
private static final Webshop DATA_TARGET = Webshop.AMAZON;
|
|
/**
|
|
* Base URL to the Amazon Purchase API.
|
|
*/
|
|
private String baseUrl;
|
|
/**
|
|
* Access credential.
|
|
*/
|
|
private String apiKey;
|
|
/**
|
|
* Product region parameter required for data writes.
|
|
*/
|
|
private static final String PRODUCT_REGION = "DE";
|
|
/**
|
|
* Locale parameter required for data writes.
|
|
*/
|
|
private static final String LOCALE = "de_DE";
|
|
|
|
/**
|
|
* Sets up instance with Base URL and API Key.
|
|
*
|
|
* @param newBaseUrl
|
|
* @param newApiKey
|
|
*/
|
|
public AmazonPurchaser(final String newBaseUrl, final String newApiKey) {
|
|
this.baseUrl = newBaseUrl;
|
|
this.apiKey = newApiKey;
|
|
}
|
|
|
|
/**
|
|
* @param productId ASIN
|
|
*/
|
|
@Override
|
|
protected URL createApiUrl(final String productId) throws MalformedURLException {
|
|
return new URL(baseUrl
|
|
+ "/products/2020-08-26/products/"
|
|
+ productId
|
|
+ "/buy?productRegion="
|
|
+ PRODUCT_REGION
|
|
+ "&locale="
|
|
+ LOCALE);
|
|
}
|
|
|
|
@Override
|
|
protected String getApiKey() {
|
|
return this.apiKey;
|
|
}
|
|
|
|
@Override
|
|
protected Webshop getDataTarget() {
|
|
return DATA_TARGET;
|
|
}
|
|
}
|