Last active
January 13, 2019 22:58
-
-
Save navi25/7b32e0b875c79c8d45c51fdb7cabc42e to your computer and use it in GitHub Desktop.
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
//ApiFactory to create TMDB Api | |
object Apifactory{ | |
//Creating Auth Interceptor to add api_key query in front of all the requests. | |
private val authInterceptor = Interceptor {chain-> | |
val newUrl = chain.request().url() | |
.newBuilder() | |
.addQueryParameter("api_key", AppConstants.tmdbApiKey) | |
.build() | |
val newRequest = chain.request() | |
.newBuilder() | |
.url(newUrl) | |
.build() | |
chain.proceed(newRequest) | |
} | |
//OkhttpClient for building http request url | |
private val tmdbClient = OkHttpClient().newBuilder() | |
.addInterceptor(authInterceptor) | |
.build() | |
fun retrofit() : Retrofit = Retrofit.Builder() | |
.client(tmdbClient) | |
.baseUrl("https://api.themoviedb.org/3/") | |
.addConverterFactory(MoshiConverterFactory.create()) | |
.addCallAdapterFactory(CoroutineCallAdapterFactory()) | |
.build() | |
val tmdbApi : TmdbApi = retrofit().create(TmdbApi::class.java) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment