diff --git a/README.md b/README.md index 4d5f7d19..f05cc40b 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ implementation("com.tryfinch.api:finch-java:0.14.0") Use `FinchOkHttpClient.builder()` to configure the client. -Alternately, set the environment with `FINCH_CLIENT_ID`, `FINCH_CLIENT_SECRET` or `FINCH_WEBHOOK_SECRET`, and use `FinchOkHttpClient.fromEnv()` to read from the environment. +Alternately, set the environment with `FINCH_CLIENT_ID`, `FINCH_CLIENT_SECRET`, `FINCH_SANDBOX_CLIENT_ID`, `FINCH_SANDBOX_CLIENT_SECRET` or `FINCH_WEBHOOK_SECRET`, and use `FinchOkHttpClient.fromEnv()` to read from the environment. ```java FinchClient client = FinchOkHttpClient.fromEnv(); @@ -56,11 +56,13 @@ FinchClient client = FinchOkHttpClient.builder() .build(); ``` -| Property | Environment variable | Required | Default value | -| ------------- | ---------------------- | -------- | ------------- | -| clientId | `FINCH_CLIENT_ID` | false | — | -| clientSecret | `FINCH_CLIENT_SECRET` | false | — | -| webhookSecret | `FINCH_WEBHOOK_SECRET` | false | — | +| Property | Environment variable | Required | Default value | +| ------------------- | ----------------------------- | -------- | ------------- | +| clientId | `FINCH_CLIENT_ID` | false | — | +| clientSecret | `FINCH_CLIENT_SECRET` | false | — | +| sandboxClientId | `FINCH_SANDBOX_CLIENT_ID` | false | — | +| sandboxClientSecret | `FINCH_SANDBOX_CLIENT_SECRET` | false | — | +| webhookSecret | `FINCH_WEBHOOK_SECRET` | false | — | Read the documentation for more configuration options. diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt index 8788f347..84a642fc 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt @@ -68,6 +68,14 @@ class FinchOkHttpClient private constructor() { fun clientSecret(clientSecret: String?) = apply { clientOptions.clientSecret(clientSecret) } + fun sandboxClientId(sandboxClientId: String?) = apply { + clientOptions.sandboxClientId(sandboxClientId) + } + + fun sandboxClientSecret(sandboxClientSecret: String?) = apply { + clientOptions.sandboxClientSecret(sandboxClientSecret) + } + fun webhookSecret(webhookSecret: String?) = apply { clientOptions.webhookSecret(webhookSecret) } diff --git a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt index 22d3a9f3..dca97888 100644 --- a/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt +++ b/finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt @@ -68,6 +68,14 @@ class FinchOkHttpClientAsync private constructor() { fun clientSecret(clientSecret: String?) = apply { clientOptions.clientSecret(clientSecret) } + fun sandboxClientId(sandboxClientId: String?) = apply { + clientOptions.sandboxClientId(sandboxClientId) + } + + fun sandboxClientSecret(sandboxClientSecret: String?) = apply { + clientOptions.sandboxClientSecret(sandboxClientSecret) + } + fun webhookSecret(webhookSecret: String?) = apply { clientOptions.webhookSecret(webhookSecret) } diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt index 2e07bb4d..a7bf95e7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt @@ -26,8 +26,6 @@ interface FinchClient { fun jobs(): JobService - fun auth(): AuthService - fun sandbox(): SandboxService fun getAccessToken( diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt index 7cf05106..bfb4a57a 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt @@ -27,8 +27,6 @@ interface FinchClientAsync { fun jobs(): JobServiceAsync - fun auth(): AuthServiceAsync - fun sandbox(): SandboxServiceAsync fun getAccessToken( diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt index c2b3033d..00a7e690 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsyncImpl.kt @@ -45,8 +45,6 @@ constructor( private val jobs: JobServiceAsync by lazy { JobServiceAsyncImpl(clientOptions) } - private val auth: AuthServiceAsync by lazy { AuthServiceAsyncImpl(clientOptions) } - private val sandbox: SandboxServiceAsync by lazy { SandboxServiceAsyncImpl(clientOptions) } private val getAccessTokenHandler: Handler = @@ -68,8 +66,6 @@ constructor( override fun jobs(): JobServiceAsync = jobs - override fun auth(): AuthServiceAsync = auth - override fun sandbox(): SandboxServiceAsync = sandbox override fun getAccessToken( diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt index 09430114..6c733909 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientImpl.kt @@ -42,8 +42,6 @@ constructor( private val jobs: JobService by lazy { JobServiceImpl(clientOptions) } - private val auth: AuthService by lazy { AuthServiceImpl(clientOptions) } - private val sandbox: SandboxService by lazy { SandboxServiceImpl(clientOptions) } private val getAccessTokenHandler: Handler = @@ -65,8 +63,6 @@ constructor( override fun jobs(): JobService = jobs - override fun auth(): AuthService = auth - override fun sandbox(): SandboxService = sandbox override fun getAccessToken( diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt index f348ee17..a6e414c7 100644 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt +++ b/finch-java-core/src/main/kotlin/com/tryfinch/api/core/ClientOptions.kt @@ -18,6 +18,8 @@ private constructor( @get:JvmName("accessToken") val accessToken: String?, @get:JvmName("clientId") val clientId: String?, @get:JvmName("clientSecret") val clientSecret: String?, + @get:JvmName("sandboxClientId") val sandboxClientId: String?, + @get:JvmName("sandboxClientSecret") val sandboxClientSecret: String?, @get:JvmName("webhookSecret") val webhookSecret: String?, @get:JvmName("headers") val headers: ListMultimap, @get:JvmName("responseValidation") val responseValidation: Boolean, @@ -44,6 +46,8 @@ private constructor( private var accessToken: String? = null private var clientId: String? = null private var clientSecret: String? = null + private var sandboxClientId: String? = null + private var sandboxClientSecret: String? = null private var webhookSecret: String? = null fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient } @@ -85,11 +89,21 @@ private constructor( fun clientSecret(clientSecret: String?) = apply { this.clientSecret = clientSecret } + fun sandboxClientId(sandboxClientId: String?) = apply { + this.sandboxClientId = sandboxClientId + } + + fun sandboxClientSecret(sandboxClientSecret: String?) = apply { + this.sandboxClientSecret = sandboxClientSecret + } + fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret } fun fromEnv() = apply { System.getenv("FINCH_CLIENT_ID")?.let { clientId(it) } System.getenv("FINCH_CLIENT_SECRET")?.let { clientSecret(it) } + System.getenv("FINCH_SANDBOX_CLIENT_ID")?.let { sandboxClientId(it) } + System.getenv("FINCH_SANDBOX_CLIENT_SECRET")?.let { sandboxClientSecret(it) } System.getenv("FINCH_WEBHOOK_SECRET")?.let { webhookSecret(it) } } @@ -119,6 +133,8 @@ private constructor( accessToken, clientId, clientSecret, + sandboxClientId, + sandboxClientSecret, webhookSecret, headers.toUnmodifiable(), responseValidation, diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/AuthCreateTokenParams.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/models/AuthCreateTokenParams.kt deleted file mode 100644 index 056d206c..00000000 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/models/AuthCreateTokenParams.kt +++ /dev/null @@ -1,303 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.tryfinch.api.models - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.tryfinch.api.core.ExcludeMissing -import com.tryfinch.api.core.JsonValue -import com.tryfinch.api.core.NoAutoDetect -import com.tryfinch.api.core.toUnmodifiable -import com.tryfinch.api.models.* -import java.util.Objects - -class AuthCreateTokenParams -constructor( - private val clientId: String, - private val clientSecret: String, - private val code: String, - private val redirectUri: String, - private val additionalQueryParams: Map>, - private val additionalHeaders: Map>, - private val additionalBodyProperties: Map, -) { - - fun clientId(): String = clientId - - fun clientSecret(): String = clientSecret - - fun code(): String = code - - fun redirectUri(): String = redirectUri - - @JvmSynthetic - internal fun getBody(): AuthCreateTokenBody { - return AuthCreateTokenBody( - clientId, - clientSecret, - code, - redirectUri, - additionalBodyProperties, - ) - } - - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams - - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JsonDeserialize(builder = AuthCreateTokenBody.Builder::class) - @NoAutoDetect - class AuthCreateTokenBody - internal constructor( - private val clientId: String?, - private val clientSecret: String?, - private val code: String?, - private val redirectUri: String?, - private val additionalProperties: Map, - ) { - - private var hashCode: Int = 0 - - @JsonProperty("client_id") fun clientId(): String? = clientId - - @JsonProperty("client_secret") fun clientSecret(): String? = clientSecret - - @JsonProperty("code") fun code(): String? = code - - @JsonProperty("redirect_uri") fun redirectUri(): String? = redirectUri - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder().from(this) - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is AuthCreateTokenBody && - this.clientId == other.clientId && - this.clientSecret == other.clientSecret && - this.code == other.code && - this.redirectUri == other.redirectUri && - this.additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = - Objects.hash( - clientId, - clientSecret, - code, - redirectUri, - additionalProperties, - ) - } - return hashCode - } - - override fun toString() = - "AuthCreateTokenBody{clientId=$clientId, clientSecret=$clientSecret, code=$code, redirectUri=$redirectUri, additionalProperties=$additionalProperties}" - - companion object { - - @JvmStatic fun builder() = Builder() - } - - class Builder { - - private var clientId: String? = null - private var clientSecret: String? = null - private var code: String? = null - private var redirectUri: String? = null - private var additionalProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(authCreateTokenBody: AuthCreateTokenBody) = apply { - this.clientId = authCreateTokenBody.clientId - this.clientSecret = authCreateTokenBody.clientSecret - this.code = authCreateTokenBody.code - this.redirectUri = authCreateTokenBody.redirectUri - additionalProperties(authCreateTokenBody.additionalProperties) - } - - @JsonProperty("client_id") - fun clientId(clientId: String) = apply { this.clientId = clientId } - - @JsonProperty("client_secret") - fun clientSecret(clientSecret: String) = apply { this.clientSecret = clientSecret } - - @JsonProperty("code") fun code(code: String) = apply { this.code = code } - - @JsonProperty("redirect_uri") - fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): AuthCreateTokenBody = - AuthCreateTokenBody( - checkNotNull(clientId) { "`clientId` is required but was not set" }, - checkNotNull(clientSecret) { "`clientSecret` is required but was not set" }, - checkNotNull(code) { "`code` is required but was not set" }, - checkNotNull(redirectUri) { "`redirectUri` is required but was not set" }, - additionalProperties.toUnmodifiable(), - ) - } - } - - fun _additionalQueryParams(): Map> = additionalQueryParams - - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalBodyProperties(): Map = additionalBodyProperties - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is AuthCreateTokenParams && - this.clientId == other.clientId && - this.clientSecret == other.clientSecret && - this.code == other.code && - this.redirectUri == other.redirectUri && - this.additionalQueryParams == other.additionalQueryParams && - this.additionalHeaders == other.additionalHeaders && - this.additionalBodyProperties == other.additionalBodyProperties - } - - override fun hashCode(): Int { - return Objects.hash( - clientId, - clientSecret, - code, - redirectUri, - additionalQueryParams, - additionalHeaders, - additionalBodyProperties, - ) - } - - override fun toString() = - "AuthCreateTokenParams{clientId=$clientId, clientSecret=$clientSecret, code=$code, redirectUri=$redirectUri, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders, additionalBodyProperties=$additionalBodyProperties}" - - fun toBuilder() = Builder().from(this) - - companion object { - - @JvmStatic fun builder() = Builder() - } - - @NoAutoDetect - class Builder { - - private var clientId: String? = null - private var clientSecret: String? = null - private var code: String? = null - private var redirectUri: String? = null - private var additionalQueryParams: MutableMap> = mutableMapOf() - private var additionalHeaders: MutableMap> = mutableMapOf() - private var additionalBodyProperties: MutableMap = mutableMapOf() - - @JvmSynthetic - internal fun from(authCreateTokenParams: AuthCreateTokenParams) = apply { - this.clientId = authCreateTokenParams.clientId - this.clientSecret = authCreateTokenParams.clientSecret - this.code = authCreateTokenParams.code - this.redirectUri = authCreateTokenParams.redirectUri - additionalQueryParams(authCreateTokenParams.additionalQueryParams) - additionalHeaders(authCreateTokenParams.additionalHeaders) - additionalBodyProperties(authCreateTokenParams.additionalBodyProperties) - } - - fun clientId(clientId: String) = apply { this.clientId = clientId } - - fun clientSecret(clientSecret: String) = apply { this.clientSecret = clientSecret } - - fun code(code: String) = apply { this.code = code } - - fun redirectUri(redirectUri: String) = apply { this.redirectUri = redirectUri } - - fun additionalQueryParams(additionalQueryParams: Map>) = apply { - this.additionalQueryParams.clear() - putAllQueryParams(additionalQueryParams) - } - - fun putQueryParam(name: String, value: String) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.add(value) - } - - fun putQueryParams(name: String, values: Iterable) = apply { - this.additionalQueryParams.getOrPut(name) { mutableListOf() }.addAll(values) - } - - fun putAllQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(this::putQueryParams) - } - - fun removeQueryParam(name: String) = apply { - this.additionalQueryParams.put(name, mutableListOf()) - } - - fun additionalHeaders(additionalHeaders: Map>) = apply { - this.additionalHeaders.clear() - putAllHeaders(additionalHeaders) - } - - fun putHeader(name: String, value: String) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.add(value) - } - - fun putHeaders(name: String, values: Iterable) = apply { - this.additionalHeaders.getOrPut(name) { mutableListOf() }.addAll(values) - } - - fun putAllHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(this::putHeaders) - } - - fun removeHeader(name: String) = apply { this.additionalHeaders.put(name, mutableListOf()) } - - fun additionalBodyProperties(additionalBodyProperties: Map) = apply { - this.additionalBodyProperties.clear() - this.additionalBodyProperties.putAll(additionalBodyProperties) - } - - fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { - this.additionalBodyProperties.put(key, value) - } - - fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = - apply { - this.additionalBodyProperties.putAll(additionalBodyProperties) - } - - fun build(): AuthCreateTokenParams = - AuthCreateTokenParams( - checkNotNull(clientId) { "`clientId` is required but was not set" }, - checkNotNull(clientSecret) { "`clientSecret` is required but was not set" }, - checkNotNull(code) { "`code` is required but was not set" }, - checkNotNull(redirectUri) { "`redirectUri` is required but was not set" }, - additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(), - additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(), - additionalBodyProperties.toUnmodifiable(), - ) - } -} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsync.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsync.kt deleted file mode 100644 index 9912388e..00000000 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsync.kt +++ /dev/null @@ -1,20 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102 - -package com.tryfinch.api.services.async - -import com.tryfinch.api.core.RequestOptions -import com.tryfinch.api.models.AuthCreateTokenParams -import com.tryfinch.api.models.CreateAccessTokenResponse -import java.util.concurrent.CompletableFuture - -interface AuthServiceAsync { - - /** Exchange the authorization code for an access token */ - @JvmOverloads - fun createToken( - params: AuthCreateTokenParams, - requestOptions: RequestOptions = RequestOptions.none() - ): CompletableFuture -} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsyncImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsyncImpl.kt deleted file mode 100644 index 13d613f4..00000000 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/async/AuthServiceAsyncImpl.kt +++ /dev/null @@ -1,55 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.tryfinch.api.services.async - -import com.tryfinch.api.core.ClientOptions -import com.tryfinch.api.core.RequestOptions -import com.tryfinch.api.core.http.HttpMethod -import com.tryfinch.api.core.http.HttpRequest -import com.tryfinch.api.core.http.HttpResponse.Handler -import com.tryfinch.api.errors.FinchError -import com.tryfinch.api.models.AuthCreateTokenParams -import com.tryfinch.api.models.CreateAccessTokenResponse -import com.tryfinch.api.services.errorHandler -import com.tryfinch.api.services.json -import com.tryfinch.api.services.jsonHandler -import com.tryfinch.api.services.withErrorHandler -import java.util.concurrent.CompletableFuture - -class AuthServiceAsyncImpl -constructor( - private val clientOptions: ClientOptions, -) : AuthServiceAsync { - - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - - private val createTokenHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) - - /** Exchange the authorization code for an access token */ - override fun createToken( - params: AuthCreateTokenParams, - requestOptions: RequestOptions - ): CompletableFuture { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .addPathSegments("auth", "token") - .putAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) - .body(json(clientOptions.jsonMapper, params.getBody())) - .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { createTokenHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } - } - } - } -} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthService.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthService.kt deleted file mode 100644 index 918bdd9a..00000000 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthService.kt +++ /dev/null @@ -1,19 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102 - -package com.tryfinch.api.services.blocking - -import com.tryfinch.api.core.RequestOptions -import com.tryfinch.api.models.AuthCreateTokenParams -import com.tryfinch.api.models.CreateAccessTokenResponse - -interface AuthService { - - /** Exchange the authorization code for an access token */ - @JvmOverloads - fun createToken( - params: AuthCreateTokenParams, - requestOptions: RequestOptions = RequestOptions.none() - ): CreateAccessTokenResponse -} diff --git a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthServiceImpl.kt b/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthServiceImpl.kt deleted file mode 100644 index cb5d7a02..00000000 --- a/finch-java-core/src/main/kotlin/com/tryfinch/api/services/blocking/AuthServiceImpl.kt +++ /dev/null @@ -1,53 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.tryfinch.api.services.blocking - -import com.tryfinch.api.core.ClientOptions -import com.tryfinch.api.core.RequestOptions -import com.tryfinch.api.core.http.HttpMethod -import com.tryfinch.api.core.http.HttpRequest -import com.tryfinch.api.core.http.HttpResponse.Handler -import com.tryfinch.api.errors.FinchError -import com.tryfinch.api.models.AuthCreateTokenParams -import com.tryfinch.api.models.CreateAccessTokenResponse -import com.tryfinch.api.services.errorHandler -import com.tryfinch.api.services.json -import com.tryfinch.api.services.jsonHandler -import com.tryfinch.api.services.withErrorHandler - -class AuthServiceImpl -constructor( - private val clientOptions: ClientOptions, -) : AuthService { - - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) - - private val createTokenHandler: Handler = - jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) - - /** Exchange the authorization code for an access token */ - override fun createToken( - params: AuthCreateTokenParams, - requestOptions: RequestOptions - ): CreateAccessTokenResponse { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .addPathSegments("auth", "token") - .putAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .putAllHeaders(params.getHeaders()) - .body(json(clientOptions.jsonMapper, params.getBody())) - .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { createTokenHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } - } - } - } -} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/AuthCreateTokenParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/models/AuthCreateTokenParamsTest.kt deleted file mode 100644 index f63639c1..00000000 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/models/AuthCreateTokenParamsTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.tryfinch.api.models - -import com.tryfinch.api.models.* -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -class AuthCreateTokenParamsTest { - - @Test - fun createAuthCreateTokenParams() { - AuthCreateTokenParams.builder() - .clientId("") - .clientSecret("") - .code("") - .redirectUri("https://example.com") - .build() - } - - @Test - fun getBody() { - val params = - AuthCreateTokenParams.builder() - .clientId("") - .clientSecret("") - .code("") - .redirectUri("https://example.com") - .build() - val body = params.getBody() - assertThat(body).isNotNull - assertThat(body.clientId()).isEqualTo("") - assertThat(body.clientSecret()).isEqualTo("") - assertThat(body.code()).isEqualTo("") - assertThat(body.redirectUri()).isEqualTo("https://example.com") - } - - @Test - fun getBodyWithoutOptionalFields() { - val params = - AuthCreateTokenParams.builder() - .clientId("") - .clientSecret("") - .code("") - .redirectUri("https://example.com") - .build() - val body = params.getBody() - assertThat(body).isNotNull - assertThat(body.clientId()).isEqualTo("") - assertThat(body.clientSecret()).isEqualTo("") - assertThat(body.code()).isEqualTo("") - assertThat(body.redirectUri()).isEqualTo("https://example.com") - } -} diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ErrorHandlingTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ErrorHandlingTest.kt index 45a14554..badb1fe0 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ErrorHandlingTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ErrorHandlingTest.kt @@ -52,6 +52,8 @@ class ErrorHandlingTest { .accessToken("My Access Token") .clientId("My Client ID") .clientSecret("My Client Secret") + .sandboxClientId("My Sandbox Client ID") + .sandboxClientSecret("My Sandbox Client Secret") .webhookSecret("My Webhook Secret") .build() } diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ServiceParamsTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ServiceParamsTest.kt index 01337a2f..eb246a9b 100644 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ServiceParamsTest.kt +++ b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/ServiceParamsTest.kt @@ -35,6 +35,8 @@ class ServiceParamsTest { .accessToken("My Access Token") .clientId("My Client ID") .clientSecret("My Client Secret") + .sandboxClientId("My Sandbox Client ID") + .sandboxClientSecret("My Sandbox Client Secret") .webhookSecret("My Webhook Secret") .baseUrl(wmRuntimeInfo.getHttpBaseUrl()) .build() diff --git a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/AuthServiceTest.kt b/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/AuthServiceTest.kt deleted file mode 100644 index 5a392224..00000000 --- a/finch-java-core/src/test/kotlin/com/tryfinch/api/services/blocking/AuthServiceTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. - -package com.tryfinch.api.services.blocking - -import com.tryfinch.api.TestServerExtension -import com.tryfinch.api.client.okhttp.FinchOkHttpClient -import com.tryfinch.api.models.* -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith - -@ExtendWith(TestServerExtension::class) -class AuthServiceTest { - - @Test - fun callCreateToken() { - val client = - FinchOkHttpClient.builder() - .baseUrl(TestServerExtension.BASE_URL) - .accessToken("My Access Token") - .build() - val authService = client.auth() - val createAccessTokenResponse = - authService.createToken( - AuthCreateTokenParams.builder() - .clientId("") - .clientSecret("") - .code("") - .redirectUri("https://example.com") - .build() - ) - println(createAccessTokenResponse) - createAccessTokenResponse.validate() - } -}