use of com.walmartlabs.concord.client.ConcordApiClient in project concord by walmartlabs.
the class ApiClientFactory method create.
public ApiClient create(String sessionToken) throws IOException {
OkHttpClient ok = new OkHttpClient();
ok.setReadTimeout(cfg.getReadTimeout(), TimeUnit.MILLISECONDS);
ok.setConnectTimeout(cfg.getConnectTimeout(), TimeUnit.MILLISECONDS);
Map<String, String> cookieJar = new HashMap<>();
ok.interceptors().add(new AddCookiesInterceptor(cookieJar));
ok.interceptors().add(new ReceivedCookiesInterceptor(cookieJar));
ConcordApiClient client = new ConcordApiClient(cfg.getApiBaseUrl(), ok);
client.setTempFolderPath(tmpPath.toString());
if (sessionToken != null) {
client.setSessionToken(sessionToken);
} else {
client.setApiKey(cfg.getApiKey());
}
client.setUserAgent(cfg.getUserAgent());
client.setVerifyingSsl(cfg.isVerifySsl());
return client;
}
use of com.walmartlabs.concord.client.ConcordApiClient in project concord by walmartlabs.
the class ApiClientFactoryImpl method create.
@Override
public ApiClient create(ApiClientConfiguration overrides) {
String baseUrl = overrides.baseUrl() != null ? overrides.baseUrl() : cfg.baseUrl();
String sessionToken = null;
if (overrides.apiKey() == null) {
sessionToken = overrides.sessionToken();
}
String apiKey = overrides.apiKey();
if (apiKey != null) {
sessionToken = null;
}
if (sessionToken == null && apiKey == null) {
throw new IllegalArgumentException("Session token or an API key is required");
}
ApiClient client = new ConcordApiClient(baseUrl, httpClient).setSessionToken(sessionToken).setApiKey(apiKey).addDefaultHeader("Accept", "*/*").setTempFolderPath(tmpDir.toString());
UUID txId = instanceId.getValue();
if (txId != null) {
client = client.setUserAgent("Concord-Runner-v2: txId=" + txId);
}
return client;
}
use of com.walmartlabs.concord.client.ConcordApiClient in project concord by walmartlabs.
the class ApiClientFactoryImpl method create.
@Override
public ApiClient create(ApiClientConfiguration overrides) {
String baseUrl = overrides.baseUrl() != null ? overrides.baseUrl() : cfg.getBaseUrl();
String sessionToken = null;
if (overrides.apiKey() == null) {
sessionToken = overrides.sessionToken();
Context ctx = overrides.context();
if (sessionToken == null && ctx != null) {
sessionToken = cfg.getSessionToken(ctx);
}
}
String apiKey = overrides.apiKey();
if (apiKey != null) {
sessionToken = null;
}
if (sessionToken == null && apiKey == null) {
throw new IllegalArgumentException("Session token or an API key is required");
}
ApiClient client = new ConcordApiClient(baseUrl, httpClient).setSessionToken(sessionToken).setApiKey(apiKey).addDefaultHeader("Accept", "*/*").setTempFolderPath(tmpDir.toString());
UUID txId = getTxId(overrides);
if (txId != null) {
client = client.setUserAgent("Concord-Runner: txId=" + txId);
}
return client;
}
Aggregations