ApiClient.kt
The snippet can be accessed without any authentication.
Authored by
a6-alrashdi
Edited
ApiClient.kt 1.25 KiB
import com.example.match.api.MatchApiService
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
object ApiClient {
private const val BASE_URL = "http://api2.isportsapi.com/"
private const val API_KEY = "4ODgWsnxTdHYKjb1"
private val okHttpClient: OkHttpClient by lazy {
OkHttpClient.Builder()
.addInterceptor { chain ->
val original = chain.request()
val originalUrl = original.url
val newUrl = originalUrl.newBuilder()
.addQueryParameter("api_key", API_KEY)
.build()
println("Final Request URL: $newUrl")
val newRequest = original.newBuilder()
.url(newUrl)
.build()
println("API Request URL: $newUrl")
chain.proceed(newRequest)
}
.build()
}
val matchApi: MatchApiService by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(MatchApiService::class.java)
}
}
Please register or sign in to comment