diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index d3ae3bd..2c2e66e 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/src/main/java/com/example/CryptoPriceSample.java b/examples/src/main/java/com/example/CryptoPriceSample.java
index 967dc25..6a32bff 100644
--- a/examples/src/main/java/com/example/CryptoPriceSample.java
+++ b/examples/src/main/java/com/example/CryptoPriceSample.java
@@ -6,20 +6,22 @@ import org.json.JSONObject;
import java.io.IOException;
import java.util.Collections;
+import java.util.Currency;
import java.util.List;
+import java.util.Locale;
public class CryptoPriceSample {
public static void main(final String[] args) {
try {
if (args.length > 0) {
- final CryptoPrice price;
+ final String currency;
if (args.length == 2) {
- price = CryptoPrice.spotPrice(args[0], args[1]);
+ currency = args[1];
} else {
- price = CryptoPrice.spotPrice(args[0]);
+ currency = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
}
- System.out.println("The current " + price.getBase() + " price is " + price.getAmount() + " in "
- + price.getCurrency());
+ final var price = CryptoPrice.spotPrice(args[0], currency);
+ System.out.println("The current " + price.getBase() + " price is " + price.toCurrency());
} else {
// Get current Bitcoin spot price.
final var price = CryptoPrice.spotPrice("BTC");
@@ -42,11 +44,13 @@ public class CryptoPriceSample {
final var response = CryptoPrice.apiCall(List.of("exchange-rates"),
Collections.singletonMap("currency", "USD"));
final var rates = new JSONObject(response).getJSONObject("data").getJSONObject("rates");
- System.out.printf("The USD-EUR exchange rate is: %s%n", rates.getString("EUR"));
+ System.out.println("The USD-EUR exchange rate is: " + rates.getString("EUR"));
}
} catch (CryptoException e) {
System.err.println("HTTP Status Code: " + e.getStatusCode());
System.err.println(e.getMessage());
+ } catch (IllegalArgumentException e) {
+ System.err.println("Could not display the specified currency: " + args[1]);
} catch (IOException e) {
System.err.println(e.getMessage());
}
diff --git a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
index e869095..413960a 100644
--- a/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
+++ b/examples/src/main/kotlin/com/example/CryptoPriceExample.kt
@@ -7,12 +7,14 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice
import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
import org.json.JSONObject
import java.io.IOException
+import java.util.*
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.amount} in ${price.currency}")
+ val currency = if (args.size == 2) args[1] else Currency.getInstance(Locale.getDefault()).currencyCode
+ val price = spotPrice(args[0], currency)
+ println("The current ${price.base} price is ${price.toCurrency()}")
} else {
// Get current Bitcoin spot price.
val price = spotPrice("BTC")
@@ -39,6 +41,8 @@ fun main(args: Array) {
} 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)
}