Combined HttpUrl building.

This commit is contained in:
Erik C. Thauvin 2021-05-23 12:31:48 -07:00
parent 23ada77699
commit 45c36389d5

View file

@ -75,16 +75,16 @@ open class CryptoPrice(val base: String, val currency: String, val amount: Doubl
@Throws(CryptoException::class, IOException::class)
fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String {
val client = OkHttpClient()
val url = COINBASE_API_URL.toHttpUrl().newBuilder()
val httpUrl = COINBASE_API_URL.toHttpUrl().newBuilder().apply {
paths.forEach {
addPathSegment(it)
}
params.forEach {
addQueryParameter(it.key, it.value)
}
}.build()
paths.forEach {
url.addPathSegment(it)
}
params.forEach {
url.addQueryParameter(it.key, it.value)
}
val request = Request.Builder().url(url.build()).build()
val request = Request.Builder().url(httpUrl).build()
val response = client.newCall(request).execute()
val body = response.body?.string()
if (body != null) {