File tree Expand file tree Collapse file tree 1 file changed +17
-14
lines changed
shared/src/commonMain/kotlin/com/hoc081098/github_search_kmm/data/remote Expand file tree Collapse file tree 1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import io.ktor.client.request.get
1111import io.ktor.http.Url
1212import kotlinx.coroutines.withContext
1313
14+ typealias ColorResponseType = Map <String , Map <String , String ?>>
15+
1416internal open class KtorGithubLanguageColorApi (
1517 private val url : Url ,
1618 private val httpClient : HttpClient ,
@@ -21,21 +23,22 @@ internal open class KtorGithubLanguageColorApi(
2123 .catch {
2224 httpClient
2325 .get(url)
24- .body<Map <String , Map <String , String ?>>>()
26+ .body<ColorResponseType >()
27+ }
28+ .flatMap { it.toColors() }
29+ }
30+
31+ private fun ColorResponseType.toColors (): Either <IllegalStateException , Map <String , ArgbColor >> {
32+ return mapNotNull { (k, v) ->
33+ v[" color" ]?.let {
34+ k to it
2535 }
26- .flatMap { map ->
27- map
28- .mapNotNull { (k, v) ->
29- v[" color" ]?.let {
30- k to it
31- }
32- }
33- .traverse { (k, v) ->
34- ArgbColor
35- .parse(v)
36- .mapLeft(::IllegalStateException )
37- .map { k to it }
38- }
36+ }
37+ .traverse { (k, v) ->
38+ ArgbColor
39+ .parse(v)
40+ .mapLeft(::IllegalStateException )
41+ .map { k to it }
3942 }
4043 .map { it.toMap() }
4144 }
You can’t perform that action at this time.
0 commit comments