Skip to content

Commit 3127fb2

Browse files
feat(api): api update (#316)
1 parent 6571db4 commit 3127fb2

24 files changed

Lines changed: 35 additions & 87 deletions

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FinchOkHttpClient private constructor() {
2323

2424
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
2525
private var baseUrl: String = ClientOptions.PRODUCTION_URL
26-
// default timeout for client is 1 minute
26+
// The default timeout for the client is 1 minute.
2727
private var timeout: Duration = Duration.ofSeconds(60)
2828
private var proxy: Proxy? = null
2929

@@ -74,8 +74,8 @@ class FinchOkHttpClient private constructor() {
7474

7575
fun fromEnv() = apply { clientOptions.fromEnv() }
7676

77-
fun build(): FinchClient {
78-
return FinchClientImpl(
77+
fun build(): FinchClient =
78+
FinchClientImpl(
7979
clientOptions
8080
.httpClient(
8181
OkHttpClient.builder()
@@ -86,6 +86,5 @@ class FinchOkHttpClient private constructor() {
8686
)
8787
.build()
8888
)
89-
}
9089
}
9190
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FinchOkHttpClientAsync private constructor() {
2323

2424
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
2525
private var baseUrl: String = ClientOptions.PRODUCTION_URL
26-
// default timeout for client is 1 minute
26+
// The default timeout for the client is 1 minute.
2727
private var timeout: Duration = Duration.ofSeconds(60)
2828
private var proxy: Proxy? = null
2929

@@ -74,8 +74,8 @@ class FinchOkHttpClientAsync private constructor() {
7474

7575
fun fromEnv() = apply { clientOptions.fromEnv() }
7676

77-
fun build(): FinchClientAsync {
78-
return FinchClientAsyncImpl(
77+
fun build(): FinchClientAsync =
78+
FinchClientAsyncImpl(
7979
clientOptions
8080
.httpClient(
8181
OkHttpClient.builder()
@@ -86,6 +86,5 @@ class FinchOkHttpClientAsync private constructor() {
8686
)
8787
.build()
8888
)
89-
}
9089
}
9190
}

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

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
6666
request.body?.run { future.whenComplete { _, _ -> close() } }
6767

6868
val call = getClient(requestOptions).newCall(request.toRequest())
69-
7069
call.enqueue(
7170
object : Callback {
7271
override fun onResponse(call: Call, response: Response) {
@@ -90,7 +89,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
9089

9190
private fun HttpRequest.toRequest(): Request {
9291
var body: RequestBody? = body?.toRequestBody()
93-
// OkHttpClient always requires a request body for PUT and POST methods
92+
// OkHttpClient always requires a request body for PUT and POST methods.
9493
if (body == null && (method == HttpMethod.PUT || method == HttpMethod.POST)) {
9594
body = "".toRequestBody()
9695
}
@@ -118,43 +117,27 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
118117
val length = contentLength()
119118

120119
return object : RequestBody() {
121-
override fun contentType(): MediaType? {
122-
return mediaType
123-
}
120+
override fun contentType(): MediaType? = mediaType
124121

125-
override fun contentLength(): Long {
126-
return length
127-
}
122+
override fun contentLength(): Long = length
128123

129-
override fun isOneShot(): Boolean {
130-
return !repeatable()
131-
}
124+
override fun isOneShot(): Boolean = !repeatable()
132125

133-
override fun writeTo(sink: BufferedSink) {
134-
writeTo(sink.outputStream())
135-
}
126+
override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream())
136127
}
137128
}
138129

139130
private fun Response.toResponse(): HttpResponse {
140131
val headers = headers.toHeaders()
141132

142133
return object : HttpResponse {
143-
override fun statusCode(): Int {
144-
return code
145-
}
134+
override fun statusCode(): Int = code
146135

147-
override fun headers(): ListMultimap<String, String> {
148-
return headers
149-
}
136+
override fun headers(): ListMultimap<String, String> = headers
150137

151-
override fun body(): InputStream {
152-
return body!!.byteStream()
153-
}
138+
override fun body(): InputStream = body!!.byteStream()
154139

155-
override fun close() {
156-
body!!.close()
157-
}
140+
override fun close() = body!!.close()
158141
}
159142
}
160143

@@ -163,9 +146,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
163146
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
164147
.arrayListValues()
165148
.build<String, String>()
166-
167149
forEach { pair -> headers.put(pair.first, pair.second) }
168-
169150
return headers
170151
}
171152

@@ -176,7 +157,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
176157
class Builder {
177158

178159
private var baseUrl: HttpUrl? = null
179-
// default timeout is 1 minute
160+
// The default timeout is 1 minute.
180161
private var timeout: Duration = Duration.ofSeconds(60)
181162
private var proxy: Proxy? = null
182163

@@ -186,8 +167,8 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
186167

187168
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
188169

189-
fun build(): OkHttpClient {
190-
return OkHttpClient(
170+
fun build(): OkHttpClient =
171+
OkHttpClient(
191172
okhttp3.OkHttpClient.Builder()
192173
.connectTimeout(timeout)
193174
.readTimeout(timeout)
@@ -197,6 +178,5 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
197178
.build(),
198179
checkNotNull(baseUrl) { "`baseUrl` is required but was not set" },
199180
)
200-
}
201181
}
202182
}

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClient.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// File generated from our OpenAPI spec by Stainless.
22

3-
@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102
4-
53
package com.tryfinch.api.client
64

75
import com.fasterxml.jackson.annotation.JsonProperty

finch-java-core/src/main/kotlin/com/tryfinch/api/client/FinchClientAsync.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// File generated from our OpenAPI spec by Stainless.
22

3-
@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102
4-
53
package com.tryfinch.api.client
64

75
import com.fasterxml.jackson.annotation.JsonProperty

finch-java-core/src/main/kotlin/com/tryfinch/api/core/Values.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ sealed class JsonField<out T : Any> {
142142
// This filter should not be used directly and should instead use the @ExcludeMissing annotation
143143
class IsMissing {
144144
override fun equals(other: Any?): Boolean = other is JsonMissing
145+
146+
override fun hashCode(): Int = Objects.hash()
145147
}
146148

147149
class Deserializer(private val type: JavaType? = null) :
@@ -479,9 +481,8 @@ internal constructor(
479481
}
480482
}
481483

482-
override fun toString(): String {
483-
return "MultipartFormValue(name='$name', contentType=$contentType, filename=$filename, value=${valueToString()})"
484-
}
484+
override fun toString(): String =
485+
"MultipartFormValue{name=$name, contentType=$contentType, filename=$filename, value=${valueToString()}}"
485486

486487
private fun valueToString(): String =
487488
when (value) {

finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/HttpClient.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("OVERLOADS_INTERFACE") // See https://youtrack.jetbrains.com/issue/KT-36102
2+
13
package com.tryfinch.api.core.http
24

35
import com.tryfinch.api.core.RequestOptions
@@ -6,11 +8,13 @@ import java.util.concurrent.CompletableFuture
68

79
interface HttpClient : AutoCloseable {
810

11+
@JvmOverloads
912
fun execute(
1013
request: HttpRequest,
1114
requestOptions: RequestOptions = RequestOptions.none(),
1215
): HttpResponse
1316

17+
@JvmOverloads
1418
fun executeAsync(
1519
request: HttpRequest,
1620
requestOptions: RequestOptions = RequestOptions.none(),

finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/HttpRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private constructor(
1717
) {
1818

1919
override fun toString(): String =
20-
"HttpRequest {method=$method, pathSegments=$pathSegments, queryParams=$queryParams, headers=$headers, body=$body}"
20+
"HttpRequest{method=$method, pathSegments=$pathSegments, queryParams=$queryParams, headers=$headers, body=$body}"
2121

2222
companion object {
2323
@JvmStatic fun builder() = Builder()

finch-java-core/src/main/kotlin/com/tryfinch/api/core/http/RetryingHttpClient.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:JvmSynthetic
2-
31
package com.tryfinch.api.core.http
42

53
import com.google.common.util.concurrent.MoreExecutors
@@ -126,15 +124,12 @@ private constructor(
126124
return executeWithRetries(request, requestOptions)
127125
}
128126

129-
override fun close() {
130-
httpClient.close()
131-
}
127+
override fun close() = httpClient.close()
132128

133-
private fun isRetryable(request: HttpRequest): Boolean {
129+
private fun isRetryable(request: HttpRequest): Boolean =
134130
// Some requests, such as when a request body is being streamed, cannot be retried because
135131
// the body data aren't available on subsequent attempts.
136-
return request.body?.repeatable() ?: true
137-
}
132+
request.body?.repeatable() ?: true
138133

139134
private fun setRetryCountHeader(request: HttpRequest, retries: Int) {
140135
request.headers.removeAll("x-stainless-retry-count")
@@ -172,11 +167,10 @@ private constructor(
172167
}
173168
}
174169

175-
private fun shouldRetry(throwable: Throwable): Boolean {
170+
private fun shouldRetry(throwable: Throwable): Boolean =
176171
// Only retry IOException and FinchIoException, other exceptions are not intended to be
177172
// retried.
178-
return throwable is IOException || throwable is FinchIoException
179-
}
173+
throwable is IOException || throwable is FinchIoException
180174

181175
private fun getRetryBackoffMillis(retries: Int, response: HttpResponse?): Duration {
182176
// About the Retry-After header:

finch-java-core/src/main/kotlin/com/tryfinch/api/models/PayrollPayGroupListParams.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ constructor(
2424
internal fun getQueryParams(): Map<String, List<String>> {
2525
val params = mutableMapOf<String, List<String>>()
2626
this.individualId?.let { params.put("individual_id", listOf(it.toString())) }
27-
this.payFrequencies?.let {
28-
params.put("pay_frequencies", listOf(it.joinToString(separator = ",")))
29-
}
27+
this.payFrequencies?.let { params.put("pay_frequencies[]", it.map(Any::toString)) }
3028
params.putAll(additionalQueryParams)
3129
return params.toUnmodifiable()
3230
}

0 commit comments

Comments
 (0)