Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 8, 2018 02:07
Show Gist options
  • Save cdmunoz/563ec0ff901be1d63b119edd808aa7e3 to your computer and use it in GitHub Desktop.
Save cdmunoz/563ec0ff901be1d63b119edd808aa7e3 to your computer and use it in GitHub Desktop.
@Module
class NetModule(private val baseUrl: String) {
@Provides
@Singleton
fun providesOkHttpClient(): OkHttpClient = OkHttpClient.Builder().build()
@Provides
@Singleton
fun providesMoshi(): Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
@Provides
@Singleton
fun providesRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): Retrofit {
return Builder().client(okHttpClient).baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
}
@Provides
@Singleton
fun providesApiInterface(retrofit: Retrofit): ApiInterface = retrofit.create(
ApiInterface::class.java)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment