Created
December 28, 2018 12:13
-
-
Save DroidLove/6de1e38c81a039936218dd0787478cf8 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
class APIService { | |
private lateinit var apiInterface: APIInterface | |
fun getClient(): APIInterface { | |
val gson = GsonBuilder().create() | |
val retrofit = Retrofit.Builder() | |
.baseUrl("https://limitless-lake-93364.herokuapp.com") | |
.client(provideOkHttpClient(provideLoggingInterceptor())) | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | |
.build() | |
apiInterface = retrofit.create(APIInterface::class.java) | |
return apiInterface | |
} | |
private fun provideOkHttpClient(interceptor: HttpLoggingInterceptor): OkHttpClient { | |
val b = OkHttpClient.Builder() | |
b.addInterceptor(interceptor) | |
return b.build() | |
} | |
private fun provideLoggingInterceptor(): HttpLoggingInterceptor { | |
val interceptor = HttpLoggingInterceptor() | |
interceptor.level = HttpLoggingInterceptor.Level.BODY | |
return interceptor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment