Skip to content

Commit 2bf32ed

Browse files
frettclaude
andcommitted
Introduce ApiConfig to consolidate API configuration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eee004b commit 2bf32ed

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/src/main/kotlin/org/cru/godtools/dagger/ConfigModule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import dagger.Module
44
import dagger.Provides
55
import dagger.hilt.InstallIn
66
import dagger.hilt.components.SingletonComponent
7-
import javax.inject.Named
87
import org.cru.godtools.BuildConfig
9-
import org.cru.godtools.api.ApiModule
8+
import org.cru.godtools.api.ApiConfig
109

1110
@Module
1211
@InstallIn(SingletonComponent::class)
1312
object ConfigModule {
1413
@get:Provides
15-
@get:Named(ApiModule.MOBILE_CONTENT_API_URL)
16-
val mobileContentApiBaseUrl = BuildConfig.MOBILE_CONTENT_API
14+
val apiConfig = ApiConfig(
15+
mobileContentApiUrl = BuildConfig.MOBILE_CONTENT_API
16+
)
1717
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.cru.godtools.api
2+
3+
data class ApiConfig(
4+
val mobileContentApiUrl: String
5+
)

library/api/src/main/kotlin/org/cru/godtools/api/ApiModule.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,18 @@ object ApiModule {
7979
.build()
8080

8181
// region mobile-content-api APIs
82-
const val MOBILE_CONTENT_API_URL = "MOBILE_CONTENT_API_BASE_URL"
8382
private const val MOBILE_CONTENT_API = "MOBILE_CONTENT_API"
8483
private const val MOBILE_CONTENT_API_AUTHENTICATED = "MOBILE_CONTENT_API_AUTHENTICATED"
8584

8685
@Provides
8786
@Reusable
8887
@Named(MOBILE_CONTENT_API)
8988
fun mobileContentApiRetrofit(
90-
@Named(MOBILE_CONTENT_API_URL) baseUrl: String,
89+
apiConfig: ApiConfig,
9190
jsonApiConverter: JsonApiConverter,
9291
okhttp: OkHttpClient,
9392
): Retrofit = Retrofit.Builder()
94-
.baseUrl(baseUrl)
93+
.baseUrl(apiConfig.mobileContentApiUrl)
9594
.addConverterFactory(LocaleConverterFactory)
9695
.addConverterFactory(JsonApiConverterFactory(jsonApiConverter))
9796
.callFactory(okhttp)
@@ -165,14 +164,16 @@ object ApiModule {
165164
@Provides
166165
@Reusable
167166
fun actionCableScarlet(
168-
@Named(MOBILE_CONTENT_API_URL) baseUrl: String,
167+
apiConfig: ApiConfig,
169168
app: Application,
170169
jsonApi: JsonApiConverter,
171170
okhttp: OkHttpClient,
172171
referenceLifecycle: ReferenceLifecycle,
173172
) = Scarlet.Builder()
174173
.forceDefaultPlatform()
175-
.webSocketFactory(okhttp.newWebSocketFactory(ActionCableRequestFactory("${baseUrl}cable")))
174+
.webSocketFactory(
175+
okhttp.newWebSocketFactory(ActionCableRequestFactory("${apiConfig.mobileContentApiUrl}cable"))
176+
)
176177
.addMessageAdapterFactory(
177178
ActionCableMessageAdapterFactory.Builder()
178179
.addMessageAdapterFactory(JsonApiMessageAdapterFactory(jsonApi))

0 commit comments

Comments
 (0)