Skip to content

Commit 7e48fcf

Browse files
docs: more code comments
1 parent 8b2df3c commit 7e48fcf

File tree

50 files changed

+363
-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.

50 files changed

+363
-4
lines changed

README.md

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

381381
### Retries
382382

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

385385
Only the following error types are retried:
386386

@@ -390,7 +390,7 @@ Only the following error types are retried:
390390
- 429 Rate Limit
391391
- 5xx Internal
392392

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

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

finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClient.kt

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import com.tryfinch.api.client.FinchClient
77
import com.tryfinch.api.client.FinchClientImpl
88
import com.tryfinch.api.core.ClientOptions
99
import com.tryfinch.api.core.Timeout
10+
import com.tryfinch.api.core.http.AsyncStreamResponse
1011
import com.tryfinch.api.core.http.Headers
12+
import com.tryfinch.api.core.http.HttpClient
1113
import com.tryfinch.api.core.http.QueryParams
1214
import com.tryfinch.api.core.jsonMapper
1315
import java.net.Proxy
@@ -20,13 +22,22 @@ import javax.net.ssl.SSLSocketFactory
2022
import javax.net.ssl.X509TrustManager
2123
import kotlin.jvm.optionals.getOrNull
2224

25+
/**
26+
* A class that allows building an instance of [FinchClient] with [OkHttpClient] as the underlying
27+
* [HttpClient].
28+
*/
2329
class FinchOkHttpClient private constructor() {
2430

2531
companion object {
2632

27-
/** Returns a mutable builder for constructing an instance of [FinchOkHttpClient]. */
33+
/** Returns a mutable builder for constructing an instance of [FinchClient]. */
2834
@JvmStatic fun builder() = Builder()
2935

36+
/**
37+
* Returns a client configured using system properties and environment variables.
38+
*
39+
* @see ClientOptions.Builder.fromEnv
40+
*/
3041
@JvmStatic fun fromEnv(): FinchClient = builder().fromEnv().build()
3142
}
3243

@@ -103,23 +114,58 @@ class FinchOkHttpClient private constructor() {
103114
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
104115
}
105116

117+
/**
118+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
119+
*
120+
* Defaults to [com.tryfinch.api.core.jsonMapper]. The default is usually sufficient and
121+
* rarely needs to be overridden.
122+
*/
106123
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
107124

125+
/**
126+
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127+
*
128+
* Defaults to a dedicated cached thread pool.
129+
*/
108130
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
109131
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
110132
}
111133

134+
/**
135+
* The clock to use for operations that require timing, like retries.
136+
*
137+
* This is primarily useful for using a fake clock in tests.
138+
*
139+
* Defaults to [Clock.systemUTC].
140+
*/
112141
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
113142

143+
/**
144+
* The base URL to use for every request.
145+
*
146+
* Defaults to the production environment: `https://api.tryfinch.com`.
147+
*/
114148
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
115149

116150
/** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
117151
fun baseUrl(baseUrl: Optional<String>) = baseUrl(baseUrl.getOrNull())
118152

153+
/**
154+
* Whether to call `validate` on every response before returning it.
155+
*
156+
* Defaults to false, which means the shape of the response will not be validated upfront.
157+
* Instead, validation will only occur for the parts of the response that are accessed.
158+
*/
119159
fun responseValidation(responseValidation: Boolean) = apply {
120160
clientOptions.responseValidation(responseValidation)
121161
}
122162

163+
/**
164+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
165+
* retries.
166+
*
167+
* Defaults to [Timeout.default].
168+
*/
123169
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
124170

125171
/**
@@ -131,6 +177,21 @@ class FinchOkHttpClient private constructor() {
131177
*/
132178
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
133179

180+
/**
181+
* The maximum number of times to retry failed requests, with a short exponential backoff
182+
* between requests.
183+
*
184+
* Only the following error types are retried:
185+
* - Connection errors (for example, due to a network connectivity problem)
186+
* - 408 Request Timeout
187+
* - 409 Conflict
188+
* - 429 Rate Limit
189+
* - 5xx Internal
190+
*
191+
* The API may also explicitly instruct the SDK to retry or not retry a request.
192+
*
193+
* Defaults to 2.
194+
*/
134195
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
135196

136197
fun accessToken(accessToken: String?) = apply { clientOptions.accessToken(accessToken) }
@@ -236,6 +297,11 @@ class FinchOkHttpClient private constructor() {
236297
clientOptions.removeAllQueryParams(keys)
237298
}
238299

300+
/**
301+
* Updates configuration using system properties and environment variables.
302+
*
303+
* @see ClientOptions.Builder.fromEnv
304+
*/
239305
fun fromEnv() = apply { clientOptions.fromEnv() }
240306

