Skip to content

Commit 69b83cf

Browse files
committed
feat: generate client interfaces and refactor client builder
1 parent f6a3a55 commit 69b83cf

200 files changed

Lines changed: 1375 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ implementation("com.lithic.api:lithic-java:0.0.0-alpha1")
3030

3131
### Configure the client
3232

33-
Use `LithicClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
33+
Use `LithicOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`:
3434

3535
```java
36-
import com.lithic.api.client.okhttp.LithicClient;
36+
import com.lithic.api.client.LithicClient;
37+
import com.lithic.api.client.okhttp.LithicOkHttpClient;
3738

38-
LithicClient client = LithicClient.builder()
39+
LithicClient client = LithicOkHttpClient.builder()
3940
.apiKey("<your API Key>")
4041
.build();
4142
```
4243

43-
Alternately, set the environment variable `LITHIC_API_KEY` and use `LithicClient.fromEnv()`:
44+
Alternately, set the environment variable `LITHIC_API_KEY` and use `LithicOkHttpClient.fromEnv()`:
4445

4546
```java
4647
LithicClient client = LithicClient.fromEnv();
@@ -56,7 +57,6 @@ To create a new card, first use the `CardCreateParams` builder to specify attrib
5657
then pass that to the `create` method of the `cards` service.
5758

5859
```java
59-
import com.lithic.api.client.okhttp.LithicClient;
6060
import com.lithic.api.models.Card;
6161
import com.lithic.api.models.CardCreateParams;
6262

@@ -72,7 +72,6 @@ The Lithic API provides a `list` method to get a paginated list of cards.
7272
You can retrieve the first page by:
7373

7474
```java
75-
import com.lithic.api.client.okhttp.LithicClient;
7675
import com.lithic.api.models.Card;
7776
import com.lithic.api.models.Page;
7877

@@ -270,21 +269,21 @@ Requests that experience certain errors are automatically retried 2 times by def
270269
You can provide a `maxRetries` on the client builder to configure this:
271270

272271
```java
273-
LithicClient client = LithicClient.builder().fromEnv().maxRetries(4).build();
272+
LithicClient client = LithicOkHttpClient.builder().fromEnv().maxRetries(4).build();
274273
```
275274

276275
### Timeouts
277276

278277
Requests time out after 60 seconds by default. You can configure this on the client builder:
279278

280279
```java
281-
LithicClient client = LithicClient.builder().fromEnv().timeout(Duration.ofSeconds(30)).build();
280+
LithicClient client = LithicOkHttpClient.builder().fromEnv().timeout(Duration.ofSeconds(30)).build();
282281
```
283282

284283
### Environments
285284

286285
Requests are made to the production environment by default. You can connect to other environments, like `sandbox`, via the client builder:
287286

