Skip to content

Instantly share code, notes, and snippets.

@wangerekaharun
Created November 8, 2019 18:05
Show Gist options
  • Select an option

  • Save wangerekaharun/b49d88729433bb1800bff641caac17f8 to your computer and use it in GitHub Desktop.

Select an option

Save wangerekaharun/b49d88729433bb1800bff641caac17f8 to your computer and use it in GitHub Desktop.
val retrofit = module(override = true) {
single {
val interceptor = HttpLoggingInterceptor()
if (BuildConfig.DEBUG) {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.BODY }
} else {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.NONE }
}
val client = OkHttpClient.Builder()
.addInterceptor(interceptor).build()
Retrofit.Builder()
.baseUrl(Utils.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
}
}
val authClient = module {
single {
val interceptor = HttpLoggingInterceptor()
if (BuildConfig.DEBUG) {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.BODY }
} else {
interceptor.apply { interceptor.level = HttpLoggingInterceptor.Level.NONE }
}
OkHttpClient.Builder().addInterceptor(AuthInterceptor()).addInterceptor(interceptor).build()
}
}
val authRetrofit = module {
single {
Retrofit.Builder()
.baseUrl(Utils.BASE_URL)
.client(get())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
}
@jumaallan
Copy link
Copy Markdown

module(override = true) is not necessary - if the project doesn't have multiple modules, or the base url doesn't change

@wangerekaharun
Copy link
Copy Markdown
Author

module(override = true) is not necessary - if the project doesn't have multiple modules, or the base url doesn't change

Noted. Thanks for pointing this out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment