From a6df33f2a7931ed251b64f2165a62989215c04eb Mon Sep 17 00:00:00 2001 From: Gary Bezruchko Date: Thu, 16 May 2024 18:07:16 +0200 Subject: [PATCH] Update SDK with latest API spec (#8) --- build.gradle.kts | 26 +++---- gradle/wrapper/gradle-wrapper.properties | 2 +- .../dev/voir/exchangeit/sdk/ExchangeItSDK.kt | 71 +++++++++++-------- .../dev/voir/exchangeit/sdk/IExchangeItSDK.kt | 30 ++++---- .../voir/exchangeit/sdk/dto/CentralBankDto.kt | 10 +++ .../exchangeit/sdk/dto/CurrencyDetailedDto.kt | 17 +++-- .../voir/exchangeit/sdk/dto/CurrencyDto.kt | 15 +++- .../sdk/dto/CurrencyHistoricalRateDto.kt | 2 +- .../sdk/dto/CurrencyHistoricalRatesDto.kt | 2 +- ...ithDateDto.kt => CurrencyLatestRateDto.kt} | 4 +- ...tRatesDto.kt => CurrencyLatestRatesDto.kt} | 7 +- .../sdk/dto/CurrencyMonthRateDto.kt | 2 +- .../sdk/dto/CurrencyMonthlyRatesDto.kt | 2 +- .../sdk/dto/CurrencyRateByDateDto.kt | 8 +++ .../dev/voir/exchangeit/sdk/dto/RatesDto.kt | 8 +++ ...ncyRateDto.kt => SimpleCurrencyRateDto.kt} | 6 +- .../{CurrencyWithRatesDto.kt => SourceDto.kt} | 8 +-- .../voir/exchangeit/sdk/dto/SourceTypeDto.kt | 24 +++++++ 18 files changed, 164 insertions(+), 80 deletions(-) create mode 100644 src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CentralBankDto.kt rename src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/{CurrencyRateWithDateDto.kt => CurrencyLatestRateDto.kt} (74%) rename src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/{CurrencyWithLatestRatesDto.kt => CurrencyLatestRatesDto.kt} (52%) create mode 100644 src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt create mode 100644 src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/RatesDto.kt rename src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/{CurrencyRateDto.kt => SimpleCurrencyRateDto.kt} (66%) rename src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/{CurrencyWithRatesDto.kt => SourceDto.kt} (51%) create mode 100644 src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceTypeDto.kt diff --git a/build.gradle.kts b/build.gradle.kts index 0c18621..e29ae37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - kotlin("multiplatform") version "1.9.22" - kotlin("plugin.serialization") version "1.9.22" + kotlin("multiplatform") version "1.9.23" + kotlin("plugin.serialization") version "1.9.23" id("maven-publish") id("signing") } @@ -20,7 +20,7 @@ allprojects { group = "dev.voir" -version = "1.0.2" +version = "1.0.3" kotlin { jvm() @@ -31,16 +31,16 @@ kotlin { sourceSets { commonMain.dependencies { // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-json - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - implementation("io.ktor:ktor-client-core:2.3.8") - implementation("io.ktor:ktor-client-content-negotiation:2.3.8") - implementation("io.ktor:ktor-client-serialization:2.3.8") - implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.8") + implementation("io.ktor:ktor-client-core:2.3.11") + implementation("io.ktor:ktor-client-content-negotiation:2.3.11") + implementation("io.ktor:ktor-client-serialization:2.3.11") + implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.11") //implementation("io.ktor:ktor-client-logging:2.3.8") //implementation("ch.qos.logback:logback-classic:1.4.14") @@ -48,7 +48,7 @@ kotlin { commonTest.dependencies { // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-test - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0") implementation(kotlin("test")) } @@ -57,12 +57,12 @@ kotlin { implementation(kotlin("stdlib-jdk8")) // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - implementation("io.ktor:ktor-client-okhttp:2.3.8") + implementation("io.ktor:ktor-client-okhttp:2.3.11") } iosMain.dependencies { // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - implementation("io.ktor:ktor-client-darwin:2.3.8") + implementation("io.ktor:ktor-client-darwin:2.3.11") } } } @@ -94,7 +94,7 @@ publishing { publications.withType { artifactId = "exchangeit-sdk" groupId = "dev.voir" - version = "1.0.2" + version = "1.0.3" artifact(tasks.register("${name}JavadocJar", Jar::class) { archiveClassifier.set("javadoc") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 17655d0..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt index a56b351..47a9447 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt @@ -36,11 +36,6 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { prettyPrint = true }) } - /* - install(Logging) { - logger = Logger.DEFAULT - } - */ }.apply { sendPipeline.intercept(HttpSendPipeline.Before) { try { @@ -51,66 +46,82 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { } } - override suspend fun getCurrencies(crypto: Boolean?, search: String?): ListDto { - return client.get("currencies") { + override suspend fun getCurrencies( + crypto: Boolean?, + search: String?, + withObsolete: Boolean?, + withNoRates: Boolean? + ): ListDto { + return client.get("v1/currencies") { parameter("crypto", crypto) parameter("search", search) + parameter("withObsolete", withObsolete) + parameter("withNoRates", withNoRates) }.bodyOrThrow() } - override suspend fun getCurrencyDetailed(base: String): DataDto { - return client.get("currencies/${base}").bodyOrThrow() + override suspend fun getCurrencyDetailed(alias: String): DataDto { + return client.get("v1/currencies/${alias}").bodyOrThrow() } - override suspend fun getLatestRates(codes: List): ListDto { - return client.get("rates/latest") { - parameter("codes", codes.joinToString(",")) + override suspend fun getLatestRates(alias: String, forAliases: List?): DataDto { + return client.get("v1/currencies/${alias}/latest") { + parameter("for", forAliases) }.bodyOrThrow() } - override suspend fun getLatestRates(base: String, codes: List?): DataDto { - return client.get("currencies/${base}/latest") { - parameter("codes", codes) + override suspend fun getLatestRates(aliases: List): DataDto { + return client.get("v1/rates/latest") { + parameter("aliases", aliases.joinToString(",")) }.bodyOrThrow() } - override suspend fun getDailyRates( - base: String, - date: String?, - codes: List? - ): DataDto { - return client.get("currencies/${base}/daily") { + + override suspend fun getHistoricalRates( + alias: String, + date: String, + forAliases: List? + ): DataDto { + return client.get("v1/currencies/${alias}/historical") { parameter("date", date) - parameter("codes", codes) + parameter("for", forAliases) }.bodyOrThrow() } override suspend fun getHistoricalRates( - base: String, + alias: String, start: String, end: String, - codes: List? + forAliases: List? ): DataDto { - return client.get("currencies/${base}/historical") { + return client.get("v1/currencies/${alias}/range") { parameter("start", start) parameter("end", end) - parameter("codes", codes) + parameter("for", forAliases) }.bodyOrThrow() } override suspend fun getMonthlyRates( - base: String, + alias: String, start: String, end: String, - codes: List? + forAliases: List? ): DataDto { - return client.get("currencies/${base}/monthly") { + return client.get("v1/currencies/${alias}/monthly") { parameter("start", start) parameter("end", end) - parameter("codes", codes) + parameter("for", forAliases) }.bodyOrThrow() } + override suspend fun getSources(): ListDto { + return client.get("v1/sources") { }.bodyOrThrow() + } + + override suspend fun getSource(alias: String): DataDto { + return client.get("v1/sources/${alias}") { }.bodyOrThrow() + } + private suspend inline fun HttpResponse.bodyOrThrow(): T { return if (status == HttpStatusCode.OK) { body() diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt index 7a8ce57..2b65371 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt @@ -3,31 +3,35 @@ package dev.voir.exchangeit.sdk import dev.voir.exchangeit.sdk.dto.* interface IExchangeItSDK { - suspend fun getCurrencies(crypto: Boolean? = null, search: String? = null): ListDto + suspend fun getCurrencies(crypto: Boolean? = null, search: String? = null, withObsolete: Boolean? = null, withNoRates: Boolean? = null): ListDto - suspend fun getCurrencyDetailed(base: String): DataDto + suspend fun getCurrencyDetailed(alias: String): DataDto - suspend fun getLatestRates(codes: List): ListDto + suspend fun getLatestRates(alias: String, forAliases: List? = null): DataDto - suspend fun getLatestRates(base: String, codes: List? = null): DataDto + suspend fun getLatestRates(aliases: List): DataDto - suspend fun getDailyRates( - base: String, - date: String? = null, - codes: List? = null - ): DataDto + suspend fun getHistoricalRates( + alias: String, + date: String, + forAliases: List? = null + ): DataDto suspend fun getHistoricalRates( - base: String, + alias: String, start: String, end: String, - codes: List? = null + forAliases: List? = null ): DataDto suspend fun getMonthlyRates( - base: String, + alias: String, start: String, end: String, - codes: List? = null + forAliases: List? = null ): DataDto + + suspend fun getSources(): ListDto + + suspend fun getSource(alias: String): DataDto } diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CentralBankDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CentralBankDto.kt new file mode 100644 index 0000000..6469b4e --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CentralBankDto.kt @@ -0,0 +1,10 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class CentralBankDto( + val alias: String, + val name: String, + val url: String? = null +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt index c1fdd80..c80615e 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt @@ -4,13 +4,20 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyDetailedDto( - val code: String, + val alias: String, val title: String, - val description: String? = null, - val localizedTitle: Map, - val localizedDescription: Map, + val code: String? = null, + val isoNumeric: String? = null, + val titleOrigin: String? = null, val crypto: Boolean, + val obsolete: Boolean, val symbol: String? = null, - val year: String? = null, + val year: Int? = null, val url: String? = null, + val popular: Boolean, + val rating: Int? = null, + val hasRates: Boolean, + val description: String? = null, + val localizedDescription: Map, + val centralBanks: List ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt index 377ea7e..4269b29 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt @@ -4,6 +4,17 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyDto( - val code: String, - val title: String + val alias: String, + val title: String, + val code: String? = null, + val isoNumeric: String? = null, + val titleOrigin: String? = null, + val crypto: Boolean, + val obsolete: Boolean, + val symbol: String? = null, + val year: Int? = null, + val url: String? = null, + val popular: Boolean, + val rating: Int? = null, + val hasRates: Boolean, ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRateDto.kt index 79a8513..fcf4911 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRateDto.kt @@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyHistoricalRateDto( val date: String, - val rates: List + val rates: List ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt index 1eeeaa6..3a44ea6 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyHistoricalRatesDto( - val code: String, + val alias: String, val title: String, val start: String, val end: String, diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateWithDateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt similarity index 74% rename from src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateWithDateDto.kt rename to src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt index 062f4ca..8340647 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateWithDateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt @@ -3,8 +3,8 @@ package dev.voir.exchangeit.sdk.dto import kotlinx.serialization.Serializable @Serializable -data class CurrencyRateWithDateDto( - val code: String, +data class CurrencyLatestRateDto( + val alias: String, val rate: Double, val date: String, val fluctuation: Double diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithLatestRatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt similarity index 52% rename from src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithLatestRatesDto.kt rename to src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt index 24be073..7d26651 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithLatestRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt @@ -3,8 +3,9 @@ package dev.voir.exchangeit.sdk.dto import kotlinx.serialization.Serializable @Serializable -data class CurrencyWithLatestRatesDto( - val code: String, +data class CurrencyLatestRatesDto( + val alias: String, val title: String, - val rates: List + val rates: List ) + diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthRateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthRateDto.kt index 216e5ac..d8d468b 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthRateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthRateDto.kt @@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyMonthRateDto( val month: String, - val rates: List + val rates: List ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt index ad7dbca..f6b522b 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyMonthlyRatesDto( - val code: String, + val alias: String, val title: String, val start: String, val end: String, diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt new file mode 100644 index 0000000..5aafcf8 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt @@ -0,0 +1,8 @@ +package dev.voir.exchangeit.sdk.dto + +data class CurrencyRateByDateDto( + val alias: String, + val title: String, + val date: String, + val rates: List +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/RatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/RatesDto.kt new file mode 100644 index 0000000..87286b3 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/RatesDto.kt @@ -0,0 +1,8 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class RatesDto( + val rates: Map> +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt similarity index 66% rename from src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateDto.kt rename to src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt index 4cf26f0..9b4b055 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt @@ -3,7 +3,7 @@ package dev.voir.exchangeit.sdk.dto import kotlinx.serialization.Serializable @Serializable -data class CurrencyRateDto( - val code: String, +data class SimpleCurrencyRateDto( + val alias: String, val rate: Double -) \ No newline at end of file +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithRatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceDto.kt similarity index 51% rename from src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithRatesDto.kt rename to src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceDto.kt index f977fd1..bebd1fd 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyWithRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceDto.kt @@ -3,9 +3,9 @@ package dev.voir.exchangeit.sdk.dto import kotlinx.serialization.Serializable @Serializable -data class CurrencyWithRatesDto( - val code: String, +data class SourceDto( + val alias: String, val title: String, - val date: String, - val rates: List + val type: SourceTypeDto, + val api: Boolean ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceTypeDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceTypeDto.kt new file mode 100644 index 0000000..1a746a4 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SourceTypeDto.kt @@ -0,0 +1,24 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +enum class SourceTypeDto { + @SerialName("central_bank") + CentralBank, + @SerialName("bank") + Bank, + @SerialName("market") + Market, + @SerialName("crypto_market") + CryptoMarket, + @SerialName("free_source") + FreeSource, + @SerialName("api") + Api, + @SerialName("unknown") + Unknown, + @SerialName("secret") + Secret, +}