From 12cf83c498a8bc58371f167d3a431429f8e7b956 Mon Sep 17 00:00:00 2001 From: eddiechayes Date: Wed, 1 Nov 2023 16:50:21 -0700 Subject: [PATCH] Regenerate Java SDK --- STATISTICS.md | 4 +- java/.konfig/generate-id.txt | 2 +- .../konfigthis/splitit/client/ApiClient.java | 80 ++++++++++++------- .../splitit/client/Configuration.java | 1 + 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/STATISTICS.md b/STATISTICS.md index 4d0ef3fa..1f41f17a 100644 --- a/STATISTICS.md +++ b/STATISTICS.md @@ -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 | diff --git a/java/.konfig/generate-id.txt b/java/.konfig/generate-id.txt index 0e3889c8..95777a3e 100644 --- a/java/.konfig/generate-id.txt +++ b/java/.konfig/generate-id.txt @@ -1 +1 @@ -0fb55136-34a5-4098-b84b-85f9afffa3c3 \ No newline at end of file +4233d460-1b1f-4b84-ae0a-2b31b3ef60a1 \ No newline at end of file diff --git a/java/src/main/java/com/konfigthis/splitit/client/ApiClient.java b/java/src/main/java/com/konfigthis/splitit/client/ApiClient.java index c191619f..acb7263d 100644 --- a/java/src/main/java/com/konfigthis/splitit/client/ApiClient.java +++ b/java/src/main/java/com/konfigthis/splitit/client/ApiClient.java @@ -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 defaultHeaderMap = new HashMap(); private Map defaultCookieMap = new HashMap(); @@ -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); } } /** @@ -165,31 +169,29 @@ public ApiClient(String basePath, String clientId, String clientSecret, Map 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.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.emptyList()); } @@ -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) { @@ -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 * diff --git a/java/src/main/java/com/konfigthis/splitit/client/Configuration.java b/java/src/main/java/com/konfigthis/splitit/client/Configuration.java index 60c2e70c..6bbaa58f 100644 --- a/java/src/main/java/com/konfigthis/splitit/client/Configuration.java +++ b/java/src/main/java/com/konfigthis/splitit/client/Configuration.java @@ -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;