com.convertapi.client.Config Maven / Gradle / Ivy
package com.convertapi.client;
import okhttp3.OkHttpClient;
import java.util.function.Function;
public class Config {
private static String defaultSecret;
private static int defaultTimeout = 0; // Infinite read waiting
private static Function defaultHttpClientBuilder = b -> b;
private static final String SCHEME = "https";
@SuppressWarnings("SpellCheckingInspection")
private static final String HOST = "v2.convertapi.com";
private final String scheme;
private final String host;
private final String secret;
private final int timeout;
private final Function httpClientBuilder;
@SuppressWarnings("unused")
public Config(String secret, String scheme, String host, int timeout, Function httpClientBuilder) {
this.scheme = scheme;
this.host = host;
this.secret = secret;
this.timeout = timeout;
this.httpClientBuilder = httpClientBuilder;
}
@SuppressWarnings("WeakerAccess")
public static Config defaults() {
return new Config(Config.defaultSecret, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder);
}
@SuppressWarnings("WeakerAccess")
public static Config defaults(String secret) {
return new Config(secret, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder);
}
@SuppressWarnings("WeakerAccess")
public static Config defaults(String secret, Function httpClientBuilder) {
return new Config(secret, SCHEME, HOST, defaultTimeout, httpClientBuilder);
}
@SuppressWarnings("unused")
public static void setDefaultSecret(String defaultSecret) {
Config.defaultSecret = defaultSecret;
}
@SuppressWarnings("unused")
public static void setDefaultTimeout(int defaultTimeout) {
Config.defaultTimeout = defaultTimeout;
}
@SuppressWarnings("unused")
public static void setDefaultHttpBuilder(Function httpClientBuilder) {
Config.defaultHttpClientBuilder = httpClientBuilder;
}
int getTimeout() {
return timeout;
}
String getScheme() {
return scheme;
}
String getHost() {
return host;
}
String getSecret() {
return secret;
}
Function getHttpClientBuilder() {
return httpClientBuilder;
}
}