288287
```java
289-
LithicClient client = LithicClient.builder().fromEnv().sandbox().build()
288+
LithicClient client = LithicOkHttpClient.builder().fromEnv().sandbox().build()
290289
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.lithic.api.client
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.junit.jupiter.api.Test
5+
6+
class LithicClientTest

lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/LithicClient.kt

Lines changed: 0 additions & 78 deletions
This file was deleted.

lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/LithicClientAsync.kt

Lines changed: 0 additions & 80 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.lithic.api.client.okhttp
2+
3+
import com.lithic.api.client.LithicClient
4+
import com.lithic.api.client.LithicClientImpl
5+
import com.lithic.api.core.ClientOptions
6+
import java.time.Duration
7+
8+
class LithicOkHttpClient private constructor() {
9+
10+
companion object {
11+
12+
@JvmStatic fun builder() = Builder()
13+
14+
@JvmStatic fun fromEnv(): LithicClient = builder().fromEnv().build()
15+
}
16+
17+
class Builder {
18+
19+
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
20+
private var baseUrl: String = ClientOptions.PRODUCTION_URL
21+
private var timeout: Duration = Duration.ofSeconds(60)
22+
private var maxRetries: Int = 2
23+
24+
fun sandbox() = apply { baseUrl(ClientOptions.SANDBOX_URL) }
25+
26+
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
27+
28+
fun timeout(timeout: Duration) = apply { this.timeout = timeout }
29+
30+
fun maxRetries(maxRetries: Int) = apply { this.clientOptions.maxRetries(maxRetries) }
31+
32+
fun apiKey(apiKey: String): Builder = apply { clientOptions.apiKey(apiKey) }
33+
34+
fun fromEnv(): Builder = apply { clientOptions.fromEnv() }
35+
36+
fun build(): LithicClient {
37+
return LithicClientImpl(
38+
clientOptions
39+
.httpClient(OkHttpClient.builder().baseUrl(baseUrl).timeout(timeout).build())
40+
.build()
41+
)
42+
}
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.lithic.api.client.okhttp
2+
3+
import com.lithic.api.client.LithicClientAsync
4+
import com.lithic.api.client.LithicClientAsyncImpl
5+
import com.lithic.api.core.ClientOptions
6+
import java.time.Duration
7+
8+
class LithicOkHttpClientAsync private constructor() {
9+
10+
companion object {
11+
12+
@JvmStatic fun builder() = Builder()
13+
14+
@JvmStatic fun fromEnv(): LithicClientAsync = builder().fromEnv().build()
15+
}
16+
17+
class Builder {
18+
19+
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
20+
private var baseUrl: String = ClientOptions.PRODUCTION_URL
21+
private var timeout: Duration = Duration.ofSeconds(60)
22+
private var maxRetries: Int = 2
23+
24+
fun sandbox() = apply { baseUrl(ClientOptions.SANDBOX_URL) }
25+
26+
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
27+
28+
fun timeout(timeout: Duration) = apply { this.timeout = timeout }
29+
30+
fun maxRetries(maxRetries: Int) = apply { this.clientOptions.maxRetries(maxRetries) }
31+
32+
fun apiKey(apiKey: String): Builder = apply { clientOptions.apiKey(apiKey) }
33+
34+
fun fromEnv(): Builder = apply { clientOptions.fromEnv() }
35+
36+
fun build(): LithicClientAsync {
37+
return LithicClientAsyncImpl(
38+
clientOptions
39+
.httpClient(OkHttpClient.builder().baseUrl(baseUrl).timeout(timeout).build())
40+
.build()
41+
)
42+
}
43+
}
44+
}

lithic-java-client-okhttp/src/test/kotlin/com/lithic/api/client/okhttp/LithicClientAsyncTest.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

lithic-java-core/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies {
1111
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.1")
1212
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.1")
1313
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.1")
14-
implementation("com.squareup.okhttp3:okhttp:4.10.0")
1514

1615
testImplementation(kotlin("test"))
1716
testImplementation(project(":lithic-java-client-okhttp"))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102
2+
3+
package com.lithic.api.client
4+
5+
import com.lithic.api.core.RequestOptions
6+
import com.lithic.api.models.*
7+
import com.lithic.api.services.blocking.*
8+
9+
interface LithicClient {
10+
11+
fun accounts(): AccountService
12+
13+
fun accountHolders(): AccountHolderService
14+
15+
fun authRules(): AuthRuleService
16+
17+
fun authStreamEnrollment(): AuthStreamEnrollmentService
18+
19+
fun cards(): CardService
20+
21+
fun fundingSources(): FundingSourceService
22+
23+
fun transactions(): TransactionService
24+
25+
/** API status check */
26+
@JvmOverloads
27+
fun apiStatus(
28+
params: ClientApiStatusParams,
29+
requestOptions: RequestOptions = RequestOptions.none()
30+
): ApiStatus
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102
2+
3+
package com.lithic.api.client
4+
5+
import com.lithic.api.core.RequestOptions
6+
import com.lithic.api.models.*
7+
import com.lithic.api.services.async.*
8+
import java.util.concurrent.CompletableFuture
9+
10+
interface LithicClientAsync {
11+
12+
fun accounts(): AccountServiceAsync
13+
14+
fun accountHolders(): AccountHolderServiceAsync
15+
16+
fun authRules(): AuthRuleServiceAsync
17+
18+
fun authStreamEnrollment(): AuthStreamEnrollmentServiceAsync
19+
20+
fun cards(): CardServiceAsync
21+
22+
fun fundingSources(): FundingSourceServiceAsync
23+
24+
fun transactions(): TransactionServiceAsync
25+
26+
/** API status check */
27+
@JvmOverloads
28+
fun apiStatus(
29+
params: ClientApiStatusParams,
30+
requestOptions: RequestOptions = RequestOptions.none()
31+
): CompletableFuture<ApiStatus>
32+
}

0 commit comments

Comments
 (0)