Skip to content

Commit

Permalink
Regenerate Java SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiechayes committed Nov 1, 2023
1 parent d060378 commit 12cf83c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
4 changes: 2 additions & 2 deletions STATISTICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

| SDK Name | Lines of Code |
| -------- | ------------- |
| java | 42451 |
| java | 42479 |
| python | 44380 |
| typescript | 9606 |
| csharp | 23097 |
| php | 45015 |
| go | 30391 |
| **Total** | 194940 |
| **Total** | 194968 |
2 changes: 1 addition & 1 deletion java/.konfig/generate-id.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0fb55136-34a5-4098-b84b-85f9afffa3c3
4233d460-1b1f-4b84-ae0a-2b31b3ef60a1
80 changes: 53 additions & 27 deletions java/src/main/java/com/konfigthis/splitit/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
public class ApiClient extends ApiClientCustom {

private String basePath = "https://web-api-v3.production.splitit.com";
private String tokenUrl = "https://id.production.splitit.com/connect/token";
private boolean debugging = false;
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
Expand Down Expand Up @@ -105,21 +106,24 @@ public ApiClient(OkHttpClient client) {

public ApiClient(OkHttpClient client, Configuration configuration) {
init();
if (client == null) {
initHttpClient();
} else {
this.httpClient = client;
if (configuration != null) {
// Setting up authentications, if applicable, may rely on the following, so we initialize them first
setBasePath(configuration.host);
setTokenUrl(configuration.tokenUrl);
}

// Setup authentications (key: authentication name, value: authentication).
authentications.put("oauth", new OAuth());
RetryingOAuth oauth = configuration != null ? setupOauth(configuration.clientId, configuration.clientSecret, null) : null;
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);

if (configuration != null) {
if (client == null) {
initHttpClient(oauth != null ? Collections.singletonList(oauth) : Collections.emptyList());
} else {
this.httpClient = client;
}

if (configuration != null) {
setVerifyingSsl(configuration.verifyingSsl);
setBasePath(configuration.host);
}
}
/**
Expand Down Expand Up @@ -165,31 +169,29 @@ public ApiClient(String basePath, String clientId, String clientSecret, Map<Stri
if (basePath != null) {
this.basePath = basePath;
}
// Setup authentications (key: authentication name, value: authentication).
RetryingOAuth oauth = setupOauth(clientId, clientSecret, parameters);
initHttpClient(Collections.singletonList(oauth));

// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}

String tokenUrl = "https://id.production.splitit.com/connect/token";
if (!"".equals(tokenUrl) && !URI.create(tokenUrl).isAbsolute()) {
private RetryingOAuth setupOauth(String clientId, String clientSecret, Map<String, String> parameters) {
if (!"".equals(getTokenUrl()) && !URI.create(getTokenUrl()).isAbsolute()) {
URI uri = URI.create(getBasePath());
tokenUrl = uri.getScheme() + ":" +
(uri.getAuthority() != null ? "//" + uri.getAuthority() : "") +
tokenUrl;
if (!URI.create(tokenUrl).isAbsolute()) {
setTokenUrl(uri.getScheme() + ":"
+ (uri.getAuthority() != null ? "//" + uri.getAuthority() : "")
+ getTokenUrl());
if (!URI.create(getTokenUrl()).isAbsolute()) {
throw new IllegalArgumentException("OAuth2 token URL must be an absolute URL");
}
}
RetryingOAuth retryingOAuth = new RetryingOAuth(tokenUrl, clientId, OAuthFlow.APPLICATION, clientSecret, parameters);
authentications.put(
"oauth",
retryingOAuth
);
initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
// Setup authentications (key: authentication name, value: authentication).

// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
RetryingOAuth oauth = new RetryingOAuth(getTokenUrl(), clientId, OAuthFlow.APPLICATION, clientSecret, parameters);
authentications.put("oauth", oauth);
return oauth;
}



private void initHttpClient() {
initHttpClient(Collections.<Interceptor>emptyList());
}
Expand Down Expand Up @@ -228,7 +230,7 @@ public String getBasePath() {
/**
* Set base path
*
* @param basePath Base path of the URL (e.g https://web-api-v3.production.splitit.com
* @param basePath Base path of the URL (e.g https://web-api-v3.production.splitit.com)
* @return An instance of OkHttpClient
*/
public ApiClient setBasePath(String basePath) {
Expand All @@ -240,6 +242,30 @@ public ApiClient setBasePath(String basePath) {
return this;
}

/**
* Get token url
*
* @return token url
*/
public String getTokenUrl() {
return tokenUrl;
}

/**
* Set token url
*
* @param tokenUrl Token URL for oauth (e.g https://id.production.splitit.com/connect/token)
* @return An instance of OkHttpClient
*/
public ApiClient setTokenUrl(String tokenUrl) {
// strip trailing slash from tokenUrl
if (tokenUrl != null && tokenUrl.endsWith("/")) {
tokenUrl = tokenUrl.substring(0, tokenUrl.length() - 1);
}
this.tokenUrl = tokenUrl;
return this;
}

/**
* Get HTTP client
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Configuration {
private static ApiClient defaultApiClient = new ApiClient();
public boolean verifyingSsl = true;
public String host = "https://web-api-v3.production.splitit.com";
public String tokenUrl = "https://id.production.splitit.com/connect/token";
public String clientId;
public String clientSecret;

Expand Down

0 comments on commit 12cf83c

Please sign in to comment.