package de.nccloud.registry.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.Int import kotlin.String import kotlin.Throwable import kotlin.collections.List import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query /** * This code was generated by [models.generator.kotlin.KotlinGenerator] */ interface ServicesClient { /** * Get all services. */ @GET(value="") fun get_( @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="/{name}") fun getName(@Path(value="name") name: String): Single> /** * Get the URI of given service. */ @GET(value="/{name}/uri") fun getNameUri(@Path(value="name") name: String): Single> object GetNameCall { 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: ServicesClient, name: String) = ApiNetworkCallResponse( client.getName(name) .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 GetNameUriCall { 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: ServicesClient, name: String) = ApiNetworkCallResponse( client.getNameUri(name) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getNameUri - Get the URI of given service. */ sealed class ErrorResponses { object Error404 : ErrorResponses() } } }