io.github.dft.amazon.AmazonSellingPartnerSdk Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of amazon-sp-api Show documentation
Show all versions of amazon-sp-api Show documentation
Amazon SP API using JDK 11
The newest version!
package io.github.dft.amazon;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.dft.amazon.constantcode.ConstantCodes;
import io.github.dft.amazon.model.AmazonCredentials;
import io.github.dft.amazon.model.auth.AccessTokenResponse;
import io.github.dft.amazon.model.handler.JsonBodyHandler;
import lombok.SneakyThrows;
import org.apache.http.client.utils.URIBuilder;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static io.github.dft.amazon.constantcode.ConstantCodes.MAX_ATTEMPTS;
import static io.github.dft.amazon.constantcode.ConstantCodes.TIME_OUT_DURATION;
import static java.nio.charset.StandardCharsets.UTF_8;
public class AmazonSellingPartnerSdk {
protected AmazonCredentials amazonCredentials;
protected String sellingRegionEndpoint;
protected HttpClient client;
private ObjectMapper objectMapper;
public AmazonSellingPartnerSdk() {
client = HttpClient.newHttpClient();
}
@SneakyThrows
public AmazonSellingPartnerSdk(AmazonCredentials amazonCredentials) {
this.amazonCredentials = amazonCredentials;
if (ConstantCodes.AWS_REGION_EU_WEST_1.equalsIgnoreCase(amazonCredentials.getRegion())) {
this.sellingRegionEndpoint = "https://sellingpartnerapi-eu.amazon.com";
} else if (ConstantCodes.AWS_REGION_US_EAST_1.equalsIgnoreCase(amazonCredentials.getRegion())) {
this.sellingRegionEndpoint = "https://sellingpartnerapi-na.amazon.com";
} else if (ConstantCodes.AWS_REGION_US_WEST_1.equalsIgnoreCase(amazonCredentials.getRegion())) {
this.sellingRegionEndpoint = "https://sellingpartnerapi-fe.amazon.com";
} else {
this.sellingRegionEndpoint = null;
}
this.objectMapper = new ObjectMapper();
client = HttpClient.newHttpClient();
}
@SneakyThrows
protected void refreshAccessToken(boolean bGrantless) {
if (amazonCredentials.getAccessToken() == null || amazonCredentials.getExpiresInTime() == null || ZonedDateTime.now(ZoneOffset.UTC).isAfter(amazonCredentials.getExpiresInTime())) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy