Skip to content

Commit

Permalink
feat(client): add support for putQueryParam on ClientOptions (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jun 17, 2024
1 parent 6068915 commit 2ed6c39
Show file tree
Hide file tree
Showing 63 changed files with 253 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("status")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("status")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private constructor(
@get:JvmName("apiKey") val apiKey: String,
@get:JvmName("webhookSecret") val webhookSecret: String?,
@get:JvmName("headers") val headers: ListMultimap<String, String>,
@get:JvmName("queryParams") val queryParams: ListMultimap<String, String>,
@get:JvmName("responseValidation") val responseValidation: Boolean,
) {

Expand All @@ -39,6 +40,7 @@ private constructor(
private var clock: Clock = Clock.systemUTC()
private var baseUrl: String = PRODUCTION_URL
private var headers: MutableMap<String, MutableList<String>> = mutableMapOf()
private var queryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
private var responseValidation: Boolean = false
private var maxRetries: Int = 2
private var apiKey: String? = null
Expand Down Expand Up @@ -71,6 +73,25 @@ private constructor(

fun removeHeader(name: String) = apply { this.headers.put(name, mutableListOf()) }

fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
this.queryParams.clear()
putAllQueryParams(queryParams)
}

fun putQueryParam(name: String, value: String) = apply {
this.queryParams.getOrPut(name) { mutableListOf() }.add(value)
}

fun putQueryParams(name: String, values: Iterable<String>) = apply {
this.queryParams.getOrPut(name) { mutableListOf() }.addAll(values)
}

fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
queryParams.forEach(this::putQueryParams)
}

fun removeQueryParam(name: String) = apply { this.queryParams.put(name, mutableListOf()) }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}
Expand All @@ -91,15 +112,19 @@ private constructor(
checkNotNull(apiKey) { "`apiKey` is required but was not set" }

val headers = ArrayListMultimap.create<String, String>()
val queryParams = ArrayListMultimap.create<String, String>()
headers.put("X-Stainless-Lang", "java")
headers.put("X-Stainless-Arch", getOsArch())
headers.put("X-Stainless-OS", getOsName())
headers.put("X-Stainless-OS-Version", getOsVersion())
headers.put("X-Stainless-Package-Version", getPackageVersion())
headers.put("X-Stainless-Runtime-Version", getJavaVersion())
headers.put("X-Lithic-Pagination", "cursor")
headers.put("Authorization", apiKey)
if (!apiKey.isNullOrEmpty()) {
headers.put("Authorization", apiKey)
}
this.headers.forEach(headers::replaceValues)
this.queryParams.forEach(queryParams::replaceValues)

return ClientOptions(
RetryingHttpClient.builder()
Expand All @@ -113,6 +138,7 @@ private constructor(
apiKey!!,
webhookSecret,
headers.toUnmodifiable(),
queryParams.toUnmodifiable(),
responseValidation,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("account_holders")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -90,6 +91,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("account_holders", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -119,6 +121,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.PATCH)
.addPathSegments("account_holders", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -151,6 +154,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("account_holders")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -195,6 +199,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("account_holders", params.getPathParam(0), "documents")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -231,6 +236,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("account_holders", params.getPathParam(0), "resubmit")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -279,6 +285,7 @@ constructor(
"documents",
params.getPathParam(1)
)
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -324,6 +331,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("account_holders", params.getPathParam(0), "documents")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -73,6 +74,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.PATCH)
.addPathSegments("accounts", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -103,6 +105,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -137,6 +140,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts", params.getPathParam(0), "spend_limits")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("aggregate_balances")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("auth_rules")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -79,6 +80,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("auth_rules", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -107,6 +109,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.PUT)
.addPathSegments("auth_rules", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -137,6 +140,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("auth_rules")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -166,6 +170,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("auth_rules", params.getPathParam(0), "apply")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -197,6 +202,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.DELETE)
.addPathSegments("auth_rules", "remove")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("auth_stream", "secret")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -75,6 +76,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("auth_stream", "secret", "rotate")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("balances")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("book_transfers")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -69,6 +70,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("book_transfers", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -98,6 +100,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("book_transfers")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("card_programs", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -65,6 +66,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("card_programs")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("cards")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -109,6 +110,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("cards", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -142,6 +144,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.PATCH)
.addPathSegments("cards", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -172,6 +175,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("cards")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -224,6 +228,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("embed", "card")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -253,6 +258,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("cards", params.getPathParam(0), "provision")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -286,6 +292,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("cards", params.getPathParam(0), "reissue")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -319,6 +326,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("cards", params.getPathParam(0), "renew")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -353,6 +361,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("cards", params.getPathParam(0), "spend_limits")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -386,6 +395,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("cards", "search_by_pan")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("digital_card_art", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down Expand Up @@ -65,6 +66,7 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("digital_card_art")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
Expand Down
Loading

0 comments on commit 2ed6c39

Please sign in to comment.