```fun get_currency_value(currency: String): Strin...
# codingconventions
f
Copy code
fun get_currency_value(currency: String): String {
    val r = khttp.get("<https://api.coinbase.com/v2/exchange-rates?currency=$currency>")
    when (r.statusCode) {
        200 -> return r.jsonObject.getJSONObject("data").getJSONObject("rates").getString("USD")
        else -> return ""
    }
}
r
feniix: should be fun getCurrencyValue
just not like pyhton
koltin conventions regard to java
f
thanks this is how it looks like now
Copy code
fun getCurrencyValue(currency: String? = "ETH"): String? {
    return try {
        val r = khttp.get("<https://api.coinbase.com/v2/exchange-rates?currency=$currency>")
        logger.debug { r.statusCode }
        when (r.statusCode) {
            200 -> r.jsonObject.getJSONObject("data").getJSONObject("rates").getString("USD")
            else -> null
        }
    } catch (e: Exception) {
        logger.error { e }
        null
    }
}
r
awesome, that much concise
for more advance
you should use kind of retrofit, and gson
use serializable
for send object through class or functions
👍
j
One more thing! You were right about the duplicate returns being bad. Instead, do
Copy code
return when(r.statusCode) {
  200 -> r.json....getString("USD")
  else -> ""
}
❤️ 1
r
Awesome.
👍
f
thank you
the function looks more like this now
r
Awesome. For further, you can use extension function to wrap datetime
f
what do you mean? @radityagumay ?