package io.flow.github.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.flow.github.v0.enums.Visibility import io.reactivex.Single import kotlin.Long 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 RepositoriesClient { @GET(value="user/repos") fun getUserRepos( @Query(value="page") page: Long, @Query(value="visibility") visibility: Visibility, @Query(value="affiliation") affiliation: String?, @Query(value="type") type: String?, @Query(value="sort") sort: String, @Query(value="direction") direction: String ): Single>> /** * List public repositories for the specified user. */ @GET(value="users/{username}/repos") fun getUsersUsernameRepos( @Path(value="username") username: String, @Query(value="page") page: Long, @Query(value="type") type: String, @Query(value="sort") sort: String, @Query(value="direction") direction: String ): Single>> /** * List repositories for the specified org. */ @GET(value="orgs/{org}/repos") fun getOrgsOrgRepos( @Path(value="org") org: String, @Query(value="page") page: Long, @Query(value="type") type: String, @Query(value="sort") sort: String, @Query(value="direction") direction: String ): Single>> object GetUserReposCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 401 -> CallError (ErrorResponses.Error401) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: RepositoriesClient, page: Long, visibility: Visibility, affiliation: String?, type: String?, sort: String, direction: String ) = ApiNetworkCallResponse( client.getUserRepos(page,visibility,affiliation,type,sort,direction) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) sealed class ErrorResponses { object Error401 : ErrorResponses() } } object GetUsersUsernameReposCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 401 -> CallError (ErrorResponses.Error401) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: RepositoriesClient, username: String, page: Long, type: String, sort: String, direction: String ) = ApiNetworkCallResponse( client.getUsersUsernameRepos(username,page,type,sort,direction) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getUsersUsernameRepos - List public repositories for the specified user. */ sealed class ErrorResponses { object Error401 : ErrorResponses() } } object GetOrgsOrgReposCall { val toError: (Throwable) -> EitherCallOrCommonNetworkError = { t -> when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { 401 -> CallError (ErrorResponses.Error401) else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } else -> CommonNetworkError(CommonNetworkErrors.processCommonNetworkError(t)) } } fun getCallAndErrorLambda( client: RepositoriesClient, org: String, page: Long, type: String, sort: String, direction: String ) = ApiNetworkCallResponse( client.getOrgsOrgRepos(org,page,type,sort,direction) .map{ response -> if(response.isSuccessful) response.body()?.let { body -> Pair(body, response.code())} else throw HttpException(response)} .map{it} , toError) /** * Error Responses for getOrgsOrgRepos - List repositories for the specified org. */ sealed class ErrorResponses { object Error401 : ErrorResponses() } } }