Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ package com.increase.api.core

@JvmSynthetic
internal fun <T : Any> checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required but was not set" }
checkNotNull(value) { "`$name` is required, but was not set" }

@JvmSynthetic
internal fun checkLength(name: String, value: String, length: Int): String =
value.also {
check(it.length == length) { "`$name` must have length $length, but was ${it.length}" }
}

@JvmSynthetic
internal fun checkMinLength(name: String, value: String, minLength: Int): String =
value.also {
check(it.length >= minLength) {
if (minLength == 1) "`$name` must be non-empty, but was empty"
else "`$name` must have at least length $minLength, but was ${it.length}"
}
}

@JvmSynthetic
internal fun checkMaxLength(name: String, value: String, maxLength: Int): String =
value.also {
check(it.length <= maxLength) {
"`$name` must have at most length $maxLength, but was ${it.length}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private constructor(
}

fun build(): ClientOptions {
checkRequired("httpClient", httpClient)
checkRequired("apiKey", apiKey)
val httpClient = checkRequired("httpClient", httpClient)
val apiKey = checkRequired("apiKey", apiKey)

val headers = Headers.builder()
val queryParams = QueryParams.builder()
Expand All @@ -185,7 +185,7 @@ private constructor(
headers.put("X-Stainless-Package-Version", getPackageVersion())
headers.put("X-Stainless-Runtime", "JRE")
headers.put("X-Stainless-Runtime-Version", getJavaVersion())
apiKey?.let {
apiKey.let {
if (!it.isEmpty()) {
headers.put("Authorization", "Bearer $it")
}
Expand All @@ -194,10 +194,10 @@ private constructor(
queryParams.replaceAll(this.queryParams.build())

return ClientOptions(
httpClient!!,
httpClient,
PhantomReachableClosingHttpClient(
RetryingHttpClient.builder()
.httpClient(httpClient!!)
.httpClient(httpClient)
.clock(clock)
.maxRetries(maxRetries)
.idempotencyHeader("Idempotency-Key")
Expand All @@ -210,7 +210,7 @@ private constructor(
queryParams.build(),
responseValidation,
maxRetries,
apiKey!!,
apiKey,
webhookSecret,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ sealed class JsonField<out T : Any> {
is JsonValue -> this
}

@JvmSynthetic fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume)

fun <R> accept(visitor: Visitor<T, R>): R =
when (this) {
is KnownValue -> visitor.visitKnown(value)
Expand Down