@Provides fun provideRetrofit(client: OkHttpClient, gson: Gson): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
}
@Provides fun providesOkHttpClient(httpLoggingInterceptor: HttpLoggingInterceptor, apiKeyRepository: ApiKeyRepository): OkHttpClient {
val apiKey = apiKeyRepository.getApiKey()
return OkHttpClient.Builder().writeTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.callTimeout(1, TimeUnit.MINUTES)
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(AuthRetrofitInterceptor("$apiKey"))
.build()
}
@Provides @Singleton fun providesRepoApi(retrofit: Retrofit) : RepoApi {
return retrofit.create(RepoApi::
class.java)
}