Skip to content

Commit ba71290

Browse files
docs: more code comments
1 parent b6dcd6c commit ba71290

File tree

120 files changed

+494
-4
lines changed

Some content is hidden

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

120 files changed

+494
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t
327327

328328
### Retries
329329

330-
The SDK automatically retries 2 times by default, with a short exponential backoff.
330+
The SDK automatically retries 2 times by default, with a short exponential backoff between requests.
331331

332332
Only the following error types are retried:
333333

@@ -337,7 +337,7 @@ Only the following error types are retried:
337337
- 429 Rate Limit
338338
- 5xx Internal
339339

340-
The API may also explicitly instruct the SDK to retry or not retry a response.
340+
The API may also explicitly instruct the SDK to retry or not retry a request.
341341

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

orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.withorb.api.client.OrbClientImpl
88
import com.withorb.api.core.ClientOptions
99
import com.withorb.api.core.Timeout
1010
import com.withorb.api.core.http.Headers
11+
import com.withorb.api.core.http.HttpClient
1112
import com.withorb.api.core.http.QueryParams
1213
import com.withorb.api.core.jsonMapper
1314
import java.net.Proxy
@@ -17,13 +18,22 @@ import javax.net.ssl.HostnameVerifier
1718
import javax.net.ssl.SSLSocketFactory
1819
import javax.net.ssl.X509TrustManager
1920

21+
/**
22+
* A class that allows building an instance of [OrbClient] with [OkHttpClient] as the underlying
23+
* [HttpClient].
24+
*/
2025
class OrbOkHttpClient private constructor() {
2126

2227
companion object {
2328

24-
/** Returns a mutable builder for constructing an instance of [OrbOkHttpClient]. */
29+
/** Returns a mutable builder for constructing an instance of [OrbClient]. */
2530
fun builder() = Builder()
2631

32+
/**
33+
* Returns a client configured using system properties and environment variables.
34+
*
35+
* @see ClientOptions.Builder.fromEnv
36+
*/
2737
fun fromEnv(): OrbClient = builder().fromEnv().build()
2838
}
2939

@@ -85,16 +95,46 @@ class OrbOkHttpClient private constructor() {
8595
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
8696
}
8797

98+
/**
99+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
100+
*
101+
* Defaults to [com.withorb.api.core.jsonMapper]. The default is usually sufficient and
102+
* rarely needs to be overridden.
103+
*/
88104
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
89105

106+
/**
107+
* The clock to use for operations that require timing, like retries.
108+
*
109+
* This is primarily useful for using a fake clock in tests.
110+
*
111+
* Defaults to [Clock.systemUTC].
112+
*/
90113
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
91114

115+
/**
116+
* The base URL to use for every request.
117+
*
118+
* Defaults to the production environment: `https://api.withorb.com/v1`.
119+
*/
92120
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
93121

122+
/**
123+
* Whether to call `validate` on every response before returning it.
124+
*
125+
* Defaults to false, which means the shape of the response will not be validated upfront.
126+
* Instead, validation will only occur for the parts of the response that are accessed.
127+
*/
94128
fun responseValidation(responseValidation: Boolean) = apply {
95129
clientOptions.responseValidation(responseValidation)
96130
}
97131

132+
/**
133+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
134+
* retries.
135+
*
136+
* Defaults to [Timeout.default].
137+
*/
98138
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
99139

100140
/**
@@ -106,6 +146,21 @@ class OrbOkHttpClient private constructor() {
106146
*/
107147
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
108148

149+
/**
150+
* The maximum number of times to retry failed requests, with a short exponential backoff
151+
* between requests.
152+
*
153+
* Only the following error types are retried:
154+
* - Connection errors (for example, due to a network connectivity problem)
155+
* - 408 Request Timeout
156+
* - 409 Conflict
157+
* - 429 Rate Limit
158+
* - 5xx Internal
159+
*
160+
* The API may also explicitly instruct the SDK to retry or not retry a request.
161+
*
162+
* Defaults to 2.
163+
*/
109164
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
110165

111166
fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) }
@@ -194,6 +249,11 @@ class OrbOkHttpClient private constructor() {
194249
clientOptions.removeAllQueryParams(keys)
195250
}
196251

