Skip to content

Commit

Permalink
Update SDK with latest API spec (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
CheckSanity authored May 16, 2024
1 parent 6e71978 commit a6df33f
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 80 deletions.
26 changes: 13 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -20,7 +20,7 @@ allprojects {


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

kotlin {
jvm()
Expand All @@ -31,24 +31,24 @@ 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")
}

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

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.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
71 changes: 41 additions & 30 deletions src/commonMain/kotlin/dev/voir/exchangeit/sdk/ExchangeItSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK {
prettyPrint = true
})
}
/*
install(Logging) {
logger = Logger.DEFAULT
}
*/
}.apply {
sendPipeline.intercept(HttpSendPipeline.Before) {
try {
Expand All @@ -51,66 +46,82 @@ class ExchangeItSDK(engine: HttpClientEngine) : IExchangeItSDK {
}
}

override suspend fun getCurrencies(crypto: Boolean?, search: String?): ListDto<CurrencyDto> {
return client.get("currencies") {
override suspend fun getCurrencies(
crypto: Boolean?,
search: String?,
withObsolete: Boolean?,
withNoRates: Boolean?
): ListDto<CurrencyDto> {
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<CurrencyDetailedDto> {
return client.get("currencies/${base}").bodyOrThrow()
override suspend fun getCurrencyDetailed(alias: String): DataDto<CurrencyDetailedDto> {
return client.get("v1/currencies/${alias}").bodyOrThrow()
}

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

override suspend fun getLatestRates(base: String, codes: List<String>?): DataDto<CurrencyWithLatestRatesDto> {
return client.get("currencies/${base}/latest") {
parameter("codes", codes)
override suspend fun getLatestRates(aliases: List<String>): DataDto<RatesDto> {
return client.get("v1/rates/latest") {
parameter("aliases", aliases.joinToString(","))
}.bodyOrThrow()
}

override suspend fun getDailyRates(
base: String,
date: String?,
codes: List<String>?
): DataDto<CurrencyWithRatesDto> {
return client.get("currencies/${base}/daily") {

override suspend fun getHistoricalRates(
alias: String,
date: String,
forAliases: List<String>?
): DataDto<CurrencyRateByDateDto> {
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<String>?
forAliases: List<String>?
): DataDto<CurrencyHistoricalRatesDto> {
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<String>?
forAliases: List<String>?
): DataDto<CurrencyMonthlyRatesDto> {
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<SourceDto> {
return client.get("v1/sources") { }.bodyOrThrow()
}

override suspend fun getSource(alias: String): DataDto<SourceDto> {
return client.get("v1/sources/${alias}") { }.bodyOrThrow()
}

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

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

suspend fun getLatestRates(codes: List<String>): ListDto<CurrencyWithLatestRatesDto>
suspend fun getLatestRates(alias: String, forAliases: List<String>? = null): DataDto<CurrencyLatestRatesDto>

suspend fun getLatestRates(base: String, codes: List<String>? = null): DataDto<CurrencyWithLatestRatesDto>
suspend fun getLatestRates(aliases: List<String>): DataDto<RatesDto>

suspend fun getDailyRates(
base: String,
date: String? = null,
codes: List<String>? = null
): DataDto<CurrencyWithRatesDto>
suspend fun getHistoricalRates(
alias: String,
date: String,
forAliases: List<String>? = null
): DataDto<CurrencyRateByDateDto>

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

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

suspend fun getSources(): ListDto<SourceDto>

suspend fun getSource(alias: String): DataDto<SourceDto>
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
val localizedDescription: Map<String, 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: 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<String, String>,
val centralBanks: List<CentralBankDto>
)
15 changes: 13 additions & 2 deletions src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/CurrencyDto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable
@Serializable
data class CurrencyHistoricalRateDto(
val date: String,
val rates: List<CurrencyRateDto>
val rates: List<SimpleCurrencyRateDto>
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CurrencyRateWithDateDto>
val rates: List<CurrencyLatestRateDto>
)

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable
@Serializable
data class CurrencyMonthRateDto(
val month: String,
val rates: List<CurrencyRateDto>
val rates: List<SimpleCurrencyRateDto>
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SimpleCurrencyRateDto>
)
8 changes: 8 additions & 0 deletions src/commonMain/kotlin/dev/voir/exchangeit/sdk/dto/RatesDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.voir.exchangeit.sdk.dto

import kotlinx.serialization.Serializable

@Serializable
data class RatesDto(
val rates: Map<String, List<CurrencyLatestRateDto>>
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Loading

0 comments on commit a6df33f

Please sign in to comment.