241307
/**

finch-java-client-okhttp/src/main/kotlin/com/tryfinch/api/client/okhttp/FinchOkHttpClientAsync.kt

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import com.tryfinch.api.client.FinchClientAsync
77
import com.tryfinch.api.client.FinchClientAsyncImpl
88
import com.tryfinch.api.core.ClientOptions
99
import com.tryfinch.api.core.Timeout
10+
import com.tryfinch.api.core.http.AsyncStreamResponse
1011
import com.tryfinch.api.core.http.Headers
12+
import com.tryfinch.api.core.http.HttpClient
1113
import com.tryfinch.api.core.http.QueryParams
1214
import com.tryfinch.api.core.jsonMapper
1315
import java.net.Proxy
@@ -20,13 +22,22 @@ import javax.net.ssl.SSLSocketFactory
2022
import javax.net.ssl.X509TrustManager
2123
import kotlin.jvm.optionals.getOrNull
2224

25+
/**
26+
* A class that allows building an instance of [FinchClientAsync] with [OkHttpClient] as the
27+
* underlying [HttpClient].
28+
*/
2329
class FinchOkHttpClientAsync private constructor() {
2430

2531
companion object {
2632

27-
/** Returns a mutable builder for constructing an instance of [FinchOkHttpClientAsync]. */
33+
/** Returns a mutable builder for constructing an instance of [FinchClientAsync]. */
2834
@JvmStatic fun builder() = Builder()
2935

36+
/**
37+
* Returns a client configured using system properties and environment variables.
38+
*
39+
* @see ClientOptions.Builder.fromEnv
40+
*/
3041
@JvmStatic fun fromEnv(): FinchClientAsync = builder().fromEnv().build()
3142
}
3243

@@ -103,23 +114,58 @@ class FinchOkHttpClientAsync private constructor() {
103114
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
104115
}
105116

117+
/**
118+
* The Jackson JSON mapper to use for serializing and deserializing JSON.
119+
*
120+
* Defaults to [com.tryfinch.api.core.jsonMapper]. The default is usually sufficient and
121+
* rarely needs to be overridden.
122+
*/
106123
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
107124

125+
/**
126+
* The executor to use for running [AsyncStreamResponse.Handler] callbacks.
127+
*
128+
* Defaults to a dedicated cached thread pool.
129+
*/
108130
fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
109131
clientOptions.streamHandlerExecutor(streamHandlerExecutor)
110132
}
111133

134+
/**
135+
* The clock to use for operations that require timing, like retries.
136+
*
137+
* This is primarily useful for using a fake clock in tests.
138+
*
139+
* Defaults to [Clock.systemUTC].
140+
*/
112141
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
113142

143+
/**
144+
* The base URL to use for every request.
145+
*
146+
* Defaults to the production environment: `https://api.tryfinch.com`.
147+
*/
114148
fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
115149

116150
/** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
117151
fun baseUrl(baseUrl: Optional<String>) = baseUrl(baseUrl.getOrNull())
118152

153+
/**
154+
* Whether to call `validate` on every response before returning it.
155+
*
156+
* Defaults to false, which means the shape of the response will not be validated upfront.
157+
* Instead, validation will only occur for the parts of the response that are accessed.
158+
*/
119159
fun responseValidation(responseValidation: Boolean) = apply {
120160
clientOptions.responseValidation(responseValidation)
121161
}
122162

163+
/**
164+
* Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
165+
* retries.
166+
*
167+
* Defaults to [Timeout.default].
168+
*/
123169
fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
124170

125171
/**
@@ -131,6 +177,21 @@ class FinchOkHttpClientAsync private constructor() {
131177
*/
132178
fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
133179

180+
/**
181+
* The maximum number of times to retry failed requests, with a short exponential backoff
182+
* between requests.
183+
*
184+
* Only the following error types are retried:
185+
* - Connection errors (for example, due to a network connectivity problem)
186+
* - 408 Request Timeout
187+
* - 409 Conflict
188+
* - 429 Rate Limit
189+
* - 5xx Internal
190+
*
191+
* The API may also explicitly instruct the SDK to retry or not retry a request.
192+
*
193+
* Defaults to 2.
194+
*/
134195
fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
135196

136197
fun accessToken(accessToken: String?) = apply { clientOptions.accessToken(accessToken) }
@@ -236,6 +297,11 @@ class FinchOkHttpClientAsync private constructor() {
236297
clientOptions.removeAllQueryParams(keys)
237298
}
238299

300+
/**
301+
* Updates configuration using system properties and environment variables.
302+
*
303+
* @see ClientOptions.Builder.fromEnv
304+
*/
239305
fun fromEnv() = apply { clientOptions.fromEnv() }
240306

241307
/**

0 commit comments

Comments
 (0)