Skip to content

Commit

Permalink
Update with API and upgrade dependencies (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
CheckSanity authored Feb 5, 2024
1 parent 6dd72db commit 6e71978
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 63 deletions.
24 changes: 14 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("multiplatform") version "1.9.21"
kotlin("plugin.serialization") version "1.9.21"
kotlin("multiplatform") version "1.9.22"
kotlin("plugin.serialization") version "1.9.22"
id("maven-publish")
id("signing")
}
Expand All @@ -20,7 +20,7 @@ allprojects {


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

kotlin {
jvm()
Expand All @@ -37,11 +37,15 @@ kotlin {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")

// https://mvnrepository.com/artifact/io.ktor/ktor-client-core
implementation("io.ktor:ktor-client-core:2.3.7")
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
implementation("io.ktor:ktor-client-serialization:2.3.7")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
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-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")
Expand All @@ -53,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.7")
implementation("io.ktor:ktor-client-okhttp:2.3.8")
}

iosMain.dependencies {
// https://mvnrepository.com/artifact/io.ktor/ktor-client-core
implementation("io.ktor:ktor-client-darwin:2.3.7")
implementation("io.ktor:ktor-client-darwin:2.3.8")
}
}
}
Expand Down Expand Up @@ -90,7 +94,7 @@ publishing {
publications.withType<MavenPublication> {
artifactId = "exchangeit-sdk"
groupId = "dev.voir"
version = "1.0.1"
version = "1.0.2"

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

override suspend fun getCurrencies(crypto: Boolean?): DataArrayDto<CurrencyDto> {
override suspend fun getCurrencies(crypto: Boolean?, search: String?): ListDto<CurrencyDto> {
return client.get("currencies") {
parameter("crypto", crypto)
parameter("search", search)
}.bodyOrThrow()
}

override suspend fun getCurrencyDetailed(base: String): DataDto<CurrencyDetailedDto> {
return client.get("currencies/${base}").bodyOrThrow()
}

override suspend fun getLatestRates(codes: List<String>): ListDto<CurrencyWithLatestRatesDto> {
return client.get("rates/latest") {
parameter("codes", codes.joinToString(","))
}.bodyOrThrow()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package dev.voir.exchangeit.sdk
import dev.voir.exchangeit.sdk.dto.*

interface IExchangeItSDK {
suspend fun getCurrencies(crypto: Boolean? = null): DataArrayDto<CurrencyDto>
suspend fun getCurrencies(crypto: Boolean? = null, search: String? = null): ListDto<CurrencyDto>

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

suspend fun getLatestRates(codes: List<String>): ListDto<CurrencyWithLatestRatesDto>

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.voir.exchangeit.sdk.dto

import kotlinx.serialization.Serializable

@Serializable
data class CurrencyDetailedDto(
val code: String,
val title: String,
val description: String? = null,
val localizedTitle: Map<String, String>,
val localizedDescription: Map<String, String>,
val crypto: Boolean,
val symbol: String? = null,
val year: String? = null,
val url: String? = null,
)
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 DataArrayDto<T>(
data class ListDto<T>(
val meta: ListMetaDto,
val data: List<T>
)
113 changes: 64 additions & 49 deletions src/commonTest/kotlin/dev/voir/exchangeit/sdk/AnyExchangeSDKTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,80 @@ class ExchangeItSDKTests {

// TODO Disable testing for now, since iosX64 tests could not be passed
// https://youtrack.jetbrains.com/issue/KTOR-5158/Darwin-certificate-is-invalid-error-when-making-requests-through-HTTPS-in-tests
/* @Test
fun `test get currencies`() = runApiTest {
val currencies = sdk.getCurrencies(crypto = null)
val crypto = sdk.getCurrencies(crypto = true)
/*@Test
fun `test get currencies`() = runApiTest {
val currencies = sdk.getCurrencies(crypto = null)
val crypto = sdk.getCurrencies(crypto = true)
assertEquals(true, currencies.meta.total > 0)
assertEquals(true, currencies.data.isNotEmpty())
assertEquals(true, currencies.meta.total > 0)
assertEquals(true, currencies.data.isNotEmpty())
assertEquals(true, crypto.meta.total > 0)
assertEquals(true, crypto.data.isNotEmpty())
assertEquals(true, crypto.meta.total > 0)
assertEquals(true, crypto.data.isNotEmpty())
assertEquals(true, currencies.data.first().code != crypto.data.first().code)
}
assertEquals(true, currencies.data.first().code != crypto.data.first().code)
}
@Test
fun `test get latest rates`() = runApiTest {
val latestRates = sdk.getLatestRates(base = "rub", codes = null)
@Test
fun `test get currency detailed`() = runApiTest {
val currency = sdk.getCurrencyDetailed(base = "usd")
assertEquals("usd", currency.data.code)
assertEquals("United States Dollar", currency.data.title)
assertEquals("Доллар США", currency.data.localizedTitle["ru"])
assertEquals("rub", latestRates.data.code)
assertEquals(true, latestRates.data.rates.isNotEmpty())
}
val notFound = kotlin.runCatching { sdk.getCurrencyDetailed(base = "usdusdusd") }
assertEquals(true, notFound.isFailure)
assertEquals("ExchangeItSDKError(code=404, message=Not Found)", notFound.exceptionOrNull()?.message)
}
@Test
fun `test get daily rates`() = runApiTest {
val dailyRates = sdk.getDailyRates(base = "rub", date = "2002-10-10", codes = null)
@Test
fun `test get latest rates`() = runApiTest {
val latestRates = sdk.getLatestRates(base = "rub", codes = null)
assertEquals("rub", dailyRates.data.code)
assertEquals("2002-10-10", dailyRates.data.date)
assertEquals(true, dailyRates.data.rates.isNotEmpty())
}
assertEquals("rub", latestRates.data.code)
assertEquals(true, latestRates.data.rates.isNotEmpty())
@Test
fun `test get historical rates`() = runApiTest {
val historicalRates =
sdk.getHistoricalRates(base = "rub", start = "2002-10-10", end = "2002-10-14", codes = null)
val latestRatesByCodes = sdk.getLatestRates(codes = listOf("rub", "aed", "usd"))
assertEquals(3, latestRatesByCodes.data.size)
}
assertEquals("rub", historicalRates.data.code)
assertEquals("2002-10-10", historicalRates.data.start)
assertEquals("2002-10-14", historicalRates.data.end)
assertEquals("2002-10-10", historicalRates.data.historical.first().date)
assertEquals("2002-10-14", historicalRates.data.historical.last().date)
}
@Test
fun `test get daily rates`() = runApiTest {
val dailyRates = sdk.getDailyRates(base = "rub", date = "2002-10-10", codes = null)
@Test
fun `test get monthly rates`() = runApiTest {
val historicalRates =
sdk.getMonthlyRates(base = "rub", start = "2002-10-10", end = "2003-10-14", codes = null)
assertEquals("rub", dailyRates.data.code)
assertEquals("2002-10-10", dailyRates.data.date)
assertEquals(true, dailyRates.data.rates.isNotEmpty())
}
assertEquals("rub", historicalRates.data.code)
assertEquals("2002-10", historicalRates.data.start)
assertEquals("2003-10", historicalRates.data.end)
assertEquals("2002-10", historicalRates.data.monthly.first().month)
assertEquals("2003-10", historicalRates.data.monthly.last().month)
}
@Test
fun `test get historical rates`() = runApiTest {
val historicalRates =
sdk.getHistoricalRates(base = "rub", start = "2002-10-10", end = "2002-10-14", codes = null)
assertEquals("rub", historicalRates.data.code)
assertEquals("2002-10-10", historicalRates.data.start)
assertEquals("2002-10-14", historicalRates.data.end)
assertEquals("2002-10-10", historicalRates.data.historical.first().date)
assertEquals("2002-10-14", historicalRates.data.historical.last().date)
}
@Test
fun `test get monthly rates`() = runApiTest {
val historicalRates =
sdk.getMonthlyRates(base = "rub", start = "2002-10-10", end = "2003-10-14", codes = null)
assertEquals("rub", historicalRates.data.code)
assertEquals("2002-10", historicalRates.data.start)
assertEquals("2003-10", historicalRates.data.end)
assertEquals("2002-10", historicalRates.data.monthly.first().month)
assertEquals("2003-10", historicalRates.data.monthly.last().month)
}
private fun runApiTest(
testBody: suspend TestScope.(await: suspend () -> Unit) -> Unit,
) = runTest(timeout = 30.seconds) {
testLock.withLock { }
testBody { testLock.withLock { } }
}*/
private fun runApiTest(
testBody: suspend TestScope.(await: suspend () -> Unit) -> Unit,
) = runTest(timeout = 30.seconds) {
testLock.withLock { }
testBody { testLock.withLock { } }
}*/
}

0 comments on commit 6e71978

Please sign in to comment.