com.increase.api.services.async.EntityServiceAsyncImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of increase-java-core Show documentation
Show all versions of increase-java-core Show documentation
An SDK library for increase
The newest version!
// File generated from our OpenAPI spec by Stainless.
package com.increase.api.services.async
import com.increase.api.core.ClientOptions
import com.increase.api.core.RequestOptions
import com.increase.api.core.http.HttpMethod
import com.increase.api.core.http.HttpRequest
import com.increase.api.core.http.HttpResponse.Handler
import com.increase.api.errors.IncreaseError
import com.increase.api.models.Entity
import com.increase.api.models.EntityArchiveBeneficialOwnerParams
import com.increase.api.models.EntityArchiveParams
import com.increase.api.models.EntityConfirmParams
import com.increase.api.models.EntityCreateBeneficialOwnerParams
import com.increase.api.models.EntityCreateParams
import com.increase.api.models.EntityListPageAsync
import com.increase.api.models.EntityListParams
import com.increase.api.models.EntityRetrieveParams
import com.increase.api.models.EntityUpdateAddressParams
import com.increase.api.models.EntityUpdateBeneficialOwnerAddressParams
import com.increase.api.models.EntityUpdateIndustryCodeParams
import com.increase.api.services.errorHandler
import com.increase.api.services.json
import com.increase.api.services.jsonHandler
import com.increase.api.services.withErrorHandler
import java.util.concurrent.CompletableFuture
class EntityServiceAsyncImpl
constructor(
private val clientOptions: ClientOptions,
) : EntityServiceAsync {
private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper)
private val createHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Create an Entity */
override fun create(
params: EntityCreateParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { createHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val retrieveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Retrieve an Entity */
override fun retrieve(
params: EntityRetrieveParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("entities", params.getPathParam(0))
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { retrieveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val listHandler: Handler =
jsonHandler(clientOptions.jsonMapper)
.withErrorHandler(errorHandler)
/** List Entities */
override fun list(
params: EntityListParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.GET)
.addPathSegments("entities")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { listHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
.let { EntityListPageAsync.of(this, params, it) }
}
}
private val archiveHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Archive an Entity */
override fun archive(
params: EntityArchiveParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "archive")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.apply { params.getBody().ifPresent { body(json(clientOptions.jsonMapper, it)) } }
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { archiveHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val archiveBeneficialOwnerHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Archive a beneficial owner for a corporate Entity */
override fun archiveBeneficialOwner(
params: EntityArchiveBeneficialOwnerParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "archive_beneficial_owner")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { archiveBeneficialOwnerHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val confirmHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/**
* Depending on your program, you may be required to re-confirm an Entity's details on a
* recurring basis. After making any required updates, call this endpoint to record that your
* user confirmed their details.
*/
override fun confirm(
params: EntityConfirmParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "confirm")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { confirmHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val createBeneficialOwnerHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Create a beneficial owner for a corporate Entity */
override fun createBeneficialOwner(
params: EntityCreateBeneficialOwnerParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "create_beneficial_owner")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { createBeneficialOwnerHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val updateAddressHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Update a Natural Person or Corporation's address */
override fun updateAddress(
params: EntityUpdateAddressParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "update_address")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { updateAddressHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val updateBeneficialOwnerAddressHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Update the address for a beneficial owner belonging to a corporate Entity */
override fun updateBeneficialOwnerAddress(
params: EntityUpdateBeneficialOwnerAddressParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments(
"entities",
params.getPathParam(0),
"update_beneficial_owner_address"
)
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { updateBeneficialOwnerAddressHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
private val updateIndustryCodeHandler: Handler =
jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler)
/** Update the industry code for a corporate Entity */
override fun updateIndustryCode(
params: EntityUpdateIndustryCodeParams,
requestOptions: RequestOptions
): CompletableFuture {
val request =
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("entities", params.getPathParam(0), "update_industry_code")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response
->
response
.use { updateIndustryCodeHandler.handle(it) }
.apply {
if (requestOptions.responseValidation ?: clientOptions.responseValidation) {
validate()
}
}
}
}
}