Combined HttpUrl building.
This commit is contained in:
parent
23ada77699
commit
45c36389d5
1 changed files with 9 additions and 9 deletions
|
@ -75,16 +75,16 @@ open class CryptoPrice(val base: String, val currency: String, val amount: Doubl
|
||||||
@Throws(CryptoException::class, IOException::class)
|
@Throws(CryptoException::class, IOException::class)
|
||||||
fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String {
|
fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String {
|
||||||
val client = OkHttpClient()
|
val client = OkHttpClient()
|
||||||
val url = COINBASE_API_URL.toHttpUrl().newBuilder()
|
val httpUrl = COINBASE_API_URL.toHttpUrl().newBuilder().apply {
|
||||||
|
|
||||||
paths.forEach {
|
paths.forEach {
|
||||||
url.addPathSegment(it)
|
addPathSegment(it)
|
||||||
}
|
}
|
||||||
params.forEach {
|
params.forEach {
|
||||||
url.addQueryParameter(it.key, it.value)
|
addQueryParameter(it.key, it.value)
|
||||||
}
|
}
|
||||||
|
}.build()
|
||||||
|
|
||||||
val request = Request.Builder().url(url.build()).build()
|
val request = Request.Builder().url(httpUrl).build()
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
val body = response.body?.string()
|
val body = response.body?.string()
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue