diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index e59b2f0..87db2ec 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 + uses: gradle/wrapper-validation-action@v3 - name: Import GPG key uses: crazy-max/ghaction-import-gpg@v6 @@ -24,13 +24,13 @@ jobs: PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'corretto' java-version: '17' - name: Gradle publish - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v3 with: arguments: | publishAllPublicationsToSonatypeRepository diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index eb5b9ce..ce8be6d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,9 +10,9 @@ jobs: name: Run tests runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | ~/.gradle/caches @@ -21,7 +21,7 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: 'corretto' java-version: '17' @@ -31,7 +31,7 @@ jobs: ./gradlew check - name: Archive test report - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Test report path: build/reports/tests/test diff --git a/.gitignore b/.gitignore index 866d95a..7358a0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .gradle build/ +.kotlin !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ diff --git a/README.md b/README.md index c7f7740..b8757ab 100644 --- a/README.md +++ b/README.md @@ -7,28 +7,20 @@ currency. *No authorization needed.* Rates are collected from several *FREE* sources and provided as it is. -Right now Exchange It API is in *alpha* so use with caution. +Right now Exchange It API is in *beta* so use with caution. ## Installation -To use the package inside your application, just add the GitHub repository to your repository list. - -> Add the credentials section if the repository isn't public - ```kotlin allprojects { repositories { google() mavenCentral() - maven { - name = "Github Packages" - url = uri("https://maven.pkg.github.com/voirdev/exchangeit-kmm-sdk") - } } } dependencies { - implementation("dev.voir:exchangeit-sdk:1.0.1") + implementation("dev.voir:exchangeit-sdk:1.0.4") } ``` @@ -47,15 +39,15 @@ val sdk = ExchangeItSDKFactory.create() ```kotlin sdk.getCurrencies() // Return list of currencies sdk.getCurrencies(crypto = true) // Return list of cryptos -sdk.getLatestRates(base = "USD") // Return latest rates for base currency code, additionally you can limit returned rates by codes parameter -sdk.getDailyRates(base = "USD", date = "2002-10-04") // Return rates for base currency on provided date +sdk.getLatestRates(alias = "USD") // Return latest rates for base currency code, additionally you can limit returned rates by codes parameter +sdk.getDailyRates(alias = "USD", date = "2002-10-04") // Return rates for base currency on provided date sdk.getHistoricalRates( - base = "USD", + alias = "USD", start = "2002-10-04", end = "2002-10-10" ) // Return rates for base currency in provided range (not more than 365 days) sdk.getMonthlyRates( - base = "USD", + alias = "USD", start = "2002-10", end = "2005-10" ) // Return average monthly rates for base currency in provided range @@ -73,4 +65,4 @@ To run tests ```bash ./gradlew publishToMavenLocal -``` \ No newline at end of file +``` diff --git a/build.gradle.kts b/build.gradle.kts index e29ae37..026abd2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - kotlin("multiplatform") version "1.9.23" - kotlin("plugin.serialization") version "1.9.23" + kotlin("multiplatform") version "2.0.0" + kotlin("plugin.serialization") version "2.0.0" id("maven-publish") id("signing") } @@ -20,7 +20,7 @@ allprojects { group = "dev.voir" -version = "1.0.3" +version = "1.0.4" kotlin { jvm() @@ -31,24 +31,21 @@ kotlin { sourceSets { commonMain.dependencies { // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1") // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-json - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - 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") + implementation("io.ktor:ktor-client-core:2.3.12") + implementation("io.ktor:ktor-client-content-negotiation:2.3.12") + implementation("io.ktor:ktor-client-serialization:2.3.12") + implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.12") } commonTest.dependencies { // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-test - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.0") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1") implementation(kotlin("test")) } @@ -57,12 +54,12 @@ kotlin { implementation(kotlin("stdlib-jdk8")) // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - implementation("io.ktor:ktor-client-okhttp:2.3.11") + implementation("io.ktor:ktor-client-okhttp:2.3.12") } iosMain.dependencies { // https://mvnrepository.com/artifact/io.ktor/ktor-client-core - implementation("io.ktor:ktor-client-darwin:2.3.11") + implementation("io.ktor:ktor-client-darwin:2.3.12") } } } @@ -94,7 +91,7 @@ publishing { publications.withType { artifactId = "exchangeit-sdk" groupId = "dev.voir" - version = "1.0.3" + version = "1.0.4" 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 48c0a02..0d18421 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.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-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 47a9447..e78d567 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt @@ -64,9 +64,14 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { return client.get("v1/currencies/${alias}").bodyOrThrow() } - override suspend fun getLatestRates(alias: String, forAliases: List?): DataDto { + override suspend fun getLatestRates( + alias: String, + forAliases: List?, + forPopular: Int? + ): DataDto { return client.get("v1/currencies/${alias}/latest") { parameter("for", forAliases) + parameter("forPopular", forPopular) }.bodyOrThrow() } @@ -76,15 +81,16 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { }.bodyOrThrow() } - override suspend fun getHistoricalRates( alias: String, date: String, - forAliases: List? + forAliases: List?, + forPopular: Int?, ): DataDto { return client.get("v1/currencies/${alias}/historical") { parameter("date", date) parameter("for", forAliases) + parameter("forPopular", forPopular) }.bodyOrThrow() } @@ -92,12 +98,14 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { alias: String, start: String, end: String, - forAliases: List? + forAliases: List?, + forPopular: Int?, ): DataDto { return client.get("v1/currencies/${alias}/range") { parameter("start", start) parameter("end", end) parameter("for", forAliases) + parameter("forPopular", forPopular) }.bodyOrThrow() } @@ -105,12 +113,14 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { alias: String, start: String, end: String, - forAliases: List? + forAliases: List?, + forPopular: Int?, ): DataDto { return client.get("v1/currencies/${alias}/monthly") { parameter("start", start) parameter("end", end) parameter("for", forAliases) + parameter("forPopular", forPopular) }.bodyOrThrow() } @@ -122,6 +132,18 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK { return client.get("v1/sources/${alias}") { }.bodyOrThrow() } + override suspend fun convert( + amount: Double, + from: String, + to: String + ): DataDto { + return client.get("v1/converter") { + parameter("amount", amount) + parameter("from", from) + parameter("to", to) + }.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 2b65371..b8bf712 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt @@ -3,35 +3,49 @@ package dev.voir.exchangeit.sdk import dev.voir.exchangeit.sdk.dto.* interface IExchangeItSDK { - suspend fun getCurrencies(crypto: Boolean? = null, search: String? = null, withObsolete: Boolean? = null, withNoRates: Boolean? = null): ListDto + suspend fun getCurrencies( + crypto: Boolean? = null, + search: String? = null, + withObsolete: Boolean? = null, + withNoRates: Boolean? = null + ): ListDto suspend fun getCurrencyDetailed(alias: String): DataDto - suspend fun getLatestRates(alias: String, forAliases: List? = null): DataDto + suspend fun getLatestRates( + alias: String, + forAliases: List? = null, + forPopular: Int? = null + ): DataDto suspend fun getLatestRates(aliases: List): DataDto suspend fun getHistoricalRates( alias: String, date: String, - forAliases: List? = null + forAliases: List? = null, + forPopular: Int? = null ): DataDto suspend fun getHistoricalRates( alias: String, start: String, end: String, - forAliases: List? = null + forAliases: List? = null, + forPopular: Int? = null ): DataDto suspend fun getMonthlyRates( alias: String, start: String, end: String, - forAliases: List? = null + forAliases: List? = null, + forPopular: Int? = null ): DataDto suspend fun getSources(): ListDto suspend fun getSource(alias: String): DataDto + + suspend fun convert(amount: Double, from: String, to: String): DataDto } diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/ConvertResultDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/ConvertResultDto.kt new file mode 100644 index 0000000..001984a --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/ConvertResultDto.kt @@ -0,0 +1,13 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class ConvertResultDto( + val from: SimpleCurrencyDto, + val to: SimpleCurrencyDto, + val amount: Double, + val result: Double, + val rate: Double, + val reverseRate: Double, +) 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 c80615e..ebc01c6 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDetailedDto.kt @@ -17,6 +17,8 @@ data class CurrencyDetailedDto( val popular: Boolean, val rating: Int? = null, val hasRates: Boolean, + val flag: CurrencyFlagDto? = null, + val logo: CurrencyImageDto? = null, 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 4269b29..d0b2cab 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt @@ -17,4 +17,6 @@ data class CurrencyDto( val popular: Boolean, val rating: Int? = null, val hasRates: Boolean, + val flag: CurrencyFlagDto? = null, + val logo: CurrencyImageDto? = null, ) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyFlagDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyFlagDto.kt new file mode 100644 index 0000000..b20ba51 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyFlagDto.kt @@ -0,0 +1,9 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class CurrencyFlagDto( + val default: CurrencyImageDto? = null, + val square: CurrencyImageDto? = null, +) 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 3a44ea6..6a2fcb0 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyHistoricalRatesDto.kt @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyHistoricalRatesDto( val alias: String, + val code: String? = null, val title: String, val start: String, val end: String, diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyImageDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyImageDto.kt new file mode 100644 index 0000000..95fc147 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyImageDto.kt @@ -0,0 +1,31 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class CurrencyImageDto( + @SerialName("16") + val size16: String?, + + @SerialName("32") + val size32: String?, + + @SerialName("64") + val size64: String?, + + @SerialName("128") + val size128: String?, + + @SerialName("256") + val size256: String?, + + @SerialName("512") + val size512: String?, + + @SerialName("1024") + val size1024: String?, + + @SerialName("svg") + val svg: String?, +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt index 8340647..4903307 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRateDto.kt @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyLatestRateDto( val alias: String, + val code: String? = null, val rate: Double, val date: String, val fluctuation: Double diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt index 7d26651..d342cd3 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyLatestRatesDto.kt @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyLatestRatesDto( val alias: String, + val code: String? = null, val title: String, 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 f6b522b..baa2c9a 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyMonthlyRatesDto.kt @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable @Serializable data class CurrencyMonthlyRatesDto( val alias: String, + val code: String? = null, 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 index 5aafcf8..f0f4021 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyRateByDateDto.kt @@ -1,7 +1,11 @@ package dev.voir.exchangeit.sdk.dto +import kotlinx.serialization.Serializable + +@Serializable data class CurrencyRateByDateDto( val alias: String, + val code: String? = null, val title: String, val date: String, val rates: List diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyDto.kt new file mode 100644 index 0000000..ce81028 --- /dev/null +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyDto.kt @@ -0,0 +1,10 @@ +package dev.voir.exchangeit.sdk.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class SimpleCurrencyDto( + val alias: String, + val code: String? = null, + val title: String, +) diff --git a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt index 9b4b055..eb7a87a 100644 --- a/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt +++ b/src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/SimpleCurrencyRateDto.kt @@ -5,5 +5,6 @@ import kotlinx.serialization.Serializable @Serializable data class SimpleCurrencyRateDto( val alias: String, + val code: String? = null, val rate: Double ) diff --git a/src/commonTest/kotlin/dev/voir/exchangeit/sdk/AnyExchangeSDKTests.kt b/src/commonTest/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDKTests.kt similarity index 100% rename from src/commonTest/kotlin/dev/voir/exchangeit/sdk/AnyExchangeSDKTests.kt rename to src/commonTest/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDKTests.kt