package com.edsancha.medallia.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.Throwable import retrofit2.Response import retrofit2.http.GET /** * This code was generated by [models.generator.kotlin.KotlinGenerator] */ interface ConfigurationsClient { /** * This API returns the full configuration as defined in the Medallia Digital command center. It * returns the list of surveys, their content and business logic as well as targeting and * segmentation rules. */ @GET(value="configuration") fun getConfiguration(): Single> object GetConfigurationCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 400 -> CallError (ErrorResponses.Error400) 401 -> CallError (ErrorResponses.Error401) 500 -> CallError (ErrorResponses.Error500) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda(client: ConfigurationsClient) = ApiNetworkCallResponse( client.getConfiguration() .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getConfiguration - This API returns the full configuration as defined in * the Medallia Digital command center. It returns the list of surveys, their content and business * logic as well as targeting and segmentation rules. */ sealed class ErrorResponses { object Error400 : ErrorResponses() object Error401 : ErrorResponses() object Error500 : ErrorResponses() } } }