Skip to content

Commit

Permalink
Update with API spec + upgrade dependencies (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
CheckSanity committed Jun 24, 2024
1 parent a6df33f commit eabace6
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
build/
.kotlin
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
Expand Down
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
```

Expand All @@ -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
Expand All @@ -73,4 +65,4 @@ To run tests

```bash
./gradlew publishToMavenLocal
```
```
29 changes: 13 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -20,7 +20,7 @@ allprojects {


group = "dev.voir"
version = "1.0.3"
version = "1.0.4"

kotlin {
jvm()
Expand All @@ -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"))
}
Expand All @@ -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")
}
}
}
Expand Down Expand Up @@ -94,7 +91,7 @@ publishing {
publications.withType<MavenPublication> {
artifactId = "exchangeit-sdk"
groupId = "dev.voir"
version = "1.0.3"
version = "1.0.4"

artifact(tasks.register("${name}JavadocJar", Jar::class) {
archiveClassifier.set("javadoc")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
32 changes: 27 additions & 5 deletions src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK {
return client.get("v1/currencies/${alias}").bodyOrThrow()
}

override suspend fun getLatestRates(alias: String, forAliases: List<String>?): DataDto<CurrencyLatestRatesDto> {
override suspend fun getLatestRates(
alias: String,
forAliases: List<String>?,
forPopular: Int?
): DataDto<CurrencyLatestRatesDto> {
return client.get("v1/currencies/${alias}/latest") {
parameter("for", forAliases)
parameter("forPopular", forPopular)
}.bodyOrThrow()
}

Expand All @@ -76,41 +81,46 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK {
}.bodyOrThrow()
}


override suspend fun getHistoricalRates(
alias: String,
date: String,
forAliases: List<String>?
forAliases: List<String>?,
forPopular: Int?,
): DataDto<CurrencyRateByDateDto> {
return client.get("v1/currencies/${alias}/historical") {
parameter("date", date)
parameter("for", forAliases)
parameter("forPopular", forPopular)
}.bodyOrThrow()
}

override suspend fun getHistoricalRates(
alias: String,
start: String,
end: String,
forAliases: List<String>?
forAliases: List<String>?,
forPopular: Int?,
): DataDto<CurrencyHistoricalRatesDto> {
return client.get("v1/currencies/${alias}/range") {
parameter("start", start)
parameter("end", end)
parameter("for", forAliases)
parameter("forPopular", forPopular)
}.bodyOrThrow()
}

override suspend fun getMonthlyRates(
alias: String,
start: String,
end: String,
forAliases: List<String>?
forAliases: List<String>?,
forPopular: Int?,
): DataDto<CurrencyMonthlyRatesDto> {
return client.get("v1/currencies/${alias}/monthly") {
parameter("start", start)
parameter("end", end)
parameter("for", forAliases)
parameter("forPopular", forPopular)
}.bodyOrThrow()
}

Expand All @@ -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<ConvertResultDto> {
return client.get("v1/converter") {
parameter("amount", amount)
parameter("from", from)
parameter("to", to)
}.bodyOrThrow()
}

private suspend inline fun <reified T> HttpResponse.bodyOrThrow(): T {
return if (status == HttpStatusCode.OK) {
body()
Expand Down
24 changes: 19 additions & 5 deletions src/commonMain/kotlin/dev/voir/exchangeit/sdk/IExchangeItSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<CurrencyDto>
suspend fun getCurrencies(
crypto: Boolean? = null,
search: String? = null,
withObsolete: Boolean? = null,
withNoRates: Boolean? = null
): ListDto<CurrencyDto>

suspend fun getCurrencyDetailed(alias: String): DataDto<CurrencyDetailedDto>

suspend fun getLatestRates(alias: String, forAliases: List<String>? = null): DataDto<CurrencyLatestRatesDto>
suspend fun getLatestRates(
alias: String,
forAliases: List<String>? = null,
forPopular: Int? = null
): DataDto<CurrencyLatestRatesDto>

suspend fun getLatestRates(aliases: List<String>): DataDto<RatesDto>

suspend fun getHistoricalRates(
alias: String,
date: String,
forAliases: List<String>? = null
forAliases: List<String>? = null,
forPopular: Int? = null
): DataDto<CurrencyRateByDateDto>

suspend fun getHistoricalRates(
alias: String,
start: String,
end: String,
forAliases: List<String>? = null
forAliases: List<String>? = null,
forPopular: Int? = null
): DataDto<CurrencyHistoricalRatesDto>

suspend fun getMonthlyRates(
alias: String,
start: String,
end: String,
forAliases: List<String>? = null
forAliases: List<String>? = null,
forPopular: Int? = null
): DataDto<CurrencyMonthlyRatesDto>

suspend fun getSources(): ListDto<SourceDto>

suspend fun getSource(alias: String): DataDto<SourceDto>

suspend fun convert(amount: Double, from: String, to: String): DataDto<ConvertResultDto>
}
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
val centralBanks: List<CentralBankDto>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit eabace6

Please sign in to comment.