diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationLoader.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationLoader.kt index 3ce876c3..a05375d7 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationLoader.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationLoader.kt @@ -29,11 +29,9 @@ internal class TurboPathConfigurationLoader(val context: Context) : CoroutineSco loadCachedConfigurationForUrl(url, onCompletion) launch { - repository.getRemoteConfiguration(url)?.let { remoteConfigJson -> - repository.parseFromJson(remoteConfigJson)?.let { config -> - onCompletion(config) - cacheConfigurationForUrl(url, config) - } + repository.getRemoteConfiguration(url)?.let { config -> + onCompletion(config) + cacheConfigurationForUrl(url, config) } } } diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepository.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepository.kt index bdc3672a..90895ac9 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepository.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepository.kt @@ -16,11 +16,11 @@ import okhttp3.Request internal class TurboPathConfigurationRepository { private val cacheFile = "turbo" - suspend fun getRemoteConfiguration(url: String): String? { + suspend fun getRemoteConfiguration(url: String): TurboPathConfiguration? { val request = Request.Builder().url(url).build() return withContext(dispatcherProvider.io) { - issueRequest(request) + issueRequest(request)?.let { parseFromJson(it) } } } diff --git a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt index a2f6e7fe..71d92353 100644 --- a/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt +++ b/turbo/src/test/kotlin/dev/hotwire/turbo/config/TurboPathConfigurationRepositoryTest.kt @@ -35,10 +35,8 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() { runBlocking { launch(Dispatchers.Main) { - val json = repository.getRemoteConfiguration(baseUrl()) - assertThat(json).isNotNull() - - val config = repository.parseFromJson(json!!) + val config = repository.getRemoteConfiguration(baseUrl()) + assertThat(config).isNotNull() assertThat(config?.rules?.size).isEqualTo(2) } } @@ -50,10 +48,7 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() { runBlocking { launch(Dispatchers.Main) { - val json = repository.getRemoteConfiguration(baseUrl()) - assertThat(json).isNotNull() - - val config = repository.parseFromJson(json!!) + val config = repository.getRemoteConfiguration(baseUrl()) assertThat(config).isNull() } }