/* * Selling Partner API for Sellers * The Selling Partner API for Sellers lets you retrieve information on behalf of sellers about their seller account, such as the marketplaces they participate in. Along with listing the marketplaces that a seller can sell in, the API also provides additional information about the marketplace such as the default language and the default currency. The API also provides seller-specific information such as whether the seller has suspended listings in that marketplace. * * OpenAPI spec version: v1 * * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ package cn.amazon.aws.rp.spapi.clients.api; import cn.amazon.aws.rp.spapi.clients.*; import cn.amazon.aws.rp.spapi.clients.model.GetMarketplaceParticipationsResponse; import cn.amazon.aws.rp.spapi.dynamodb.entity.SellerCredentials; import cn.amazon.aws.rp.spapi.invoker.seller.SellerGetMarketParticipation; import cn.amazon.aws.rp.spapi.lambda.requestlimiter.ApiProxy; import com.google.gson.reflect.TypeToken; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class SellersApi { private ApiClient apiClient; private static final Logger logger = LoggerFactory.getLogger(SellersApi.class); SellersApi() { // TODO why not provide the credentials? this(Configuration.getDefaultApiClient()); } public SellersApi(ApiClient apiClient) { this.apiClient = apiClient; } public ApiClient getApiClient() { return apiClient; } public void setApiClient(ApiClient apiClient) { this.apiClient = apiClient; } /** * Build call for getMarketplaceParticipations * @param progressListener Progress listener * @param progressRequestListener Progress request listener * @return Call to execute * @throws ApiException If fail to serialize the request body object */ public com.squareup.okhttp.Call getMarketplaceParticipationsCall( final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object localVarPostBody = null; // create path and map variables String localVarPath = "/sellers/v1/marketplaceParticipations"; List localVarQueryParams = new ArrayList(); List localVarCollectionQueryParams = new ArrayList(); Map localVarHeaderParams = new HashMap(); Map localVarFormParams = new HashMap(); final String[] localVarAccepts = { "application/json" }; final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept); final String[] localVarContentTypes = { "application/json" }; final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); localVarHeaderParams.put("Content-Type", localVarContentType); if(progressListener != null) { apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() { @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException { com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .body(new ProgressResponseBody(originalResponse.body(), progressListener)) .build(); } }); } String[] localVarAuthNames = new String[] { }; return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener); } @SuppressWarnings("rawtypes") private com.squareup.okhttp.Call getMarketplaceParticipationsValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { com.squareup.okhttp.Call call = getMarketplaceParticipationsCall(progressListener, progressRequestListener); return call; } /** * * Returns a list of marketplaces that the seller submitting the request can sell in and information about the seller's participation in those marketplaces. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | .016 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation. * @return GetMarketplaceParticipationsResponse * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public GetMarketplaceParticipationsResponse getMarketplaceParticipations() throws ApiException { ApiResponse resp = getMarketplaceParticipationsWithHttpInfo(); return resp.getData(); } /** * * Returns a list of marketplaces that the seller submitting the request can sell in and information about the seller's participation in those marketplaces. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | .016 | 15 | For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation. * @return ApiResponse<GetMarketplaceParticipationsResponse> * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public ApiResponse getMarketplaceParticipationsWithHttpInfo() throws ApiException { com.squareup.okhttp.Call call = getMarketplaceParticipationsValidateBeforeCall(null, null); Type localVarReturnType = new TypeToken(){}.getType(); return apiClient.execute(call, localVarReturnType); } /** * (asynchronously) * Returns a list of marketplaces that the seller submitting the request can sell in and information about the * seller's participation in those marketplaces. * **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | .016 | 15 | * For more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation. * * @param callback The callback to be executed when the API call finishes * @return The request call * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public com.squareup.okhttp.Call getMarketplaceParticipationsAsync(final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { callback.onDownloadProgress(bytesRead, contentLength, done); } }; progressRequestListener = new ProgressRequestBody.ProgressRequestListener() { @Override public void onRequestProgress(long bytesWritten, long contentLength, boolean done) { callback.onUploadProgress(bytesWritten, contentLength, done); } }; } com.squareup.okhttp.Call call = getMarketplaceParticipationsValidateBeforeCall(progressListener, progressRequestListener); Type localVarReturnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, localVarReturnType, callback); return call; } public static class Builder extends SPAPIBuilder { @Override public SellersApi build(SellerCredentials sellerCredentials) throws NoSuchFieldException, IllegalAccessException { buildAuth(sellerCredentials); return new SellersApi(apiClient); } } /** * Authorize for the API call. * TODO - share the token cache with other functions. * * @param sellerCredentials * @return */ public static SellersApi buildSellerApi(SellerCredentials sellerCredentials) throws NoSuchFieldException, IllegalAccessException { return (new Builder()) .build(sellerCredentials); } // According to the nature of Lambda, in most cases it will not create memory leak. private static Map sellerApiHolder = new HashMap<>(); public static SellersApi getOrCreateSellersApi(SellerCredentials sellerCredentials) throws NoSuchFieldException, IllegalAccessException { SellersApi api = sellerApiHolder.get(Integer.toHexString(sellerCredentials.hashCode())); if (api == null) { api = SellersApi.buildSellerApi(sellerCredentials); sellerApiHolder.put(Integer.toHexString(sellerCredentials.hashCode()), api); logger.info("Seller API client created."); } return api; } public static ApiResponse getMarketplaceParticipations(SellerCredentials sellerCredentials) throws Throwable { // Seller API is per Seller - they have different secrets. final SellersApi sellersApi = SellersApi.getOrCreateSellersApi(sellerCredentials); final SellerGetMarketParticipation getMarketParticipation = new SellerGetMarketParticipation(sellersApi); final ApiProxy apiProxy = new ApiProxy<>(getMarketParticipation); final ApiResponse marketplaceParticipationsWithHttpInfo = apiProxy.invkWithToken(null, sellerCredentials.getSeller_id()); // No parameters are needed. return marketplaceParticipationsWithHttpInfo; } }