diff --git a/.gitignore b/.gitignore index 0742f86..13a066e 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ dist/ ehthumbs.db fabric.properties gen/ +gradle.properties hs_err_pid* kobaltBuild kobaltw*-test diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index f8467b4..0fc3113 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3d0bb47..323152a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/README.md b/README.md index 737e4c1..fa4942b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause) -[![Kotlin](https://img.shields.io/badge/kotlin-1.8-7f52ff)](https://kotlinlang.org/) +[![Kotlin](https://img.shields.io/badge/kotlin-1.8.2222-7f52ff)](https://kotlinlang.org/) [![Nexus Snapshot](https://img.shields.io/nexus/s/net.thauvin.erik/cryptoprice?label=snapshot&server=https%3A%2F%2Foss.sonatype.org%2F)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/) [![Release](https://img.shields.io/github/release/ethauvin/cryptoprice.svg)](https://github.com/ethauvin/cryptoprice/releases/latest) -[![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik/cryptoprice)](https://central.sonatype.com/artifact/net.thauvin.erik/cryptoprice) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/cryptoprice/badge.svg?color=blue)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/cryptoprice) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_cryptoprice&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice) [![GitHub CI](https://github.com/ethauvin/cryptoprice/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/cryptoprice/actions/workflows/gradle.yml) diff --git a/build.gradle.kts b/build.gradle.kts index 51e2407..9f612e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,15 +7,15 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { id("application") - id("com.github.ben-manes.versions") version "0.48.0" - id("io.gitlab.arturbosch.detekt") version "1.23.1" + id("com.github.ben-manes.versions") version "0.47.0" + id("io.gitlab.arturbosch.detekt") version "1.23.0" id("java") id("maven-publish") - id("org.jetbrains.dokka") version "1.9.0" - id("org.jetbrains.kotlinx.kover") version "0.7.3" - id("org.sonarqube") version "4.3.1.3277" + id("org.jetbrains.dokka") version "1.8.20" + id("org.jetbrains.kotlinx.kover") version "0.7.2" + id("org.sonarqube") version "4.2.1.3168" id("signing") - kotlin("jvm") version "1.9.10" + kotlin("jvm") version "1.8.22" } defaultTasks(ApplicationPlugin.TASK_RUN_NAME) @@ -49,7 +49,7 @@ dependencies { implementation("org.json:json:20230618") testImplementation(kotlin("test")) - testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.27.0") + testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.26.1") } application { diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 8dc24d4..d055a8e 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -2,7 +2,6 @@ - NestedBlockDepth:CryptoPrice.kt$CryptoPrice.Companion$@JvmStatic @JvmOverloads @Throws(CryptoException::class, IOException::class) fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String ThrowsCount:CryptoPrice.kt$CryptoPrice.Companion$@JvmStatic @JvmOverloads @Throws(CryptoException::class, IOException::class) fun apiCall(paths: List<String>, params: Map<String, String> = emptyMap()): String diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index bc160d1..3dff3ec 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("application") - id("com.github.ben-manes.versions") version "0.48.0" - kotlin("jvm") version "1.9.10" + id("com.github.ben-manes.versions") version "0.47.0" + kotlin("jvm") version "1.8.10" } // ./gradlew run @@ -21,7 +21,7 @@ repositories { dependencies { implementation("net.thauvin.erik:cryptoprice:1.0.1-SNAPSHOT") - implementation("org.json:json:20230618") + implementation("org.json:json:20230227") } java { diff --git a/examples/gradle/wrapper/gradle-wrapper.jar b/examples/gradle/wrapper/gradle-wrapper.jar index 7f93135..c1962a7 100644 Binary files a/examples/gradle/wrapper/gradle-wrapper.jar and b/examples/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties index ac72c34..37aef8d 100644 --- a/examples/gradle/wrapper/gradle-wrapper.properties +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 -validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/gradlew b/examples/gradlew index 0adc8e1..aeb74cb 100755 --- a/examples/gradlew +++ b/examples/gradlew @@ -83,8 +83,7 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -131,13 +130,10 @@ location of your Java installation." fi else JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index e69de29..0000000 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ac72c34..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 -validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 0adc8e1..aeb74cb 100755 --- a/gradlew +++ b/gradlew @@ -83,8 +83,7 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -131,13 +130,10 @@ location of your Java installation." fi else JAVACMD=java - if ! command -v java >/dev/null 2>&1 - then - die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." - fi fi # Increase the maximum file descriptors if we can. diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt index 6cfdfcd..7db00db 100644 --- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt +++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt @@ -110,16 +110,11 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe if (response.isSuccessful) { return body } else { - if (json.has("errors")) { - val data = json.getJSONArray("errors") - throw CryptoException( - response.code, data.getJSONObject(0).getString("id"), - data.getJSONObject(0).getString("message") - ) - } else { - throw CryptoException(response.code, json.getString("error"), - json.getString("message")) - } + val data = json.getJSONArray("errors") + throw CryptoException( + response.code, data.getJSONObject(0).getString("id"), + data.getJSONObject(0).getString("message") + ) } } catch (e: JSONException) { throw CryptoException(response.code, id = "parse_error", "Could not parse data.", e) diff --git a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt index 1ac50e5..dbb8eba 100644 --- a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt +++ b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt @@ -33,8 +33,10 @@ package net.thauvin.erik.crypto import assertk.all import assertk.assertThat +import assertk.assertions.contains import assertk.assertions.isEqualTo import assertk.assertions.isGreaterThan +import assertk.assertions.isNotNull import assertk.assertions.prop import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall import net.thauvin.erik.crypto.CryptoPrice.Companion.buyPrice @@ -124,7 +126,20 @@ class CryptoPriceTest { @Test @Throws(CryptoException::class) - fun testNotFound() { + fun testPrices() { + assertFailsWith( + message = "spotPrice(FOO)", + exceptionClass = CryptoException::class, + block = { spotPrice("FOO") } + ) + + try { + spotPrice("BAR") + } catch (e: CryptoException) { + assertThat(e.id, "spotPrice(bar) error id").isEqualTo("not_found") + assertThat(e.message, "spotPrice(bar) error message").isEqualTo("Invalid base currency") + } + assertFailsWith( message = "buyPrice(BTC,BAR)", exceptionClass = CryptoException::class, @@ -136,8 +151,7 @@ class CryptoPriceTest { } catch (e: CryptoException) { assertThat(e, "sellPrice(FOOBAR)").all { prop(CryptoException::statusCode).isEqualTo(404) - prop(CryptoException::message).isEqualTo("not found") - prop(CryptoException::id).isEqualTo("not found") + prop(CryptoException::message).isNotNull().contains("invalid", true) } } }