252+
/**
253+
* Updates configuration using system properties and environment variables.
254+
*
255+
* @see ClientOptions.Builder.fromEnv
256+
*/
197257
fun fromEnv() = apply { clientOptions.fromEnv() }
198258

199259
/**

orb-kotlin-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.withorb.api.client.OrbClientAsyncImpl
88
import com.withorb.api.core.ClientOptions
99
import com.withorb.api.core.Timeout
1010
import com.withorb.api.core.http.Headers
11+
import com.withorb.api.core.http.HttpClient
1112
import com.withorb.api.core.http.QueryParams
1213
import com.withorb.api.core.jsonMapper
1314
import java.net.Proxy
@@ -17,13 +18,22 @@ import javax.net.ssl.HostnameVerifier
1718
import javax.net.ssl.SSLSocketFactory
1819
import javax.net.ssl.X509TrustManager
1920

21+
/**
22+
* A class that allows building an instance of [OrbClientAsync] with [OkHttpClient] as the
23+
* underlying [HttpClient].
24+
*/
2025
class OrbOkHttpClientAsync private constructor() {
2126

2227
companion object {
2328

24-
/** Returns a mutable builder for constructing an instance of [OrbOkHttpClientAsync]. */
29+
/** Returns a mutable builder for constructing an instance of [OrbClientAsync]. */
2530
fun builder() = Builder()
2631

32+
/**
33+
* Returns a client configured using system properties and environment variables.
34+
*
35+
* @see ClientOptions.Builder.fromEnv
36+
*/
2737
fun fromEnv(): OrbClientAsync = builder().fromEnv().build()
2838
}
2939

@@ -85,16 +95,46 @@ class OrbOkHttpClientAsync private constructor() {
8595
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
8696
}
8797

98+
/**
99+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
100+
*
101+
* Defaults to [com.withorb.api.core.jsonMapper]. The default is usually sufficient and
102+
* rarely needs to be overridden.
103+
*/
88104
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
89105

106+
/**
107+
* The clock to use for operations that require timing, like retries.
108+
*
109+
* This is primarily useful for using a fake clock in tests.
110+
*
111+
* Defaults to [Clock.systemUTC].
112+
*/
90113
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
91114

115+
/**
116+
* The base URL to use for every request.
117+
*
118+
* Defaults to the production environment: `https://api.withorb.com/v1`.
119+
*/
92120
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
93121

122+
/**
123+
* Whether to call `validate` on every response before returning it.
124+
*
125+
* Defaults to false, which means the shape of the response will not be validated upfront.
126+
* Instead, validation will only occur for the parts of the response that are accessed.
127+
*/
94128
fun responseValidation(responseValidation: Boolean) = apply {
95129
clientOptions.responseValidation(responseValidation)
96130
}
97131

132+
/**
133+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
134+
* retries.
135+
*
136+
* Defaults to [Timeout.default].
137+
*/
98138
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
99139

100140
/**
@@ -106,6 +146,21 @@ class OrbOkHttpClientAsync private constructor() {
106146
*/
107147
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
108148

149+
/**
150+
* The maximum number of times to retry failed requests, with a short exponential backoff
151+
* between requests.
152+
*
153+
* Only the following error types are retried:
154+
* - Connection errors (for example, due to a network connectivity problem)
155+
* - 408 Request Timeout
156+
* - 409 Conflict
157+
* - 429 Rate Limit
158+
* - 5xx Internal
159+
*
160+
* The API may also explicitly instruct the SDK to retry or not retry a request.
161+
*
162+
* Defaults to 2.
163+
*/
109164
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
110165

111166
fun apiKey(apiKey: String) = apply { clientOptions.apiKey(apiKey) }
@@ -194,6 +249,11 @@ class OrbOkHttpClientAsync private constructor() {
194249
clientOptions.removeAllQueryParams(keys)
195250
}
196251

252+
/**
253+
* Updates configuration using system properties and environment variables.
254+
*
255+
* @see ClientOptions.Builder.fromEnv
256+
*/
197257
fun fromEnv() = apply { clientOptions.fromEnv() }
198258

199259
/**

0 commit comments

Comments
 (0)