Created
March 8, 2018 02:07
-
-
Save cdmunoz/563ec0ff901be1d63b119edd808aa7e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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