io.github.dft.amazon.AmazonSPSellers 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
package io.github.dft.amazon;
import com.amazonaws.http.HttpMethodName;
import io.github.dft.amazon.constantcode.ConstantCodes;
import io.github.dft.amazon.model.AmazonCredentials;
import io.github.dft.amazon.model.handler.JsonBodyHandler;
import io.github.dft.amazon.model.sellersapi.v1.GetMarketplaceParticipationsResponse;
import lombok.SneakyThrows;
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class AmazonSPSellers extends AmazonSellingPartnerSdk {
@SneakyThrows
public AmazonSPSellers(AmazonCredentials amazonCredentials) {
super(amazonCredentials);
}
@SneakyThrows
public GetMarketplaceParticipationsResponse getMarketplaceParticipations() {
final var signRequest = signRequest(ConstantCodes.SELLERS_API_V1, HttpMethodName.GET, null);
HttpRequest request = HttpRequest.newBuilder(new URI(sellingRegionEndpoint + ConstantCodes.SELLERS_API_V1))
.header(ConstantCodes.HTTP_HEADER_ACCEPTS, ConstantCodes.HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(ConstantCodes.HTTP_HEADER_CONTENT_TYPE, ConstantCodes.HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(ConstantCodes.HTTP_HEADER_X_AMZ_ACCESS_TOKEN, amazonCredentials.getAccessToken())
.header(ConstantCodes.HTTP_HEADER_AUTHORIZATION, signRequest.getHeaders().get(ConstantCodes.HTTP_HEADER_AUTHORIZATION))
.header(ConstantCodes.HTTP_HEADER_X_AMZ_SECURITY_TOKEN, signRequest.getHeaders().get(ConstantCodes.HTTP_HEADER_X_AMZ_SECURITY_TOKEN))
.header(ConstantCodes.X_AMZ_DATE, signRequest.getHeaders().get(ConstantCodes.X_AMZ_DATE))
.build();
HttpResponse.BodyHandler handler = new JsonBodyHandler<>(GetMarketplaceParticipationsResponse.class);
return getRequestWrapped(request, handler);
}
}