From 45c36389d5e4df2c58b41d7ef158a3d36a293103 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 23 May 2021 12:31:48 -0700 Subject: [PATCH] Combined HttpUrl building. --- .../net/thauvin/erik/crypto/CryptoPrice.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt index 14095b4..2dd08eb 100644 --- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt +++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt @@ -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, params: Map = 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) {