Skip to content

Commit

Permalink
simplify toFlags logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Yiu authored and Tim Yiu committed Sep 25, 2023
1 parent ea962e4 commit 03aa7e4
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions sdk/src/main/java/com/amplitude/experiment/FlagApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.amplitude.experiment.util.Logger
import kotlinx.serialization.decodeFromString
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.json.JSONArray
import java.io.IOException
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -54,14 +53,8 @@ internal class SdkFlagApi(
try {
Logger.d("Received fetch response: $response")
val body = response.body?.string() ?: ""
val jsonArray = JSONArray(body)
val flags = mutableMapOf<String, EvaluationFlag>()
(0 until jsonArray.length()).forEach {
val jsonString = jsonArray.getJSONObject(it).toString()
val flag = json.decodeFromString<EvaluationFlag>(jsonString)
flags[flag.key] = flag
}

val flags = json.decodeFromString<List<EvaluationFlag>>(body)
.associateBy { it.key }
future.complete(flags)
} catch (e: IOException) {
onFailure(call, e)
Expand Down

0 comments on commit 03aa7e4

Please sign in to comment.