io.github.dft.amazon.AmazonSPDestinationAPI 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 io.github.dft.amazon.model.AmazonCredentials;
import io.github.dft.amazon.model.destination.CreateDestinationRequest;
import io.github.dft.amazon.model.destination.CreateDestinationResponse;
import io.github.dft.amazon.model.destination.GetDestinationsResponse;
import io.github.dft.amazon.model.handler.JsonBodyHandler;
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static io.github.dft.amazon.constantcode.ConstantCodes.HTTP_HEADER_ACCEPTS;
import static io.github.dft.amazon.constantcode.ConstantCodes.HTTP_HEADER_CONTENT_TYPE;
import static io.github.dft.amazon.constantcode.ConstantCodes.HTTP_HEADER_VALUE_APPLICATION_JSON;
import static io.github.dft.amazon.constantcode.ConstantCodes.HTTP_HEADER_X_AMZ_ACCESS_TOKEN;
import static io.github.dft.amazon.constantcode.ConstantCodes.NOTIFICATION_DESTINATIONS_API_V1;
public class AmazonSPDestinationAPI extends AmazonSellingPartnerSdk {
public AmazonSPDestinationAPI(AmazonCredentials amazonCredentials) {
super(amazonCredentials);
}
public CreateDestinationResponse createDestination(CreateDestinationRequest destinationRequest) {
URI uri = URI.create(sellingRegionEndpoint + NOTIFICATION_DESTINATIONS_API_V1);
String requestBody = getString(destinationRequest);
refreshAccessToken(false);
HttpRequest request = HttpRequest.newBuilder(uri)
.header(HTTP_HEADER_ACCEPTS, HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(HTTP_HEADER_X_AMZ_ACCESS_TOKEN, amazonCredentials.getAccessToken())
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse.BodyHandler handler = new JsonBodyHandler<>(CreateDestinationResponse.class);
return getRequestWrapped(request, handler);
}
public GetDestinationsResponse getDestinations() {
URI uri = URI.create(sellingRegionEndpoint + NOTIFICATION_DESTINATIONS_API_V1);
refreshAccessToken(false);
HttpRequest request = HttpRequest.newBuilder(uri)
.header(HTTP_HEADER_ACCEPTS, HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_VALUE_APPLICATION_JSON)
.header(HTTP_HEADER_X_AMZ_ACCESS_TOKEN, amazonCredentials.getAccessToken())
.GET()
.build();
HttpResponse.BodyHandler handler = new JsonBodyHandler<>(GetDestinationsResponse.class);
return getRequestWrapped(request, handler);
}
}