package io.apibuilder.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.Long import kotlin.String import kotlin.Throwable import kotlin.Unit import kotlin.collections.List import retrofit2.Response import retrofit2.http.Body 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 OrganizationsClient { /** * Search all organizations. Results are always paginated. */ @GET(value="organizations") fun getOrganizations( @Query(value="guid") guid: UUID?, @Query(value="user_guid") userGuid: UUID?, @Query(value="key") key: String?, @Query(value="name") name: String?, @Query(value="namespace") namespace: String?, @Query(value="limit") limit: Long, @Query(value="offset") offset: Long ): Single>> /** * Returns the organization with this key. */ @GET(value="organizations/{key}") fun getOrganizationsKey(@Path(value="key") key: String): Single> /** * Create a new organization. */ @POST(value="organizations") fun postOrganizations(@Body organizationForm: OrganizationForm): Single> /** * Update an organization. */ @PUT(value="organizations/{key}") fun putOrganizationsKey(@Path(value="key") key: String, @Body organizationForm: OrganizationForm): Single> /** * Deletes an organization and all of its associated applications. */ @DELETE(value="organizations/{key}") fun deleteOrganizationsKey(@Path(value="key") key: String): Single> /** * Returns all attribute values for this organization. Results are always paginated. */ @GET(value="organizations/{key}/attributes") fun getOrganizationsKeyAttributes( @Path(value="key") key: String, @Query(value="name") name: String?, @Query(value="limit") limit: Long, @Query(value="offset") offset: Long ): Single>> /** * Returns the attribute value with this name. */ @GET(value="organizations/{key}/attributes/{name}") fun getOrganizationsKeyAttributesName(@Path(value="key") key: String, @Path(value="name") name: String): Single> /** * Create or update a new attribute value. */ @PUT(value="organizations/{key}/attributes/{name}") fun putOrganizationsKeyAttributesName( @Path(value="key") key: String, @Path(value="name") name: String, @Body attributeValueForm: AttributeValueForm ): Single> /** * Deletes the attribute value with the specified name. Only the user who created an attribute * value can delete it. */ @DELETE(value="organizations/{key}/attributes/{name}") fun deleteOrganizationsKeyAttributesName(@Path(value="key") key: String, @Path(value="name") name: String): Single> object GetOrganizationsKeyCall { 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: OrganizationsClient, key: String) = ApiNetworkCallResponse( client.getOrganizationsKey(key) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getOrganizationsKey - Returns the organization with this key. */ sealed class ErrorResponses { object Error404 : ErrorResponses() } } object PostOrganizationsCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 409 -> body?.let { CallError(ErrorResponses.Error409(io.apibuilder.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(409, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: OrganizationsClient, organizationForm: OrganizationForm) = ApiNetworkCallResponse( client.postOrganizations(organizationForm) .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 postOrganizations - Create a new organization. */ sealed class ErrorResponses { data class Error409( val data: List ) : ErrorResponses() } } object PutOrganizationsKeyCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 409 -> body?.let { CallError(ErrorResponses.Error409(io.apibuilder.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(409, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: OrganizationsClient, key: String, organizationForm: OrganizationForm ) = ApiNetworkCallResponse( client.putOrganizationsKey(key,organizationForm) .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 putOrganizationsKey - Update an organization. */ sealed class ErrorResponses { data class Error409( val data: List ) : ErrorResponses() } } object GetOrganizationsKeyAttributesNameCall { 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: OrganizationsClient, key: String, name: String ) = ApiNetworkCallResponse( client.getOrganizationsKeyAttributesName(key,name) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getOrganizationsKeyAttributesName - Returns the attribute value with this * name. */ sealed class ErrorResponses { object Error404 : ErrorResponses() } } object PutOrganizationsKeyAttributesNameCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 404 -> CallError (ErrorResponses.Error404) 409 -> body?.let { CallError(ErrorResponses.Error409(io.apibuilder.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, ErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(409, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: OrganizationsClient, key: String, name: String, attributeValueForm: AttributeValueForm ) = ApiNetworkCallResponse( client.putOrganizationsKeyAttributesName(key,name,attributeValueForm) .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 putOrganizationsKeyAttributesName - Create or update a new attribute * value. */ sealed class ErrorResponses { object Error404 : ErrorResponses() data class Error409( val data: List ) : ErrorResponses() } } object DeleteOrganizationsKeyAttributesNameCall { 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: OrganizationsClient, key: String, name: String ) = ApiNetworkCallResponse( client.deleteOrganizationsKeyAttributesName(key,name) .map{ response -> if(response.isSuccessful) Pair(Unit, response.code()) else throw HttpException(response)} .map{it} , toError) /** * Error Responses for deleteOrganizationsKeyAttributesName - Deletes the attribute value with * the specified name. Only the user who created an attribute value can delete it. */ sealed class ErrorResponses { object Error401 : ErrorResponses() object Error404 : ErrorResponses() } } }