package payp.mard2p.api.v0.models import com.jakewharton.retrofit2.adapter.rxjava2.HttpException import io.apibuilder.app.ApiNetworkCallResponse import io.apibuilder.app.CommonNetworkErrors import io.apibuilder.app.EitherCallOrCommonNetworkError import io.apibuilder.app.EitherCallOrCommonNetworkError.CallError import io.apibuilder.app.EitherCallOrCommonNetworkError.CommonNetworkError import io.reactivex.Single import kotlin.Double import kotlin.Long import kotlin.String import kotlin.Throwable import kotlin.Unit import kotlin.collections.List import retrofit2.Response import retrofit2.http.DELETE 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 AccountsClient { /** * Used to create an account. */ @POST(value="accounts/create") fun postAccountsCreate( @Query(value="accountid") accountid: Long, @Query(value="ownerid") ownerid: String, @Query(value="total_amount") totalAmount: Double, @Query(value="sold") sold: Double, @Query(value="debit") debit: Double, @Query(value="currency") currency: String ): Single> /** * Used to update an account. */ @PUT(value="accounts/update/{accountid}") fun putAccountsUpdateAccountid( @Path(value="accountid") accountid: Long, @Query(value="ownerid") ownerid: String, @Query(value="total_amount") totalAmount: Double, @Query(value="currency") currency: String, @Query(value="sold") sold: Double, @Query(value="debit") debit: Double ): Single> /** * Delete some account. */ @DELETE(value="accounts/delete/{accountid}") fun deleteAccountsDeleteAccountid(@Path(value="accountid") accountid: Long): Single> /** * Find account by its id */ @GET(value="accounts/{accountid}") fun getAccountsAccountid( @Path(value="accountid") accountid: Long, @Query(value="ownerid") ownerid: String, @Query(value="total_amount") totalAmount: Double, @Query(value="sold") sold: Double, @Query(value="debit") debit: Double, @Query(value="currency") currency: String ): Single> /** * Find all the accounts. */ @GET(value="accounts/list") fun getAccountsList( @Query(value="accountid") accountid: Long, @Query(value="ownerid") ownerid: String, @Query(value="total_amount") totalAmount: Double, @Query(value="currency") currency: String, @Query(value="sold") sold: Double, @Query(value="debit") debit: Double ): Single>> object PostAccountsCreateCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 409 -> CallError (ErrorResponses.Error409) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: AccountsClient, accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String ) = ApiNetworkCallResponse( client.postAccountsCreate(accountid,ownerid,totalAmount,sold,debit,currency) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for postAccountsCreate - Used to create an account. */ sealed class ErrorResponses { object Error409 : ErrorResponses() } } object PutAccountsUpdateAccountidCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 409 -> CallError (ErrorResponses.Error409) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: AccountsClient, accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double ) = ApiNetworkCallResponse( client.putAccountsUpdateAccountid(accountid,ownerid,totalAmount,currency,sold,debit) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for putAccountsUpdateAccountid - Used to update an account. */ sealed class ErrorResponses { object Error409 : ErrorResponses() } } object DeleteAccountsDeleteAccountidCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 401 -> CallError (ErrorResponses.Error401) 404 -> CallError (ErrorResponses.Error404) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: AccountsClient, accountid: Long) = ApiNetworkCallResponse( client.deleteAccountsDeleteAccountid(accountid) .map{ response -> if(response.isSuccessful) Pair(Unit, response.code()) else throw HttpException(response)} .map{it} , toError) /** * Error Responses for deleteAccountsDeleteAccountid - Delete some account. */ sealed class ErrorResponses { object Error401 : ErrorResponses() object Error404 : ErrorResponses() } } object GetAccountsAccountidCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> CallError (ErrorResponses.Error404) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: AccountsClient, accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String ) = ApiNetworkCallResponse( client.getAccountsAccountid(accountid,ownerid,totalAmount,sold,debit,currency) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getAccountsAccountid - Find account by its id */ sealed class ErrorResponses { object Error404 : ErrorResponses() } } object GetAccountsListCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> CallError (ErrorResponses.Error404) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: AccountsClient, accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double ) = ApiNetworkCallResponse( client.getAccountsList(accountid,ownerid,totalAmount,currency,sold,debit) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getAccountsList - Find all the accounts. */ sealed class ErrorResponses { object Error404 : ErrorResponses() } } }