Search in sources :

Example 1 with ConcordApiClient

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;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) HashMap(java.util.HashMap) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient)

Example 2 with ConcordApiClient

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;
}
Also used : ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ApiClient(com.walmartlabs.concord.ApiClient) UUID(java.util.UUID)

Example 3 with ConcordApiClient

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;
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(com.walmartlabs.concord.sdk.Context) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ConcordApiClient(com.walmartlabs.concord.client.ConcordApiClient) ApiClient(com.walmartlabs.concord.ApiClient) UUID(java.util.UUID)

Aggregations

ConcordApiClient (com.walmartlabs.concord.client.ConcordApiClient)3 ApiClient (com.walmartlabs.concord.ApiClient)2 UUID (java.util.UUID)2 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 Context (com.walmartlabs.concord.sdk.Context)1 HashMap (java.util.HashMap)1 SSLContext (javax.net.ssl.SSLContext)1