vkay94 / TMDb-Kotlin

TheMovieDatabase API wrapper for Kotlin
https://vkay94.github.io/TMDb-Kotlin
Apache License 2.0
9 stars 2 forks source link

Providing `OkHttpClient` #3

Open Nevercom opened 3 years ago

Nevercom commented 3 years ago

Hi, This is more of a question. I'm trying to understand the process of providing a different instance of OkHttpClient without interfering with library's functionality.

As stated in documentation, it is possible to add certain modifications to TMDbInterceptor and then assign the new Interceptor to TMDb.tmdbInterceptor before calling init. However it seems that TMDb.tmdbInterceptor is immediately overwritten in defaultOkHttpClient() function: https://github.com/vkay94/TMDb-Kotlin/blob/5feaa37702d65a84ac9d58e88187e49b88a6e353/src/main/java/de/vkay/api/tmdb/TMDb.kt#L159-L162

Furthermore, if we provide our own instance of OkHttpClient, no TMDbInterceptor is attached to it, unless we add it to OkHttpClient ourselves and also set the TMDb.tmdbInterceptor, as it seems that it only gets instantiated in defaultOkHttpClient() function, and several functionalities of the library depend on TMDb.tmdbInterceptor not being null.

I'm not sure about all these and it would be great if you could shed some light on this matter.

If I'm right though, it seems that if the defaultOkHttpClient() get called anyway, regardless of user providing OkHttpClient or not, could be the solution. Of course it needs to instantiate a new OkHttpClient if user has not provided one, and then modify it (add Interceptor) and also instantiate the TMDb.tmdbInterceptor.