
com.lithic.api.services.async.AccountServiceAsyncImpl.kt Maven / Gradle / Ivy
// File generated from our OpenAPI spec by Stainless.
package com.lithic.api.services.async
import com.lithic.api.core.ClientOptions
import com.lithic.api.core.RequestOptions
import com.lithic.api.core.http.HttpMethod
import com.lithic.api.core.http.HttpRequest
import com.lithic.api.core.http.HttpResponse.Handler
import com.lithic.api.errors.LithicError
import com.lithic.api.models.Account
import com.lithic.api.models.AccountListPageAsync
import com.lithic.api.models.AccountListParams
import com.lithic.api.models.AccountRetrieveParams
import com.lithic.api.models.AccountUpdateParams
import com.lithic.api.services.async.accounts.CreditConfigurationServiceAsync
import com.lithic.api.services.async.accounts.CreditConfigurationServiceAsyncImpl
import com.lithic.api.services.errorHandler
import com.lithic.api.services.json
import com.lithic.api.services.jsonHandler
import com.lithic.api.services.withErrorHandler
class AccountServiceAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : AccountServiceAsync {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val creditConfigurations: CreditConfigurationServiceAsync by lazy {
CreditConfigurationServiceAsyncImpl(clientOptions)
}
override fun creditConfigurations(): CreditConfigurationServiceAsync = creditConfigurations
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Get account configuration such as spend limits. */
override suspend fun retrieve(
params: AccountRetrieveParams,
requestOptions: RequestOptions
): Account {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts", params.getPathParam(0))
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { retrieveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val updateHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/**
* Update account configuration such as spend limits and verification address. Can only be run
* on accounts that are part of the program managed by this API key.
*
* Accounts that are in the `PAUSED` state will not be able to transact or create new cards.
*/
override suspend fun update(
params: AccountUpdateParams,
requestOptions: RequestOptions
): Account {
val request =
HttpRequest.builder()
.method(HttpMethod.PATCH)
.addPathSegments("accounts", params.getPathParam(0))
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { updateHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val listHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** List account configurations. */
override suspend fun list(
params: AccountListParams,
requestOptions: RequestOptions
): AccountListPageAsync {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("accounts")
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
response
.use { listHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
.let { AccountListPageAsync.of(this, params, it) }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy