package platform.ibm.com.customer.api.v0.models import com.fasterxml.jackson.core.type.TypeReference import com.jakewharton.retrofit2.adapter.rxjava2.HttpException import io.apibuilder.app.ApiNetworkCallResponse import io.apibuilder.app.CommonNetworkErrors import io.apibuilder.app.CommonNetworkErrors.UnknownNetworkError import io.apibuilder.app.EitherCallOrCommonNetworkError import io.apibuilder.app.EitherCallOrCommonNetworkError.CallError import io.apibuilder.app.EitherCallOrCommonNetworkError.CommonNetworkError import io.reactivex.Single import java.util.UUID import kotlin.String import kotlin.Throwable import kotlin.collections.List import retrofit2.Response import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.PUT import retrofit2.http.Path import retrofit2.http.Query /** * This code was generated by [models.generator.kotlin.KotlinGenerator] */ interface CustomersClient { /** * Search for a specific customer. You must specify at least 1 parameter - either a guid, email or * token - and will receive back either 0 or 1 users. */ @GET(value="customers/customers") fun getCustomersCustomers( @Query(value="financialAccountNumber") financialAccountNumber: UUID?, @Query(value="email") email: String?, @Query(value="customerName") customerName: String? ): Single>> /** * Returns information about the user with this financialAccountNumber. */ @GET(value="customers/{customerName}") fun getCustomersCustomerName(@Path(value="customerName") customerName: String): Single> /** * Create a new customer. */ @POST(value="customers/customers") fun postCustomersCustomers(@Body customerCreateForm: CustomerCreateForm): Single> /** * Updates information about the customer with the specified financialAccountNumber. */ @PUT(value="customers/{customerName}") fun putCustomersCustomerName(@Path(value="customerName") customerName: String, @Body customerUpdateForm: CustomerUpdateForm): Single> object GetCustomersCustomersCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> body?.let { CallError(ErrorResponses.Error404(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(404, "No Body")) 500 -> body?.let { CallError(ErrorResponses.Error500(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(500, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: CustomersClient, financialAccountNumber: UUID?, email: String?, customerName: String? ) = ApiNetworkCallResponse( client.getCustomersCustomers(financialAccountNumber,email,customerName) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object ErrorListTypeReference : TypeReference>() object ErrorListTypeReference : TypeReference>() /** * Error Responses for getCustomersCustomers - Search for a specific customer. You must specify * at least 1 parameter - either a guid, email or token - and will receive back either 0 or 1 * users. */ sealed class ErrorResponses { data class Error404( val data: List ) : ErrorResponses() data class Error500( val data: List ) : ErrorResponses() } } object GetCustomersCustomerNameCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> body?.let { CallError(ErrorResponses.Error404(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(404, "No Body")) 500 -> body?.let { CallError(ErrorResponses.Error500(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(500, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: CustomersClient, customerName: String) = ApiNetworkCallResponse( client.getCustomersCustomerName(customerName) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object ErrorListTypeReference : TypeReference>() object ErrorListTypeReference : TypeReference>() /** * Error Responses for getCustomersCustomerName - Returns information about the user with this * financialAccountNumber. */ sealed class ErrorResponses { data class Error404( val data: List ) : ErrorResponses() data class Error500( val data: List ) : ErrorResponses() } } object PostCustomersCustomersCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 500 -> body?.let { CallError(ErrorResponses.Error500(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(500, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: CustomersClient, customerCreateForm: CustomerCreateForm) = ApiNetworkCallResponse( client.postCustomersCustomers(customerCreateForm) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object ErrorListTypeReference : TypeReference>() /** * Error Responses for postCustomersCustomers - Create a new customer. */ sealed class ErrorResponses { data class Error500( val data: List ) : ErrorResponses() } } object PutCustomersCustomerNameCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> body?.let { CallError(ErrorResponses.Error404(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(404, "No Body")) 500 -> body?.let { CallError(ErrorResponses.Error500(platform.ibm.com.customer.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(500, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: CustomersClient, customerName: String, customerUpdateForm: CustomerUpdateForm ) = ApiNetworkCallResponse( client.putCustomersCustomerName(customerName,customerUpdateForm) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object ErrorListTypeReference : TypeReference>() object ErrorListTypeReference : TypeReference>() /** * Error Responses for putCustomersCustomerName - Updates information about the customer with * the specified financialAccountNumber. */ sealed class ErrorResponses { data class Error404( val data: List ) : ErrorResponses() data class Error500( val data: List ) : ErrorResponses() } } }