Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ interface FinchClient {

fun jobs(): JobService

fun auth(): AuthService

fun sandbox(): SandboxService

fun getAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ interface FinchClientAsync {

fun jobs(): JobServiceAsync

fun auth(): AuthServiceAsync

fun sandbox(): SandboxServiceAsync

fun getAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetAccessTokenResponse> =
Expand All @@ -68,8 +66,6 @@ constructor(

override fun jobs(): JobServiceAsync = jobs

override fun auth(): AuthServiceAsync = auth

override fun sandbox(): SandboxServiceAsync = sandbox

override fun getAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetAccessTokenResponse> =
Expand All @@ -65,8 +63,6 @@ constructor(

override fun jobs(): JobService = jobs

override fun auth(): AuthService = auth

override fun sandbox(): SandboxService = sandbox

override fun getAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
@get:JvmName("responseValidation") val responseValidation: Boolean,
Expand All @@ -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 }
Expand Down Expand Up @@ -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) }
}

Expand Down Expand Up @@ -119,6 +133,8 @@ private constructor(
accessToken,
clientId,
clientSecret,
sandboxClientId,
sandboxClientSecret,
webhookSecret,
headers.toUnmodifiable(),
responseValidation,
Expand Down
Loading