mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
сделан impl
This commit is contained in:
parent
47aec110a8
commit
7bcf2c897c
2 changed files with 38 additions and 0 deletions
|
@ -0,0 +1,7 @@
|
|||
package su.redume.core.network.api
|
||||
|
||||
import su.redume.core.network.model.CurrencyDto
|
||||
|
||||
interface FiatCurrencyServer {
|
||||
suspend fun currency(): List<CurrencyDto>
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package su.redume.core.network.impl
|
||||
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
import io.ktor.client.plugins.defaultRequest
|
||||
import io.ktor.http.*
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.client.request.*
|
||||
import javax.inject.Inject
|
||||
import su.redume.core.network.api.FiatCurrencyServer
|
||||
import su.redume.core.network.model.CurrencyDto
|
||||
|
||||
class FiatCurrencyServerImpl @Inject constructor() : FiatCurrencyServer {
|
||||
private val httpClient = HttpClient {
|
||||
install(ContentNegotiation) {
|
||||
json(
|
||||
Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
)
|
||||
}
|
||||
defaultRequest {
|
||||
contentType(ContentType.Application.Json)
|
||||
url("https://duckduckgo.com/js/spice/currency/1/")
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun currency(value: String, pair: String): List<CurrencyDto> = httpClient.get("$value/$pair").body()
|
||||
}
|
Loading…
Add table
Reference in a new issue