Skip to content

Commit cb1a836

Browse files
feat(api): manual updates
1 parent 6831464 commit cb1a836

File tree

139 files changed

+2418
-3552
lines changed

Some content is hidden

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

139 files changed

+2418
-3552
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
lint:
17-
timeout-minutes: 10
17+
timeout-minutes: 15
1818
name: lint
1919
runs-on: ${{ github.repository == 'stainless-sdks/terminal-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
2020
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
@@ -37,7 +37,7 @@ jobs:
3737
- name: Run lints
3838
run: ./scripts/lint
3939
test:
40-
timeout-minutes: 10
40+
timeout-minutes: 15
4141
name: test
4242
runs-on: ${{ github.repository == 'stainless-sdks/terminal-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
4343
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork

.github/workflows/publish-sonatype.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v4
1818

1919
- name: Set up Java
20-
uses: actions/setup-java@v3
20+
uses: actions/setup-java@v4
2121
with:
2222
distribution: temurin
2323
java-version: |

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 37
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-007e5b747998d674f393434855b8c2a017051933e7bf5506aa5fabbc26dbe8f4.yml
3-
openapi_spec_hash: 23f30ca06d5bf3eb93e26d3fd7d90091
4-
config_hash: 6f5c0872923f09a48196d34610023f40
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/terminal%2Fterminal-84ef614abb971e8673a8639face21c77dc72cc8f1b246e84796afcc7057e6b1b.yml
3+
openapi_spec_hash: d08a15c87914e11038f240f0d25d09e2
4+
config_hash: c6e19e8b772c386e1ba9d971019d5d89

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,23 @@ import shop.terminal.api.client.okhttp.TerminalOkHttpClient;
5353
import shop.terminal.api.models.product.ProductListParams;
5454
import shop.terminal.api.models.product.ProductListResponse;
5555

56-
// Configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
56+
// Configures using the `terminal.bearerToken` and `terminal.baseUrl` system properties
57+
// Or configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
5758
TerminalClient client = TerminalOkHttpClient.fromEnv();
5859

5960
ProductListResponse products = client.product().list();
6061
```
6162

6263
## Client configuration
6364

64-
Configure the client using environment variables:
65+
Configure the client using system properties or environment variables:
6566

6667
```java
6768
import shop.terminal.api.client.TerminalClient;
6869
import shop.terminal.api.client.okhttp.TerminalOkHttpClient;
6970

70-
// Configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
71+
// Configures using the `terminal.bearerToken` and `terminal.baseUrl` system properties
72+
// Or configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
7173
TerminalClient client = TerminalOkHttpClient.fromEnv();
7274
```
7375

@@ -89,18 +91,21 @@ import shop.terminal.api.client.TerminalClient;
8991
import shop.terminal.api.client.okhttp.TerminalOkHttpClient;
9092

9193
TerminalClient client = TerminalOkHttpClient.builder()
92-
// Configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
94+
// Configures using the `terminal.bearerToken` and `terminal.baseUrl` system properties
95+
// Or configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
9396
.fromEnv()
9497
.appId("My App ID")
9598
.build();
9699
```
97100

98101
See this table for the available options:
99102

100-
| Setter | Environment variable | Required | Default value |
101-
| ------------- | ----------------------- | -------- | ----------------------------- |
102-
| `bearerToken` | `TERMINAL_BEARER_TOKEN` | true | - |
103-
| `baseUrl` | `TERMINAL_BASE_URL` | true | `"https://api.terminal.shop"` |
103+
| Setter | System property | Environment variable | Required | Default value |
104+
| ------------- | ---------------------- | ----------------------- | -------- | ----------------------------- |
105+
| `bearerToken` | `terminal.bearerToken` | `TERMINAL_BEARER_TOKEN` | true | - |
106+
| `baseUrl` | `terminal.baseUrl` | `TERMINAL_BASE_URL` | true | `"https://api.terminal.shop"` |
107+
108+
System properties take precedence over environment variables.
104109

105110
> [!TIP]
106111
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -146,7 +151,8 @@ import shop.terminal.api.client.okhttp.TerminalOkHttpClient;
146151
import shop.terminal.api.models.product.ProductListParams;
147152
import shop.terminal.api.models.product.ProductListResponse;
148153

149-
// Configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
154+
// Configures using the `terminal.bearerToken` and `terminal.baseUrl` system properties
155+
// Or configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
150156
TerminalClient client = TerminalOkHttpClient.fromEnv();
151157

152158
CompletableFuture<ProductListResponse> products = client.async().product().list();
@@ -161,7 +167,8 @@ import shop.terminal.api.client.okhttp.TerminalOkHttpClientAsync;
161167
import shop.terminal.api.models.product.ProductListParams;
162168
import shop.terminal.api.models.product.ProductListResponse;
163169

164-
// Configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
170+
// Configures using the `terminal.bearerToken` and `terminal.baseUrl` system properties
171+
// Or configures using the `TERMINAL_BEARER_TOKEN` and `TERMINAL_BASE_URL` environment variables
165172
TerminalClientAsync client = TerminalOkHttpClientAsync.fromEnv();
166173

167174
CompletableFuture<ProductListResponse> products = client.product().list();
@@ -214,6 +221,8 @@ The SDK throws custom unchecked exception types:
214221

215222
- [`TerminalIoException`](terminal-java-core/src/main/kotlin/shop/terminal/api/errors/TerminalIoException.kt): I/O networking errors.
216223

224+
- [`TerminalRetryableException`](terminal-java-core/src/main/kotlin/shop/terminal/api/errors/TerminalRetryableException.kt): Generic error indicating a failure that could be retried by the client.
225+
217226
- [`TerminalInvalidDataException`](terminal-java-core/src/main/kotlin/shop/terminal/api/errors/TerminalInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response.
218227

219228
- [`TerminalException`](terminal-java-core/src/main/kotlin/shop/terminal/api/errors/TerminalException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class.
@@ -234,6 +243,12 @@ Or to `debug` for more verbose logging:
234243
$ export TERMINAL_LOG=debug
235244
```
236245

246+
## ProGuard and R8
247+
248+
Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `terminal-java-core` is published with a [configuration file](terminal-java-core/src/main/resources/META-INF/proguard/terminal-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage).
249+
250+
ProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary.
251+
237252
## Jackson
238253

239254
The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default.
@@ -249,7 +264,7 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t
249264

250265
### Retries
251266

252-
The SDK automatically retries 2 times by default, with a short exponential backoff.
267+
The SDK automatically retries 2 times by default, with a short exponential backoff between requests.
253268

254269
Only the following error types are retried:
255270

@@ -259,7 +274,7 @@ Only the following error types are retried:
259274
- 429 Rate Limit
260275
- 5xx Internal
261276

262-
The API may also explicitly instruct the SDK to retry or not retry a response.
277+
The API may also explicitly instruct the SDK to retry or not retry a request.
263278

264279
To set a custom number of retries, configure the client using the `maxRetries` method:
265280

@@ -318,6 +333,27 @@ TerminalClient client = TerminalOkHttpClient.builder()
318333
.build();
319334
```
320335

336+
### HTTPS
337+
338+
> [!NOTE]
339+
> Most applications should not call these methods, and instead use the system defaults. The defaults include
340+
> special optimizations that can be lost if the implementations are modified.
341+
342+
To configure how HTTPS connections are secured, configure the client using the `sslSocketFactory`, `trustManager`, and `hostnameVerifier` methods:
343+
344+
```java
345+
import shop.terminal.api.client.TerminalClient;
346+
import shop.terminal.api.client.okhttp.TerminalOkHttpClient;
347+
348+
TerminalClient client = TerminalOkHttpClient.builder()
349+
.fromEnv()
350+
// If `sslSocketFactory` is set, then `trustManager` must be set, and vice versa.
351+
.sslSocketFactory(yourSSLSocketFactory)
352+
.trustManager(yourTrustManager)
353+
.hostnameVerifier(yourHostnameVerifier)
354+
.build();
355+
```
356+
321357
### Environments
322358

323359
The SDK sends requests to the production by default. To send requests to a different environment, configure the client like so:

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ rootProject.name = "terminal-java-root"
33
include("terminal-java")
44
include("terminal-java-client-okhttp")
55
include("terminal-java-core")
6+
include("terminal-java-proguard-test")
67
include("terminal-java-example")

terminal-java-client-okhttp/src/main/kotlin/shop/terminal/api/client/okhttp/OkHttpClient.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import java.io.InputStream
55
import java.net.Proxy
66
import java.time.Duration
77
import java.util.concurrent.CompletableFuture
8+
import javax.net.ssl.HostnameVerifier
9+
import javax.net.ssl.SSLSocketFactory
10+
import javax.net.ssl.X509TrustManager
811
import okhttp3.Call
912
import okhttp3.Callback
1013
import okhttp3.HttpUrl.Companion.toHttpUrl
@@ -189,13 +192,28 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC
189192

190193
private var timeout: Timeout = Timeout.default()
191194
private var proxy: Proxy? = null
195+
private var sslSocketFactory: SSLSocketFactory? = null
196+
private var trustManager: X509TrustManager? = null
197+
private var hostnameVerifier: HostnameVerifier? = null
192198

193199
fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
194200

195201
fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
196202

197203
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
198204

205+
fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply {
206+
this.sslSocketFactory = sslSocketFactory
207+
}
208+
209+
fun trustManager(trustManager: X509TrustManager?) = apply {
210+
this.trustManager = trustManager
211+
}
212+
213+
fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply {
214+
this.hostnameVerifier = hostnameVerifier
215+
}
216+
199217
fun build(): OkHttpClient =
200218
OkHttpClient(
201219
okhttp3.OkHttpClient.Builder()
@@ -204,6 +222,19 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC
204222
.writeTimeout(timeout.write())
205223
.callTimeout(timeout.request())
206224
.proxy(proxy)
225+
.apply {
226+
val sslSocketFactory = sslSocketFactory
227+
val trustManager = trustManager
228+
if (sslSocketFactory != null && trustManager != null) {
229+
sslSocketFactory(sslSocketFactory, trustManager)
230+
} else {
231+
check((sslSocketFactory != null) == (trustManager != null)) {
232+
"Both or none of `sslSocketFactory` and `trustManager` must be set, but only one was set"
233+
}
234+
}
235+
236+
hostnameVerifier?.let(::hostnameVerifier)
237+
}
207238
.build()
208239
.apply {
209240
// We usually make all our requests to the same host so it makes sense to

0 commit comments

Comments
 (0)