Last active
February 4, 2018 17:36
-
-
Save mohsenoid/2fa179f7d64c8ba0c9a5516d66c8a0d2 to your computer and use it in GitHub Desktop.
Sample ApiModule https://hackernoon.com/yet-another-mvp-article-part-3-calling-apis-using-retrofit-23757f4eee05
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
package com.mirhoseini.marvel.domain; | |
/*...*/ | |
@Module | |
public class ApiModule { | |
@Provides | |
@Singleton | |
public MarvelApi provideMarvelApi(Retrofit retrofit) { | |
return retrofit.create(MarvelApi.class); | |
} | |
@Provides | |
@Singleton | |
public Retrofit provideRetrofit(HttpUrl baseUrl, Converter.Factory converterFactory, CallAdapter.Factory callAdapterFactory, OkHttpClient okHttpClient) { | |
return new Retrofit.Builder() | |
.baseUrl(baseUrl) | |
.addConverterFactory(converterFactory) | |
.addCallAdapterFactory(callAdapterFactory) | |
.client(okHttpClient) | |
.build(); | |
} | |
@Provides | |
@Singleton | |
public Converter.Factory provideGsonConverterFactory(Gson gson) { | |
return GsonConverterFactory.create(gson); | |
} | |
@Singleton | |
@Provides | |
public Gson provideGson() { | |
return new Gson(); | |
} | |
@Provides | |
@Singleton | |
public CallAdapter.Factory provideRxJavaCallAdapterFactory() { | |
return RxJavaCallAdapterFactory.create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment