package de.nccloud.reporting.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.Int 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 ViewsClient { @GET(value="views") fun getViews( @Query(value="offset") offset: Int, @Query(value="limit") limit: Int, @Query(value="sort_by") sortBy: String, @Query(value="direction") direction: de.nccloud.common.v0.enums.SortDirection ): Single> @GET(value="views/{guid}") fun getViewsGuid(@Path(value="guid") guid: UUID): Single> @POST(value="views") fun postViews(@Body viewForm: ViewForm): Single> @PUT(value="views/{guid}") fun putViewsGuid(@Path(value="guid") guid: UUID, @Body viewForm: ViewForm): Single> @DELETE(value="views/{guid}") fun deleteViewsGuid(@Path(value="guid") guid: UUID): Single> object GetViewsGuidCall { 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: ViewsClient, guid: UUID) = ApiNetworkCallResponse( client.getViewsGuid(guid) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) sealed class ErrorResponses { object Error404 : ErrorResponses() } } object PostViewsCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 400 -> body?.let { CallError(ErrorResponses.Error400(de.nccloud.reporting.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, de.nccloud.common.v0.models.GenericErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(400, "No Body")) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: ViewsClient, viewForm: ViewForm) = ApiNetworkCallResponse( client.postViews(viewForm) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object `de.nccloud.common.v0.models.GenericErrorListTypeReference` : TypeReference>() sealed class ErrorResponses { data class Error400( val data: List ) : ErrorResponses() } } object PutViewsGuidCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 400 -> body?.let { CallError(ErrorResponses.Error400(de.nccloud.reporting.api.v0.models.JacksonObjectMapperFactory.create().readValue(body, de.nccloud.common.v0.models.GenericErrorListTypeReference ))) } ?: CommonNetworkError(UnknownNetworkError(400, "No Body")) 404 -> CallError (ErrorResponses.Error404) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: ViewsClient, guid: UUID, viewForm: ViewForm ) = ApiNetworkCallResponse( client.putViewsGuid(guid,viewForm) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) object `de.nccloud.common.v0.models.GenericErrorListTypeReference` : TypeReference>() sealed class ErrorResponses { data class Error400( val data: List ) : ErrorResponses() object Error404 : ErrorResponses() } } object DeleteViewsGuidCall { 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: ViewsClient, guid: UUID) = ApiNetworkCallResponse( client.deleteViewsGuid(guid) .map{ response -> if(response.isSuccessful) Pair(Unit, response.code()) else throw HttpException(response)} .map{it} , toError) sealed class ErrorResponses { object Error404 : ErrorResponses() } } }