com.foresee.api.sdk.clients.BaseApiClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of public-api-sdk Show documentation
Show all versions of public-api-sdk Show documentation
SDK to access Foresee data over Public API
package com.foresee.api.sdk.clients;
import com.amazonaws.mobileconnectors.apigateway.ApiClientFactory;
import com.foresee.api.sdk.common.Environment;
import com.google.common.base.Strings;
public class BaseApiClient {
/** Accept header */
protected static final String ACCEPT_HEADER= "Accept";
/** Content type header */
protected static final String CONTENT_TYPE_HEADER= "Content-Type";
/** Content type for json payloads */
protected static final String CONTENT_TYPE_JSON = "application/json";
/** Client Credentials Grant Type */
protected static final String GRANT_TYPE_CLIENT_CREDENTIALS = "client_credentials";
/** Basic Auth Header Prefix */
protected static final String AUTHORIZATION_HEADER = "Authorization";
/** Basic Auth Header Prefix */
protected static final String AUTHORIZATION_HEADER_PREFIX_BASIC = "Basic ";
/** Bearer Auth Header Prefix */
protected static final String AUTHORIZATION_HEADER_PREFIX_BEARER = "Bearer ";
/** Content type for json payloads */
protected static final String SCOPE = "r";
/** Factory to get a handle on the Public API Client */
private final ApiClientFactory factory;
/** Instance of various clients */
private final PublicAPIsVersionClient apiClient;
/** The environment for this client */
private Environment environment;
public BaseApiClient(Environment env) {
environment = env;
factory = new ApiClientFactory();
if (env == Environment.DEVELOPMENT) {
apiClient = factory.build(PublicAPIsVersionClient_DEV.class);
} else if (env == Environment.QA) {
apiClient = factory.build(PublicAPIsVersionClient_QA.class);
} else if (env == Environment.STAGING) {
apiClient = factory.build(PublicAPIsVersionClient_STG.class);
} else {
apiClient = factory.build(PublicAPIsVersionClient_PROD.class);
}
}
/**
* Get the instance of the Public API Client
* @return
*/
public PublicAPIsVersionClient apiClient() {
return apiClient;
}
protected String getAuthorizationHeader(String accessToken) {
if (Strings.isNullOrEmpty(accessToken)) {
throw new IllegalArgumentException("Passed accessToken cannot be null or empty");
}
return AUTHORIZATION_HEADER_PREFIX_BEARER + accessToken;
}
/**
* The environment
* @return
*/
public Environment getEnvironment() {
return environment;
}
}