deployment.DeploymentApi.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of evaluation-proxy-core Show documentation
Show all versions of evaluation-proxy-core Show documentation
Core package for Amplitude's evaluation proxy.
package com.amplitude.deployment
import com.amplitude.VERSION
import com.amplitude.experiment.evaluation.EvaluationFlag
import com.amplitude.util.get
import com.amplitude.util.json
import com.amplitude.util.logger
import com.amplitude.util.retry
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.request.headers
import io.ktor.client.request.parameter
internal interface DeploymentApi {
suspend fun getFlagConfigs(deploymentKey: String): List
}
internal class DeploymentApiV1(
private val serverUrl: String
) : DeploymentApi {
companion object {
val log by logger()
}
private val client = HttpClient(OkHttp)
override suspend fun getFlagConfigs(deploymentKey: String): List {
log.trace("getFlagConfigs: start - deploymentKey=$deploymentKey")
val response = retry(onFailure = { e -> log.error("Get flag configs failed: $e") }) {
client.get(serverUrl, "/sdk/v2/flags") {
parameter("v", "0")
headers {
set("Authorization", "Api-Key $deploymentKey")
set("X-Amp-Exp-Library", "experiment-local-proxy/$VERSION")
}
}
}
return json.decodeFromString>(response.body()).also {
log.trace("getFlagConfigs: end - deploymentKey=$deploymentKey")
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy