Skip to content

Commit

Permalink
feat(client): add methods for header params (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 20, 2024
1 parent a6e3a9c commit cb88b74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ constructor(
private val type: Type,
private val accountToken: String?,
private val isForBenefitOf: Boolean?,
private val idempotencyKey: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map<String, JsonValue>,
Expand All @@ -38,6 +39,8 @@ constructor(

fun isForBenefitOf(): Boolean? = isForBenefitOf

fun idempotencyKey(): String? = idempotencyKey

internal fun getBody(): FinancialAccountCreateBody {
return FinancialAccountCreateBody(
nickname,
Expand All @@ -48,7 +51,12 @@ constructor(
)
}

internal fun getHeaders(): Headers = additionalHeaders
internal fun getHeaders(): Headers {
val headers = Headers.builder()
this.idempotencyKey?.let { headers.put("Idempotency-Key", listOf(it.toString())) }
headers.putAll(additionalHeaders)
return headers.build()
}

internal fun getQueryParams(): QueryParams = additionalQueryParams

Expand Down Expand Up @@ -167,15 +175,15 @@ constructor(
return true
}

return /* spotless:off */ other is FinancialAccountCreateParams && this.nickname == other.nickname && this.type == other.type && this.accountToken == other.accountToken && this.isForBenefitOf == other.isForBenefitOf && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
return /* spotless:off */ other is FinancialAccountCreateParams && this.nickname == other.nickname && this.type == other.type && this.accountToken == other.accountToken && this.isForBenefitOf == other.isForBenefitOf && this.idempotencyKey == other.idempotencyKey && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams && this.additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
}

override fun hashCode(): Int {
return /* spotless:off */ Objects.hash(nickname, type, accountToken, isForBenefitOf, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
return /* spotless:off */ Objects.hash(nickname, type, accountToken, isForBenefitOf, idempotencyKey, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
}

override fun toString() =
"FinancialAccountCreateParams{nickname=$nickname, type=$type, accountToken=$accountToken, isForBenefitOf=$isForBenefitOf, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
"FinancialAccountCreateParams{nickname=$nickname, type=$type, accountToken=$accountToken, isForBenefitOf=$isForBenefitOf, idempotencyKey=$idempotencyKey, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"

fun toBuilder() = Builder().from(this)

Expand All @@ -191,6 +199,7 @@ constructor(
private var type: Type? = null
private var accountToken: String? = null
private var isForBenefitOf: Boolean? = null
private var idempotencyKey: String? = null
private var additionalHeaders: Headers.Builder = Headers.builder()
private var additionalQueryParams: QueryParams.Builder = QueryParams.builder()
private var additionalBodyProperties: MutableMap<String, JsonValue> = mutableMapOf()
Expand All @@ -200,6 +209,7 @@ constructor(
this.type = financialAccountCreateParams.type
this.accountToken = financialAccountCreateParams.accountToken
this.isForBenefitOf = financialAccountCreateParams.isForBenefitOf
this.idempotencyKey = financialAccountCreateParams.idempotencyKey
additionalHeaders(financialAccountCreateParams.additionalHeaders)
additionalQueryParams(financialAccountCreateParams.additionalQueryParams)
additionalBodyProperties(financialAccountCreateParams.additionalBodyProperties)
Expand All @@ -213,6 +223,8 @@ constructor(

fun isForBenefitOf(isForBenefitOf: Boolean) = apply { this.isForBenefitOf = isForBenefitOf }

fun idempotencyKey(idempotencyKey: String) = apply { this.idempotencyKey = idempotencyKey }

fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
putAllAdditionalHeaders(additionalHeaders)
Expand Down Expand Up @@ -339,6 +351,7 @@ constructor(
checkNotNull(type) { "`type` is required but was not set" },
accountToken,
isForBenefitOf,
idempotencyKey,
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FinancialAccountCreateParamsTest {
.type(FinancialAccountCreateParams.Type.OPERATING)
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.isForBenefitOf(true)
.idempotencyKey("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.build()
}

Expand All @@ -26,6 +27,7 @@ class FinancialAccountCreateParamsTest {
.type(FinancialAccountCreateParams.Type.OPERATING)
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.isForBenefitOf(true)
.idempotencyKey("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.build()
val body = params.getBody()
assertThat(body).isNotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FinancialAccountServiceTest {
.type(FinancialAccountCreateParams.Type.OPERATING)
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.isForBenefitOf(true)
.idempotencyKey("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
.build()
)
println(financialAccount)
Expand Down

0 comments on commit cb88b74

Please sign in to comment.