@@ -9,6 +9,7 @@ import com.tryfinch.api.core.ClientOptions
99import com.tryfinch.api.core.Timeout
1010import com.tryfinch.api.core.http.Headers
1111import com.tryfinch.api.core.http.QueryParams
12+ import com.tryfinch.api.core.jsonMapper
1213import java.net.Proxy
1314import java.time.Clock
1415import java.time.Duration
@@ -30,10 +31,9 @@ class FinchOkHttpClientAsync private constructor() {
3031 class Builder internal constructor() {
3132
3233 private var clientOptions: ClientOptions .Builder = ClientOptions .builder()
33- private var timeout: Timeout = Timeout .default()
3434 private var proxy: Proxy ? = null
3535
36- fun baseUrl ( baseUrl : String ) = apply { clientOptions.baseUrl(baseUrl) }
36+ fun proxy ( proxy : Proxy ) = apply { this .proxy = proxy }
3737
3838 /* *
3939 * Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -54,6 +54,51 @@ class FinchOkHttpClientAsync private constructor() {
5454
5555 fun clock (clock : Clock ) = apply { clientOptions.clock(clock) }
5656
57+ fun baseUrl (baseUrl : String? ) = apply { clientOptions.baseUrl(baseUrl) }
58+
59+ /* * Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
60+ fun baseUrl (baseUrl : Optional <String >) = baseUrl(baseUrl.getOrNull())
61+
62+ fun responseValidation (responseValidation : Boolean ) = apply {
63+ clientOptions.responseValidation(responseValidation)
64+ }
65+
66+ fun timeout (timeout : Timeout ) = apply { clientOptions.timeout(timeout) }
67+
68+ /* *
69+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
70+ *
71+ * See [Timeout.request] for more details.
72+ *
73+ * For fine-grained control, pass a [Timeout] object.
74+ */
75+ fun timeout (timeout : Duration ) = apply { clientOptions.timeout(timeout) }
76+
77+ fun maxRetries (maxRetries : Int ) = apply { clientOptions.maxRetries(maxRetries) }
78+
79+ fun accessToken (accessToken : String? ) = apply { clientOptions.accessToken(accessToken) }
80+
81+ /* * Alias for calling [Builder.accessToken] with `accessToken.orElse(null)`. */
82+ fun accessToken (accessToken : Optional <String >) = accessToken(accessToken.getOrNull())
83+
84+ fun clientId (clientId : String? ) = apply { clientOptions.clientId(clientId) }
85+
86+ /* * Alias for calling [Builder.clientId] with `clientId.orElse(null)`. */
87+ fun clientId (clientId : Optional <String >) = clientId(clientId.getOrNull())
88+
89+ fun clientSecret (clientSecret : String? ) = apply { clientOptions.clientSecret(clientSecret) }
90+
91+ /* * Alias for calling [Builder.clientSecret] with `clientSecret.orElse(null)`. */
92+ fun clientSecret (clientSecret : Optional <String >) = clientSecret(clientSecret.getOrNull())
93+
94+ fun webhookSecret (webhookSecret : String? ) = apply {
95+ clientOptions.webhookSecret(webhookSecret)
96+ }
97+
98+ /* * Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
99+ fun webhookSecret (webhookSecret : Optional <String >) =
100+ webhookSecret(webhookSecret.getOrNull())
101+
57102 fun headers (headers : Headers ) = apply { clientOptions.headers(headers) }
58103
59104 fun headers (headers : Map <String , Iterable <String >>) = apply {
@@ -134,51 +179,6 @@ class FinchOkHttpClientAsync private constructor() {
134179 clientOptions.removeAllQueryParams(keys)
135180 }
136181
137- fun timeout (timeout : Timeout ) = apply {
138- clientOptions.timeout(timeout)
139- this .timeout = timeout
140- }
141-
142- /* *
143- * Sets the maximum time allowed for a complete HTTP call, not including retries.
144- *
145- * See [Timeout.request] for more details.
146- *
147- * For fine-grained control, pass a [Timeout] object.
148- */
149- fun timeout (timeout : Duration ) = timeout(Timeout .builder().request(timeout).build())
150-
151- fun maxRetries (maxRetries : Int ) = apply { clientOptions.maxRetries(maxRetries) }
152-
153- fun proxy (proxy : Proxy ) = apply { this .proxy = proxy }
154-
155- fun responseValidation (responseValidation : Boolean ) = apply {
156- clientOptions.responseValidation(responseValidation)
157- }
158-
159- fun accessToken (accessToken : String? ) = apply { clientOptions.accessToken(accessToken) }
160-
161- /* * Alias for calling [Builder.accessToken] with `accessToken.orElse(null)`. */
162- fun accessToken (accessToken : Optional <String >) = accessToken(accessToken.getOrNull())
163-
164- fun clientId (clientId : String? ) = apply { clientOptions.clientId(clientId) }
165-
166- /* * Alias for calling [Builder.clientId] with `clientId.orElse(null)`. */
167- fun clientId (clientId : Optional <String >) = clientId(clientId.getOrNull())
168-
169- fun clientSecret (clientSecret : String? ) = apply { clientOptions.clientSecret(clientSecret) }
170-
171- /* * Alias for calling [Builder.clientSecret] with `clientSecret.orElse(null)`. */
172- fun clientSecret (clientSecret : Optional <String >) = clientSecret(clientSecret.getOrNull())
173-
174- fun webhookSecret (webhookSecret : String? ) = apply {
175- clientOptions.webhookSecret(webhookSecret)
176- }
177-
178- /* * Alias for calling [Builder.webhookSecret] with `webhookSecret.orElse(null)`. */
179- fun webhookSecret (webhookSecret : Optional <String >) =
180- webhookSecret(webhookSecret.getOrNull())
181-
182182 fun fromEnv () = apply { clientOptions.fromEnv() }
183183
184184 /* *
@@ -189,7 +189,9 @@ class FinchOkHttpClientAsync private constructor() {
189189 fun build (): FinchClientAsync =
190190 FinchClientAsyncImpl (
191191 clientOptions
192- .httpClient(OkHttpClient .builder().timeout(timeout).proxy(proxy).build())
192+ .httpClient(
193+ OkHttpClient .builder().timeout(clientOptions.timeout()).proxy(proxy).build()
194+ )
193195 .build()
194196 )
195197 }
0 commit comments