package com.example.ayudapy import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Call import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import retrofit2.http.GET import retrofit2.http.Path import retrofit2.http.Query import java.util.concurrent.TimeUnit interface ApiService { @GET("?in_bbox") fun getListaCentro( @Query("limit") limit : Int, @Query("offset") offset : Int ): Call /* @GET("helprequestsgeo/") fun getHelpRequests(@Query("in_bbox") boundaryBox: String): Call*/ @GET("?in_bbox") fun getListaPedidos( @Query("limit") limit : Int, @Query("offset") offset : Int ): Call @GET("{id}") fun getPedidoDetalle( @Path("id") id : Int ): Call companion object { // init Retrofit base server instance val redditClient by lazy { ApiService.invoke("https://ayudapy.org/api/v1/donationcenters/") } val stackClient by lazy { ApiService.invoke("https://ayudapy.org/api/v1/helprequestsgeo/") } val pedidoDetalle by lazy { ApiService.invoke("https://ayudapy.org/api/v1/helprequests/") } private val loggingInterceptor = HttpLoggingInterceptor().apply { this.level = HttpLoggingInterceptor.Level.BODY } operator fun invoke(baseUrl: String): ApiService { val client = OkHttpClient.Builder().apply { /**addNetworkInterceptor(StethoInterceptor()) */ addNetworkInterceptor(loggingInterceptor) connectTimeout(10, TimeUnit.MINUTES) readTimeout(10, TimeUnit.MINUTES) writeTimeout(10, TimeUnit.MINUTES) }.build() return Retrofit.Builder() .client(client) .baseUrl(baseUrl) // .addCallAdapterFactory(CoroutineCallAdapterFactory()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(ApiService::class.java) } } }