-
-
Save jmfayard/b65b999a7729664365a11858e603c7eb to your computer and use it in GitHub Desktop.
From Zero To One: One refactoring later
This file contains 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
fun api() : ApiComponent = ApiModule | |
interface ApiComponent { | |
val okHttpClient: OkHttpClient | |
val moshi: Moshi | |
val catApi: CatApi | |
} | |
object ApiModule : ApiComponent { | |
val loggingInterceptor = HttpLoggingInterceptor() | |
.setLevel(HttpLoggingInterceptor.Level.BODY) | |
override val okHttpClient = OkHttpClient.Builder() | |
.addNetworkInterceptor(loggingInterceptor) | |
.build() | |
override val moshi = Moshi.Builder().build() | |
val retrofit = Retrofit.Builder() | |
.client(okHttpClient) | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
.addConverterFactory(MoshiConverterFactory.create(moshi)) | |
.baseUrl("http://httpbin.org") | |
.build() | |
override val catApi = retrofit.create(CatApi::class.java) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment