Skip to content

Instantly share code, notes, and snippets.

@DroidLove
Created December 28, 2018 12:13
Show Gist options
  • Save DroidLove/6de1e38c81a039936218dd0787478cf8 to your computer and use it in GitHub Desktop.
Save DroidLove/6de1e38c81a039936218dd0787478cf8 to your computer and use it in GitHub Desktop.
class APIService {
private lateinit var apiInterface: APIInterface
fun getClient(): APIInterface {
val gson = GsonBuilder().create()
val retrofit = Retrofit.Builder()
.baseUrl("https://limitless-lake-93364.herokuapp.com")
.client(provideOkHttpClient(provideLoggingInterceptor()))
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
apiInterface = retrofit.create(APIInterface::class.java)
return apiInterface
}
private fun provideOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient {
val b = OkHttpClient.Builder()
b.addInterceptor(interceptor)
return b.build()
}
private fun provideLoggingInterceptor(): HttpLoggingInterceptor {
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY
return interceptor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment