-
-
-
\ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
deleted file mode 100644
index a97931a..0000000
--- a/.vscode/launch.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "version": "0.2.0",
- "configurations": [
- {
- "type": "java",
- "name": "Run Tests",
- "request": "launch",
- "mainClass": "net.thauvin.erik.crypto.CryptopriceTest"
- }
- ]
-}
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index 133aa45..0000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "java.project.sourcePaths": [
- "src/main/java",
- "src/main/resources",
- "src/test/java",
- "src/bld/java"
- ],
- "java.configuration.updateBuildConfiguration": "automatic",
- "java.project.referencedLibraries": [
- "${HOME}/.bld/dist/bld-1.7.5.jar",
- "lib/compile/*.jar",
- "lib/runtime/*.jar",
- "lib/test/*.jar"
- ]
-}
diff --git a/LICENSE.txt b/LICENSE.txt
index 194661d..e7f7d47 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
+Copyright 2021-2025 Erik C. Thauvin (erik@thauvin.net)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/README.md b/README.md
index 1c583ed..d36883b 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,6 @@
[](https://opensource.org/licenses/BSD-3-Clause)
-[](https://kotlinlang.org/)
+[](https://kotlinlang.org/)
+[](https://rife2.com/bld)
[](https://github.com/ethauvin/cryptoprice/releases/latest)
[](https://central.sonatype.com/artifact/net.thauvin.erik/cryptoprice)
[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/)
@@ -10,7 +11,7 @@
# Retrieve cryptocurrencies current (buy, sell or spot) prices
-A simple implementation of the prices [Coinbase Public API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
+A simple implementation of the prices [Coinbase Public API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices).
## Examples (TL;DR)
@@ -39,7 +40,7 @@ To use with [bld](https://rife2.com/bld), include the following dependency in yo
repositories = List.of(MAVEN_CENTRAL);
scope(compile)
- .include(dependency("net.thauvin.erik:cryptoprice:1.0.1"));
+ .include(dependency("net.thauvin.erik:cryptoprice:1.0.2"));
```
Be sure to use the [bld Kotlin extension](https://github.com/rife2/bld-kotlin) in your project.
@@ -54,7 +55,7 @@ repositories {
}
dependencies {
- implementation("net.thauvin.erik:cryptoprice:1.0.1")
+ implementation("net.thauvin.erik:cryptoprice:1.0.2")
}
```
@@ -93,7 +94,7 @@ A `CryptoPrice` object is returned defined as follows:
```kotlin
CryptoPrice(val base: String, val currency: String, val amount: BigDecimal)
```
-The parameter names match the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
+The parameter names match the [Coinbase API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices).
#### Format
@@ -122,7 +123,7 @@ println(price.toJson())
{"data":{"base":"BTC","currency":"USD","amount":"34567.89"}}
```
-The `data` object matches the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices). To specify a different (or no) key, use:
+The `data` object matches the [Coinbase API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices). To specify a different (or no) key, use:
```kotlin
println(price.toJson("bitcoin"))
@@ -145,7 +146,7 @@ val eth = """{"ether":{"base":"ETH","currency":"USD","amount":"2345.67"}}""".toP
### Extending
-A generic `apiCall()` function is available to access other [data API endpoints](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies). For example to retrieve the [exchange rates](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates):
+A generic `apiCall()` function is available to access other [data API endpoints](https://docs.cdp.coinbase.com/coinbase-app/docs/api-currencies). For example to retrieve the [exchange rates](https://docs.cdp.coinbase.com/coinbase-app/docs/api-exchange-rates):
```kotlin
apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
@@ -157,3 +158,22 @@ will return something like:
```
See the [examples](https://github.com/ethauvin/cryptoprice/blob/master/examples/) for more details.
+
+## Contributing
+
+If you want to contribute to this project, all you have to do is clone the GitHub
+repository:
+
+```console
+git clone git@github.com:ethauvin/cryptoprice.git
+```
+
+Then use [bld](https://rife2.com/bld) to build:
+
+```console
+cd cryptoprice
+./bld compile
+```
+
+The project has an [IntelliJ IDEA](https://www.jetbrains.com/idea/) project structure. You can just open it after all
+the dependencies were downloaded and peruse the code.
diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml
index 7c85194..ace99d2 100644
--- a/bitbucket-pipelines.yml
+++ b/bitbucket-pipelines.yml
@@ -1,10 +1,20 @@
-image: openjdk:17
+image: ubuntu:latest
pipelines:
default:
- step:
name: Test with bld
script:
+ # Install latest Java & Kotlin via SDKMAN!
+ - apt-get update -qq && apt-get install -y curl zip
+ - curl -s "https://get.sdkman.io" | bash
+ - echo sdkman_auto_answer=true > $HOME/.sdkman/etc/config
+ - echo sdkman_auto_selfupdate=true >> $HOME/.sdkman/etc/config
+ - source "$HOME/.sdkman/bin/sdkman-init.sh"
+ - sdk install java
+ - sdk install kotlin
+ - source "$HOME/.sdkman/bin/sdkman-init.sh"
+ # Download, compile and test with bld
- ./bld download
- ./bld compile
- ./bld test
diff --git a/examples/bld/.idea/bld.xml b/examples/bld/.idea/bld.xml
new file mode 100644
index 0000000..6600cee
--- /dev/null
+++ b/examples/bld/.idea/bld.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/bld/.idea/libraries/bld.xml b/examples/bld/.idea/libraries/bld.xml
index cf75013..af4608e 100644
--- a/examples/bld/.idea/libraries/bld.xml
+++ b/examples/bld/.idea/libraries/bld.xml
@@ -2,11 +2,11 @@
-
+
-
+
diff --git a/examples/bld/.idea/libraries/compile.xml b/examples/bld/.idea/libraries/compile.xml
index 9bd86aa..99cc0c0 100644
--- a/examples/bld/.idea/libraries/compile.xml
+++ b/examples/bld/.idea/libraries/compile.xml
@@ -7,7 +7,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/examples/bld/.idea/libraries/runtime.xml b/examples/bld/.idea/libraries/runtime.xml
index 2ae5c4b..d4069f2 100644
--- a/examples/bld/.idea/libraries/runtime.xml
+++ b/examples/bld/.idea/libraries/runtime.xml
@@ -8,7 +8,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/examples/bld/.idea/libraries/test.xml b/examples/bld/.idea/libraries/test.xml
index b80486a..57ed5ef 100644
--- a/examples/bld/.idea/libraries/test.xml
+++ b/examples/bld/.idea/libraries/test.xml
@@ -8,7 +8,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/examples/bld/.idea/misc.xml b/examples/bld/.idea/misc.xml
index 699ae41..d0c8b16 100644
--- a/examples/bld/.idea/misc.xml
+++ b/examples/bld/.idea/misc.xml
@@ -12,6 +12,7 @@
diff --git a/examples/gradle/bin/main/com/example/CryptoPriceExample.kt b/examples/gradle/bin/main/com/example/CryptoPriceExample.kt
deleted file mode 100644
index da169d0..0000000
--- a/examples/gradle/bin/main/com/example/CryptoPriceExample.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.example
-
-import net.thauvin.erik.crypto.CryptoException
-import net.thauvin.erik.crypto.CryptoPrice.Companion.apiCall
-import net.thauvin.erik.crypto.CryptoPrice.Companion.buyPrice
-import net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice
-import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
-import org.json.JSONObject
-import java.io.IOException
-
-fun main(args: Array) {
- try {
- if (args.isNotEmpty()) {
- val price = if (args.size == 2) spotPrice(args[0], args[1]) else spotPrice(args[0])
- println("The current ${price.base} price is ${price.toCurrency()}")
- } else {
- // Get current Bitcoin spot price.
- val price = spotPrice("BTC")
- println("The current Bitcoin price is ${price.toCurrency()}")
-
- println()
-
- // Get current Ethereum sell price in Pound sterling.
- val gbpPrice = sellPrice("ETH", "GBP")
- println("The current Ethereum sell price is ${gbpPrice.toCurrency()}")
-
- // Get current Litecoin buy price in Euro.
- val euroPrice = buyPrice("LTC", "EUR")
- println("The current Litecoin buy price is ${euroPrice.toCurrency()}")
-
- println()
-
- // Get exchange rate using API.
- // See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates
- val response = apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
- val rates = JSONObject(response).getJSONObject("data").getJSONObject("rates")
- println("The USD-EUR exchange rate is: ${rates.getString("EUR")}")
- }
- } catch (e: CryptoException) {
- System.err.println("HTTP Status Code: ${e.statusCode}")
- System.err.println(e.message)
- } catch (e: IllegalArgumentException) {
- System.err.println("Could not display the specified currency: ${args[1]}")
- } catch (e: IOException) {
- System.err.println(e.message)
- }
-}
diff --git a/examples/gradle/bin/main/com/example/CryptoPriceSample.class b/examples/gradle/bin/main/com/example/CryptoPriceSample.class
deleted file mode 100644
index feb8e49..0000000
Binary files a/examples/gradle/bin/main/com/example/CryptoPriceSample.class and /dev/null differ
diff --git a/examples/gradle/build.gradle.kts b/examples/gradle/build.gradle.kts
index ea935f5..626d902 100644
--- a/examples/gradle/build.gradle.kts
+++ b/examples/gradle/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.50.0"
- kotlin("jvm") version "1.9.21"
+ id("com.github.ben-manes.versions") version "0.51.0"
+ kotlin("jvm") version "2.1.20"
}
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
@@ -15,8 +15,8 @@ repositories {
}
dependencies {
- implementation("net.thauvin.erik:cryptoprice:1.0.1-SNAPSHOT")
- implementation("org.json:json:20231013")
+ implementation("net.thauvin.erik:cryptoprice:1.0.3-SNAPSHOT")
+ implementation("org.json:json:20240303")
}
java {
@@ -28,11 +28,11 @@ application {
mainClass.set("com.example.CryptoPriceExampleKt")
}
-tasks {
- withType().configureEach {
- kotlinOptions.jvmTarget = java.targetCompatibility.toString()
- }
+kotlin {
+ compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
+}
+tasks {
register("runJava") {
group = "application"
mainClass.set("com.example.CryptoPriceSample")
diff --git a/examples/gradle/gradle/wrapper/gradle-wrapper.jar b/examples/gradle/gradle/wrapper/gradle-wrapper.jar
index 7f93135..1b33c55 100644
Binary files a/examples/gradle/gradle/wrapper/gradle-wrapper.jar and b/examples/gradle/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/examples/gradle/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/gradle/wrapper/gradle-wrapper.properties
index 3fa8f86..ca025c8 100644
--- a/examples/gradle/gradle/wrapper/gradle-wrapper.properties
+++ b/examples/gradle/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/examples/gradle/gradlew b/examples/gradle/gradlew
index 1aa94a4..23d15a9 100755
--- a/examples/gradle/gradlew
+++ b/examples/gradle/gradlew
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# SPDX-License-Identifier: Apache-2.0
+#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
# 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -112,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
@@ -203,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
-# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
- org.gradle.wrapper.GradleWrapperMain \
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
diff --git a/examples/gradle/gradlew.bat b/examples/gradle/gradlew.bat
index 93e3f59..db3a6ac 100644
--- a/examples/gradle/gradlew.bat
+++ b/examples/gradle/gradlew.bat
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
@@ -57,22 +59,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+set CLASSPATH=
@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
diff --git a/examples/gradle/src/main/kotlin/com/example/CryptoPriceExample.kt b/examples/gradle/src/main/kotlin/com/example/CryptoPriceExample.kt
index 4eb0a6c..6aa15fc 100644
--- a/examples/gradle/src/main/kotlin/com/example/CryptoPriceExample.kt
+++ b/examples/gradle/src/main/kotlin/com/example/CryptoPriceExample.kt
@@ -41,7 +41,7 @@ fun main(args: Array) {
} catch (e: CryptoException) {
System.err.println("HTTP Status Code: ${e.statusCode}")
System.err.println("${e.message} (${e.id})")
- } catch (e: IllegalArgumentException) {
+ } catch (ignore: IllegalArgumentException) {
System.err.println("Could not display the specified currency: ${args[1]}")
} catch (e: IOException) {
System.err.println(e.message)
diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar
index e029c6d..19f87d3 100644
Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ
diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties
index ac34063..751133d 100644
--- a/lib/bld/bld-wrapper.properties
+++ b/lib/bld/bld-wrapper.properties
@@ -1,9 +1,10 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
-bld.extension.jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.1
-bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.0-SNAPSHOT
-bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.0-SNAPSHOT
-bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation=
+bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.10-SNAPSHOT
+bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.4-SNAPSHOT
+bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10
+bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.1.0-SNAPSHOT
+bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories=
-bld.version=1.7.5
+bld.version=2.2.1
diff --git a/pom.xml b/pom.xml
index 47da6a8..f3345e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0net.thauvin.erikcryptoprice
- 1.0.2-SNAPSHOT
+ 1.0.3-SNAPSHOTcryptopriceRetrieve cryptocurrencies priceshttps://github.com/ethauvin/cryptoprice
@@ -18,31 +18,13 @@
org.jetbrains.kotlinkotlin-stdlib
- 1.9.21
- compile
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-common
- 1.9.21
- compile
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk7
- 1.9.21
- compile
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- 1.9.21
+ 2.1.20compileorg.jsonjson
- 20231013
+ 20250107compile
diff --git a/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java b/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java
index c33e9eb..18b18ec 100644
--- a/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java
+++ b/src/bld/java/net/thauvin/erik/crypto/CryptoPriceBuild.java
@@ -1,13 +1,45 @@
+/*
+ * CryptoPriceBuild.java
+ *
+ * Copyright 2021-2025 Erik C. Thauvin (erik@thauvin.net)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
package net.thauvin.erik.crypto;
import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.DetektOperation;
+import rife.bld.extension.DokkaOperation;
import rife.bld.extension.JacocoReportOperation;
-import rife.bld.extension.dokka.DokkaOperation;
import rife.bld.extension.dokka.LoggingLevel;
import rife.bld.extension.dokka.OutputFormat;
+import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.bld.publish.PomBuilder;
import rife.bld.publish.PublishDeveloper;
@@ -18,16 +50,21 @@ import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.compile;
import static rife.bld.dependencies.Scope.test;
public class CryptoPriceBuild extends Project {
+ final File srcMainKotlin = new File(srcMainDirectory(), "kotlin");
+
public CryptoPriceBuild() {
pkg = "net.thauvin.erik.crypto";
name = "cryptoprice";
- version = version(1, 0, 2, "SNAPSHOT");
+ version = version(1, 0, 3, "SNAPSHOT");
mainClass = "net.thauvin.erik.crypto.CryptoPrice";
@@ -36,63 +73,70 @@ public class CryptoPriceBuild extends Project {
autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
- final var kotlin = version(1, 9, 21);
+ final var kotlin = version(2, 1, 20);
scope(compile)
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin))
- .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-common", kotlin))
- .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk7", kotlin))
- .include(dependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", kotlin))
- .include(dependency("org.json", "json", "20231013"))
+ .include(dependency("org.json", "json", "20250107"))
.include(dependency("com.squareup.okhttp3", "okhttp", version(4, 12, 0)));
scope(test)
- .include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 27, 0)))
- .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", version(1, 9, 21)))
- .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
- .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)));
+ .include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 28, 1)))
+ .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin))
+ .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2)))
+ .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 2)))
+ .include(dependency("org.junit.platform", "junit-platform-launcher", version(1, 12, 2)));
publishOperation()
.repository(version.isSnapshot() ? repository(SONATYPE_SNAPSHOTS_LEGACY.location())
.withCredentials(property("sonatype.user"), property("sonatype.password"))
: repository(SONATYPE_RELEASES_LEGACY.location())
.withCredentials(property("sonatype.user"), property("sonatype.password")))
+ .repository(repository("github"))
.info()
.groupId("net.thauvin.erik")
.artifactId(name)
.description("Retrieve cryptocurrencies prices")
.url("https://github.com/ethauvin/" + name)
- .developer(
- new PublishDeveloper()
- .id("ethauvin")
- .name("Erik C. Thauvin")
- .email("erik@thauvin.net")
- .url("https://erik.thauvin.net/")
+ .developer(new PublishDeveloper()
+ .id("ethauvin")
+ .name("Erik C. Thauvin")
+ .email("erik@thauvin.net")
+ .url("https://erik.thauvin.net/")
)
- .license(
- new PublishLicense()
- .name("BSD 3-Clause")
- .url("https://opensource.org/licenses/BSD-3-Clause")
+ .license(new PublishLicense()
+ .name("BSD 3-Clause")
+ .url("https://opensource.org/licenses/BSD-3-Clause")
)
- .scm(
- new PublishScm()
- .connection("scm:git:https://github.com/ethauvin/" + name + ".git")
- .developerConnection("scm:git:git@github.com:ethauvin/" + name + ".git")
- .url("https://github.com/ethauvin/" + name)
+ .scm(new PublishScm()
+ .connection("scm:git:https://github.com/ethauvin/" + name + ".git")
+ .developerConnection("scm:git:git@github.com:ethauvin/" + name + ".git")
+ .url("https://github.com/ethauvin/" + name)
)
.signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase"));
- jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
+ jarSourcesOperation().sourceDirectories(srcMainKotlin);
}
public static void main(final String[] args) {
+ // Enable detailed logging for the extensions
+ final var level = Level.ALL;
+ final var logger = Logger.getLogger("rife.bld.extension");
+ final var consoleHandler = new ConsoleHandler();
+
+ consoleHandler.setLevel(level);
+ logger.addHandler(consoleHandler);
+ logger.setLevel(level);
+ logger.setUseParentHandlers(false);
+
new CryptoPriceBuild().start(args);
}
@BuildCommand(summary = "Compiles the Kotlin project")
@Override
- public void compile() throws IOException {
+ public void compile() throws Exception {
new CompileKotlinOperation()
.fromProject(this)
+ .compileOptions(new CompileOptions().verbose(true))
.execute();
}
@@ -113,9 +157,10 @@ public class CryptoPriceBuild extends Project {
}
@BuildCommand(summary = "Generates JaCoCo Reports")
- public void jacoco() throws IOException {
+ public void jacoco() throws Exception {
new JacocoReportOperation()
.fromProject(this)
+ .sourceFiles(srcMainKotlin)
.execute();
}
@@ -137,6 +182,12 @@ public class CryptoPriceBuild extends Project {
pomRoot();
}
+ @Override
+ public void publishLocal() throws Exception {
+ super.publishLocal();
+ pomRoot();
+ }
+
@BuildCommand(value = "pom-root", summary = "Generates the POM file in the root directory")
public void pomRoot() throws FileUtilsErrorException {
PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(),
diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
index 38fd2df..a4e599b 100644
--- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
+++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoException.kt
@@ -1,7 +1,7 @@
/*
* CryptoException.kt
*
- * Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
+ * Copyright 2021-2025 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
diff --git a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
index 0940aac..578efe5 100644
--- a/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
+++ b/src/main/kotlin/net/thauvin/erik/crypto/CryptoPrice.kt
@@ -1,7 +1,7 @@
/*
* CryptoPrice.kt
*
- * Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
+ * Copyright 2021-2025 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -42,6 +42,8 @@ import java.math.BigDecimal
import java.text.NumberFormat
import java.time.LocalDate
import java.util.*
+import java.util.logging.Level
+import java.util.logging.Logger
/**
* Retrieves and holds a cryptocurrency price.
@@ -57,6 +59,9 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
// Coinbase API URL
private const val COINBASE_API_URL = "https://api.coinbase.com/v2/"
+ /** The logger instance. **/
+ val logger: Logger by lazy { Logger.getLogger(CryptoPrice::class.java.simpleName) }
+
/**
* Converts JSON data object to [CryptoPrice].
*
@@ -105,6 +110,9 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
id = "empty_response",
message = "Empty response."
)
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine(body)
+ }
try {
val json = JSONObject(body)
if (response.isSuccessful) {
diff --git a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
index 1ac50e5..fcc64f2 100644
--- a/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/crypto/CryptoPriceTest.kt
@@ -1,7 +1,7 @@
/*
* CryptoPriceTest.kt
*
- * Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
+ * Copyright 2021-2025 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -42,9 +42,12 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.toPrice
import org.json.JSONObject
+import org.junit.jupiter.api.BeforeAll
import java.math.BigDecimal
import java.time.LocalDate
import java.util.*
+import java.util.logging.ConsoleHandler
+import java.util.logging.Level
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
@@ -80,7 +83,6 @@ class CryptoPriceTest {
prop(CryptoPrice::currency).isEqualTo("EUR")
prop(CryptoPrice::amount).isGreaterThan(BigDecimal(0))
}
-
}
}
@@ -240,4 +242,16 @@ class CryptoPriceTest {
assertEquals(json, price.toString(), "toString()")
assertEquals(price.toString(), price.toJson(""), "toString() = toJson('')")
}
+
+ companion object {
+ @JvmStatic
+ @BeforeAll
+ fun beforeAll() {
+ with(CryptoPrice.logger) {
+ addHandler(ConsoleHandler().apply { level = Level.FINE })
+ level = Level.FINE
+ useParentHandlers = false
+ }
+ }
+ }
}