refactor(di): move ApiModule to core and api

This commit is contained in:
Harsh Shandilya 2022-11-13 16:08:02 +05:30
parent 9d41b7e819
commit 005dc9ab83
No known key found for this signature in database
4 changed files with 69 additions and 18 deletions

View file

@ -0,0 +1,43 @@
/*
* Copyright © 2021-2022 Harsh Shandilya.
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
package dev.msfjarvis.claw.api.injection
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import dev.msfjarvis.claw.api.LobstersApi
import dev.msfjarvis.claw.injection.scopes.AppScope
import okhttp3.OkHttpClient
import retrofit2.CallAdapter
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.create
@Module
@ContributesTo(AppScope::class)
object ApiModule {
@Provides
fun provideRetrofit(
client: OkHttpClient,
converterFactories: Set<@JvmSuppressWildcards Converter.Factory>,
callAdapterFactories: Set<@JvmSuppressWildcards CallAdapter.Factory>
): Retrofit {
return Retrofit.Builder()
.client(client)
.baseUrl(LobstersApi.BASE_URL)
.apply {
converterFactories.forEach(this::addConverterFactory)
callAdapterFactories.forEach(this::addCallAdapterFactory)
}
.build()
}
@Provides
fun provideApi(retrofit: Retrofit): LobstersApi {
return retrofit.create()
}
}