From 39bbd1cf69008ad291e21477eec1d7d86c37a760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Terje=20S=C3=B8rensen?= Date: Sun, 11 Feb 2024 09:39:14 +0100 Subject: [PATCH 01/11] Made categories in CoinFullData to list of Strings --- .../com/litesoftwares/coingecko/domain/Coins/CoinFullData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/litesoftwares/coingecko/domain/Coins/CoinFullData.java b/src/main/java/com/litesoftwares/coingecko/domain/Coins/CoinFullData.java index ce7577e..7ab91c2 100644 --- a/src/main/java/com/litesoftwares/coingecko/domain/Coins/CoinFullData.java +++ b/src/main/java/com/litesoftwares/coingecko/domain/Coins/CoinFullData.java @@ -29,7 +29,7 @@ public class CoinFullData { @JsonProperty("hashing_algorithm") private String hashingAlgorithm; @JsonProperty("categories") - private List categories; + private List categories; @JsonProperty("public_notice") private String publicNotice; @JsonProperty("additional_notices") From 899e85ce687251863e63a81cf9cb08c054852520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Terje=20S=C3=B8rensen?= Date: Thu, 28 Mar 2024 07:54:21 +0100 Subject: [PATCH 02/11] Create maven.yml --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..afe4fe3 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 206028c01476311c636a19b206d047af566d5a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Terje=20S=C3=B8rensen?= Date: Thu, 28 Mar 2024 07:56:02 +0100 Subject: [PATCH 03/11] Update maven.yml --- .github/workflows/maven.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index afe4fe3..9e5bf12 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,3 @@ jobs: cache: maven - name: Build with Maven run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From ae6fffefc307fdd0dbc4830618b46b5e4212a3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Terje=20S=C3=B8rensen?= Date: Thu, 28 Mar 2024 08:24:41 +0100 Subject: [PATCH 04/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 818acc3..181ced8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # CoinGecko-Java +![CoinGecko build status](https://github.com/Philipinho/CoinGecko-Java/actions/workflows/maven.yml/badge.svg) Java wrapper for the CoinGecko API.

java-gecko-200 From 8bf3f37715a8f2f93ece47d7431f235d09c68560 Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Thu, 2 May 2024 18:42:41 +0100 Subject: [PATCH 05/11] line break --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 181ced8..a9df553 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # CoinGecko-Java ![CoinGecko build status](https://github.com/Philipinho/CoinGecko-Java/actions/workflows/maven.yml/badge.svg) + Java wrapper for the CoinGecko API.

java-gecko-200 From d504457cb2fb7e4807a399c241aa49a3e5ccf9c3 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Wed, 8 Nov 2023 10:01:07 +0100 Subject: [PATCH 06/11] Switch to own coordinates, enable CI/CD via GitHub Actions and some minor cleanups --- .github/dependabot.yml | 11 ++ .github/workflows/maven-publish-release.yml | 30 +++++ .github/workflows/maven.yml | 28 ++--- README.md | 14 ++- pom.xml | 127 ++++++++++++++++++-- 5 files changed, 180 insertions(+), 30 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/maven-publish-release.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..76e22be --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "maven" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/maven-publish-release.yml b/.github/workflows/maven-publish-release.yml new file mode 100644 index 0000000..102cd60 --- /dev/null +++ b/.github/workflows/maven-publish-release.yml @@ -0,0 +1,30 @@ +name: Publish release package to the Maven Central Repository +on: + release: + types: [ created ] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Install gpg secret key + run: | + # Install gpg secret key + cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import + # Verify gpg secret key + gpg --list-secret-keys --keyid-format LONG + - uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + cache: maven + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Publish package + run: mvn --batch-mode -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} -P release clean deploy + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9e5bf12..44fd9a4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,11 +1,3 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - name: Java CI with Maven on: @@ -16,16 +8,14 @@ on: jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + - uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn --batch-mode --update-snapshots package \ No newline at end of file diff --git a/README.md b/README.md index a9df553..f30a0ae 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ +CoinGecko Client (Java) +======================= +![GitHub](https://img.shields.io/github/license/osslabz/coingecko-client) +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osslabz/coingecko-client/maven.yml?branch=master) +[![Maven Central](https://img.shields.io/maven-central/v/net.osslabz/coingecko-client?label=Maven%20Central)](https://search.maven.org/artifact/net.osslabz/coingecko-client) + +This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philipinho/CoinGecko-Java) that is properly releases on [Maven Central](https://search.maven.org/artifact/net.osslabz/coingecko-client). + +--- + +--- + # CoinGecko-Java ![CoinGecko build status](https://github.com/Philipinho/CoinGecko-Java/actions/workflows/maven.yml/badge.svg) @@ -45,4 +57,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/pom.xml b/pom.xml index bbad67d..d17c9d3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,38 +4,134 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.litesoftwares + net.osslabz coingecko-java - 1.0-SNAPSHOT + 1.0.0 + + ${project.groupId}:${project.artifactId} + Allows to decode raw input data from an EVM smart contract call (on Ethereum or a compatible chain like + Avalanche, BSC etc.) into a processable format obtained from the contract's ABi definition (JSON). + + https://github.com/osslabz/coingecko-client - 1.8 - 1.8 + 8 UTF-8 + + 2.9.0 + + + MIT License + https://opensource.org/license/mit/ + + + + + + Philip Okugbe + 16838612+Philipinho@users.noreply.github.com + Philipinho/CoinGecko-Java + https://github.com/Philipinho/CoinGecko-Java + + + + + scm:git:ssh://git@github.com/osslabz/coingecko-client.git + scm:git:ssh://git@github.com/osslabz/coingecko-client.git + https://github.com/osslabz/coingecko-client + HEAD + + com.squareup.retrofit2 retrofit - 2.9.0 + ${retrofit.version} com.squareup.retrofit2 converter-jackson - 2.9.0 + ${retrofit.version} org.projectlombok lombok - 1.18.28 + 1.18.30 provided + + + + release + + + + org.apache.maven.plugins + maven-source-plugin + 3.3.0 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.5.0 + + + attach-javadocs + + jar + + + none + false + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + + @@ -43,10 +139,21 @@ maven-compiler-plugin 3.11.0 - 1.8 - 1.8 + ${maven.compiler.release} - + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + \ No newline at end of file From 5600d9d718f58bf67bf1c9b3cbb6851bf4eed188 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Wed, 8 Nov 2023 11:19:46 +0100 Subject: [PATCH 07/11] post release --- README.md | 2 -- pom.xml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index f30a0ae..2e83231 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philip --- ---- - # CoinGecko-Java ![CoinGecko build status](https://github.com/Philipinho/CoinGecko-Java/actions/workflows/maven.yml/badge.svg) diff --git a/pom.xml b/pom.xml index d17c9d3..1a27e81 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.osslabz coingecko-java - 1.0.0 + 1.0.1-SNAPSHOT ${project.groupId}:${project.artifactId} Allows to decode raw input data from an EVM smart contract call (on Ethereum or a compatible chain like From 081a7b9f76b33f6b0158a2fc777289ef91854701 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Thu, 9 Nov 2023 08:11:37 +0100 Subject: [PATCH 08/11] fix artifact name --- README.md | 2 ++ pom.xml | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2e83231..e20c2ac 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ CoinGecko Client (Java) This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philipinho/CoinGecko-Java) that is properly releases on [Maven Central](https://search.maven.org/artifact/net.osslabz/coingecko-client). +Once [Enable CI and Automated Release Management #41](https://github.com/Philipinho/CoinGecko-Java/pull/41) is merged and the original project is published this fork will be discontinued. + --- # CoinGecko-Java diff --git a/pom.xml b/pom.xml index 1a27e81..a0c0abc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,11 @@ 4.0.0 net.osslabz - coingecko-java - 1.0.1-SNAPSHOT + coingecko-client + 1.0.1 ${project.groupId}:${project.artifactId} - Allows to decode raw input data from an EVM smart contract call (on Ethereum or a compatible chain like - Avalanche, BSC etc.) into a processable format obtained from the contract's ABi definition (JSON). - + Java wrapper for the CoinGecko API https://github.com/osslabz/coingecko-client From cd3fb4cc420824663bfb1bc5f4099b119f9913a5 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Thu, 9 Nov 2023 08:24:47 +0100 Subject: [PATCH 09/11] some readme cleanup --- README.md | 42 ++++++++++++++++++++++++++++++++++++------ pom.xml | 12 ++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e20c2ac..4a8f7dc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,43 @@ -CoinGecko Client (Java) -======================= -![GitHub](https://img.shields.io/github/license/osslabz/coingecko-client) -![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osslabz/coingecko-client/maven.yml?branch=master) -[![Maven Central](https://img.shields.io/maven-central/v/net.osslabz/coingecko-client?label=Maven%20Central)](https://search.maven.org/artifact/net.osslabz/coingecko-client) +![GitHub](https://img.shields.io/github/license/osslabz/coingecko-java) +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osslabz/coingecko-java/maven.yml?branch=master) +[![Maven Central](https://img.shields.io/maven-central/v/net.osslabz/coingecko-java?label=Maven%20Central)](https://search.maven.org/artifact/net.osslabz/coingecko-client) -This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philipinho/CoinGecko-Java) that is properly releases on [Maven Central](https://search.maven.org/artifact/net.osslabz/coingecko-client). +This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philipinho/CoinGecko-Java) that is properly releases on [Maven Central](https://search.maven.org/artifact/net.osslabz/coingecko-java). Once [Enable CI and Automated Release Management #41](https://github.com/Philipinho/CoinGecko-Java/pull/41) is merged and the original project is published this fork will be discontinued. +Usage +--------- + +### Maven + +```xml + + net.osslabz + coingecko-java + 1.0.0 + +``` + +### Gradle (Groovy) + +```groovy +dependencies { + implementation 'net.osslabz:coingecko-java:1.0.0' +} +``` + +### Gradle (Kotlin) + +```kotlin +dependencies { + implementation ("net.osslabz:coingecko-java:1.0.0") +} +``` + + +**For further info see below the original README.** + --- # CoinGecko-Java diff --git a/pom.xml b/pom.xml index a0c0abc..ad308f8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ 4.0.0 net.osslabz - coingecko-client - 1.0.1 + coingecko-java + 1.0.1-SNAPSHOT ${project.groupId}:${project.artifactId} Java wrapper for the CoinGecko API - https://github.com/osslabz/coingecko-client + https://github.com/osslabz/coingecko-java 8 @@ -36,9 +36,9 @@ - scm:git:ssh://git@github.com/osslabz/coingecko-client.git - scm:git:ssh://git@github.com/osslabz/coingecko-client.git - https://github.com/osslabz/coingecko-client + scm:git:ssh://git@github.com/osslabz/coingecko-java.git + scm:git:ssh://git@github.com/osslabz/coingecko-java.git + https://github.com/osslabz/coingecko-java HEAD From 7f186387f6acc348048ce6c9bbb487178641a04b Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Thu, 9 Nov 2023 08:26:31 +0100 Subject: [PATCH 10/11] some readme cleanup --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4a8f7dc..c9d2af9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ +# CoinGecko-Java ![GitHub](https://img.shields.io/github/license/osslabz/coingecko-java) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osslabz/coingecko-java/maven.yml?branch=master) [![Maven Central](https://img.shields.io/maven-central/v/net.osslabz/coingecko-java?label=Maven%20Central)](https://search.maven.org/artifact/net.osslabz/coingecko-client) +Java wrapper for the CoinGecko API. +

+ java-gecko-200 +

+ + This is a (synced) fork of [Philipinho/CoinGecko-Java](https://github.com/Philipinho/CoinGecko-Java) that is properly releases on [Maven Central](https://search.maven.org/artifact/net.osslabz/coingecko-java). Once [Enable CI and Automated Release Management #41](https://github.com/Philipinho/CoinGecko-Java/pull/41) is merged and the original project is published this fork will be discontinued. @@ -40,14 +47,6 @@ dependencies { --- -# CoinGecko-Java -![CoinGecko build status](https://github.com/Philipinho/CoinGecko-Java/actions/workflows/maven.yml/badge.svg) - -Java wrapper for the CoinGecko API. -

- java-gecko-200 -

- ## Usage This API client covers all CoinGecko's API endpoints and i'll try to update it when new endpoints are added. From 845964ffecc9542123b1b135de4546184599e682 Mon Sep 17 00:00:00 2001 From: Raphael Vullriede Date: Thu, 29 Feb 2024 20:43:39 +0100 Subject: [PATCH 11/11] add support for PRO and DEMO tokens --- .github/workflows/maven-publish-release.yml | 2 +- .github/workflows/maven.yml | 2 +- pom.xml | 24 ++++- .../litesoftwares/coingecko/CoinGeckoApi.java | 42 ++++++-- .../coingecko/constant/TokenType.java | 16 +++ .../coingecko/domain/ApiToken.java | 31 ++++++ .../impl/CoinGeckoApiClientImpl.java | 99 +++++++++++-------- .../coingecko/examples/SearchExample.java | 2 +- 8 files changed, 164 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/litesoftwares/coingecko/constant/TokenType.java create mode 100644 src/main/java/com/litesoftwares/coingecko/domain/ApiToken.java diff --git a/.github/workflows/maven-publish-release.yml b/.github/workflows/maven-publish-release.yml index 102cd60..11ed4aa 100644 --- a/.github/workflows/maven-publish-release.yml +++ b/.github/workflows/maven-publish-release.yml @@ -13,7 +13,7 @@ jobs: cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import # Verify gpg secret key gpg --list-secret-keys --keyid-format LONG - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK uses: actions/setup-java@v3 with: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 44fd9a4..1ebe402 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,7 +10,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK uses: actions/setup-java@v3 with: diff --git a/pom.xml b/pom.xml index ad308f8..7374d77 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.osslabz coingecko-java - 1.0.1-SNAPSHOT + 1.1.0 ${project.groupId}:${project.artifactId} Java wrapper for the CoinGecko API @@ -24,6 +24,7 @@ MIT License https://opensource.org/license/mit/ + @@ -50,6 +51,17 @@ ${retrofit.version} + + com.squareup.okhttp3 + logging-interceptor + 4.12.0 + + + org.slf4j + slf4j-api + 2.0.9 + + com.squareup.retrofit2 converter-jackson @@ -63,6 +75,14 @@ provided + + + ch.qos.logback + logback-classic + 1.4.14 + test + + @@ -86,7 +106,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.3 attach-javadocs diff --git a/src/main/java/com/litesoftwares/coingecko/CoinGeckoApi.java b/src/main/java/com/litesoftwares/coingecko/CoinGeckoApi.java index 0e349d7..02029c1 100644 --- a/src/main/java/com/litesoftwares/coingecko/CoinGeckoApi.java +++ b/src/main/java/com/litesoftwares/coingecko/CoinGeckoApi.java @@ -1,7 +1,11 @@ package com.litesoftwares.coingecko; +import com.litesoftwares.coingecko.constant.TokenType; +import com.litesoftwares.coingecko.domain.ApiToken; import com.litesoftwares.coingecko.exception.CoinGeckoApiException; import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Call; import retrofit2.Response; import retrofit2.Retrofit; @@ -12,20 +16,38 @@ import java.util.concurrent.TimeUnit; public class CoinGeckoApi { - private final String API_BASE_URL = "https://api.coingecko.com/api/v3/"; + + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CoinGeckoApi.class); + private static final String API_BASE_URL_PUBLIC = "https://api.coingecko.com/api/v3/"; + + private static final String API_BASE_URL_PRO = "https://pro-api.coingecko.com/api/v3/"; private OkHttpClient okHttpClient = null; private Retrofit retrofit = null; - public S createService(Class serviceClass, Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds){ - okHttpClient = new OkHttpClient.Builder() + public S createService(Class serviceClass, Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds, ApiToken apiToken) { + OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder() .connectTimeout(connectionTimeoutSeconds, TimeUnit.SECONDS) .readTimeout(readTimeoutSeconds, TimeUnit.SECONDS) - .writeTimeout(writeTimeoutSeconds, TimeUnit.SECONDS) - .build(); + .writeTimeout(writeTimeoutSeconds, TimeUnit.SECONDS); + + if (apiToken != null) { + httpClientBuilder.addInterceptor(chain -> { + Request original = chain.request(); + Request request = original.newBuilder() + .header(apiToken.getType().getHeaderName(), apiToken.getValue()) + .method(original.method(), original.body()) + .build(); + + return chain.proceed(request); + }); + } + httpClientBuilder.addInterceptor(new HttpLoggingInterceptor(log::trace).setLevel(HttpLoggingInterceptor.Level.HEADERS)); + + okHttpClient = httpClientBuilder.build(); retrofit = new Retrofit.Builder() - .baseUrl(API_BASE_URL) + .baseUrl(apiToken != null && TokenType.PRO.equals(apiToken.getType()) ? API_BASE_URL_PRO : API_BASE_URL_PUBLIC) .client(okHttpClient) .addConverterFactory(JacksonConverterFactory.create()) .build(); @@ -38,7 +60,7 @@ public T executeSync(Call call) { Response response = call.execute(); if (response.isSuccessful()) { return response.body(); - } else if(response.code() == 429) { + } else if (response.code() == 429) { // When the client gets rate limited the response is a CloudFlare error page, // not a regular error body. CoinGeckoApiError apiError = new CoinGeckoApiError(); @@ -68,9 +90,9 @@ public void shutdown() { } } - private CoinGeckoApiError getCoinGeckoApiError(Response response) throws IOException{ - return (CoinGeckoApiError) retrofit.responseBodyConverter(CoinGeckoApiError.class,new Annotation[0]) + private CoinGeckoApiError getCoinGeckoApiError(Response response) throws IOException { + return (CoinGeckoApiError) retrofit.responseBodyConverter(CoinGeckoApiError.class, new Annotation[0]) .convert(response.errorBody()); } -} +} \ No newline at end of file diff --git a/src/main/java/com/litesoftwares/coingecko/constant/TokenType.java b/src/main/java/com/litesoftwares/coingecko/constant/TokenType.java new file mode 100644 index 0000000..dee9287 --- /dev/null +++ b/src/main/java/com/litesoftwares/coingecko/constant/TokenType.java @@ -0,0 +1,16 @@ +package com.litesoftwares.coingecko.constant; + +public enum TokenType { + DEMO("x-cg-demo-api-key"), + PRO("x-cg-demo-api-key"); + + private final String headerName; + + TokenType(String headerName) { + this.headerName = headerName; + } + + public String getHeaderName() { + return headerName; + } +} \ No newline at end of file diff --git a/src/main/java/com/litesoftwares/coingecko/domain/ApiToken.java b/src/main/java/com/litesoftwares/coingecko/domain/ApiToken.java new file mode 100644 index 0000000..b3ffed7 --- /dev/null +++ b/src/main/java/com/litesoftwares/coingecko/domain/ApiToken.java @@ -0,0 +1,31 @@ +package com.litesoftwares.coingecko.domain; + +import com.litesoftwares.coingecko.constant.TokenType; + +public class ApiToken { + + private TokenType type; + + private String value; + + public ApiToken(TokenType type, String value) { + this.type = type; + this.value = value; + } + + public static ApiToken demo(String value) { + return new ApiToken(TokenType.DEMO, value); + } + + public static ApiToken pro(String value) { + return new ApiToken(TokenType.PRO, value); + } + + public TokenType getType() { + return type; + } + + public String getValue() { + return value; + } +} \ No newline at end of file diff --git a/src/main/java/com/litesoftwares/coingecko/impl/CoinGeckoApiClientImpl.java b/src/main/java/com/litesoftwares/coingecko/impl/CoinGeckoApiClientImpl.java index 23661ed..3843a89 100644 --- a/src/main/java/com/litesoftwares/coingecko/impl/CoinGeckoApiClientImpl.java +++ b/src/main/java/com/litesoftwares/coingecko/impl/CoinGeckoApiClientImpl.java @@ -1,20 +1,30 @@ package com.litesoftwares.coingecko.impl; -import com.litesoftwares.coingecko.CoinGeckoApiService; import com.litesoftwares.coingecko.CoinGeckoApi; -import com.litesoftwares.coingecko.domain.*; -import com.litesoftwares.coingecko.domain.Coins.*; +import com.litesoftwares.coingecko.CoinGeckoApiClient; +import com.litesoftwares.coingecko.CoinGeckoApiService; +import com.litesoftwares.coingecko.domain.AssetPlatforms; +import com.litesoftwares.coingecko.domain.Coins.CoinFullData; +import com.litesoftwares.coingecko.domain.Coins.CoinHistoryById; +import com.litesoftwares.coingecko.domain.Coins.CoinList; +import com.litesoftwares.coingecko.domain.Coins.CoinMarkets; +import com.litesoftwares.coingecko.domain.Coins.CoinTickerById; +import com.litesoftwares.coingecko.domain.Coins.MarketChart; import com.litesoftwares.coingecko.domain.Events.EventCountries; import com.litesoftwares.coingecko.domain.Events.EventTypes; import com.litesoftwares.coingecko.domain.Events.Events; import com.litesoftwares.coingecko.domain.ExchangeRates.ExchangeRates; -import com.litesoftwares.coingecko.domain.Exchanges.*; +import com.litesoftwares.coingecko.domain.Exchanges.ExchangeById; +import com.litesoftwares.coingecko.domain.Exchanges.Exchanges; +import com.litesoftwares.coingecko.domain.Exchanges.ExchangesList; +import com.litesoftwares.coingecko.domain.Exchanges.ExchangesTickersById; import com.litesoftwares.coingecko.domain.Global.DecentralizedFinanceDefi; import com.litesoftwares.coingecko.domain.Global.Global; +import com.litesoftwares.coingecko.domain.Ping; import com.litesoftwares.coingecko.domain.Search.Search; import com.litesoftwares.coingecko.domain.Search.Trending; import com.litesoftwares.coingecko.domain.Status.StatusUpdates; -import com.litesoftwares.coingecko.CoinGeckoApiClient; +import com.litesoftwares.coingecko.domain.ApiToken; import java.util.List; import java.util.Map; @@ -31,43 +41,52 @@ public CoinGeckoApiClientImpl() { this(DEFAULT_CONNECTION_TIMEOUT, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_TIMEOUT); } - public CoinGeckoApiClientImpl(Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds){ + public CoinGeckoApiClientImpl(ApiToken apiToken) { + this(DEFAULT_CONNECTION_TIMEOUT, DEFAULT_READ_TIMEOUT, DEFAULT_WRITE_TIMEOUT, apiToken); + } + + public CoinGeckoApiClientImpl(Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds) { + this(connectionTimeoutSeconds, readTimeoutSeconds, writeTimeoutSeconds, null); + } + + public CoinGeckoApiClientImpl(Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds, ApiToken apiToken) { this.coinGeckoApi = new CoinGeckoApi(); this.coinGeckoApiService = coinGeckoApi.createService( CoinGeckoApiService.class, connectionTimeoutSeconds, readTimeoutSeconds, - writeTimeoutSeconds + writeTimeoutSeconds, + apiToken ); } @Override - public Ping ping(){ + public Ping ping() { return coinGeckoApi.executeSync(coinGeckoApiService.ping()); } @Override - public Map> getPrice(String ids, String vsCurrencies){ - return getPrice(ids, vsCurrencies, false, false, false, false); + public Map> getPrice(String ids, String vsCurrencies) { + return getPrice(ids, vsCurrencies, false, false, false, false); } @Override public Map> getPrice(String ids, String vsCurrencies, boolean includeMarketCap, boolean include24hrVol, boolean include24hrChange, boolean includeLastUpdatedAt) { - return coinGeckoApi.executeSync(coinGeckoApiService.getPrice(ids, vsCurrencies,includeMarketCap, include24hrVol, include24hrChange, includeLastUpdatedAt)); + return coinGeckoApi.executeSync(coinGeckoApiService.getPrice(ids, vsCurrencies, includeMarketCap, include24hrVol, include24hrChange, includeLastUpdatedAt)); } @Override public Map> getTokenPrice(String id, String contractAddress, String vsCurrencies) { - return getTokenPrice(id,contractAddress,vsCurrencies,false,false,false,false); + return getTokenPrice(id, contractAddress, vsCurrencies, false, false, false, false); } @Override public Map> getTokenPrice(String id, String contractAddress, String vsCurrencies, boolean includeMarketCap, boolean include24hrVol, boolean include24hrChange, boolean includeLastUpdatedAt) { - return coinGeckoApi.executeSync(coinGeckoApiService.getTokenPrice(id,contractAddress,vsCurrencies,includeMarketCap,include24hrVol,include24hrChange,includeLastUpdatedAt)); + return coinGeckoApi.executeSync(coinGeckoApiService.getTokenPrice(id, contractAddress, vsCurrencies, includeMarketCap, include24hrVol, include24hrChange, includeLastUpdatedAt)); } @Override - public List getSupportedVsCurrencies(){ + public List getSupportedVsCurrencies() { return coinGeckoApi.executeSync(coinGeckoApiService.getSupportedVsCurrencies()); } @@ -78,7 +97,7 @@ public List getCoinList() { @Override public List getCoinMarkets(String vsCurrency) { - return getCoinMarkets(vsCurrency,null,null,null,null,false,null); + return getCoinMarkets(vsCurrency, null, null, null, null, false, null); } @Override @@ -93,37 +112,37 @@ public List getCoinMarkets(String vsCurrency, String ids, String ca @Override public CoinFullData getCoinById(String id) { - return getCoinById(id,true,true,true,true,true,false); + return getCoinById(id, true, true, true, true, true, false); } @Override public CoinFullData getCoinById(String id, boolean localization, boolean tickers, boolean marketData, boolean communityData, boolean developerData, boolean sparkline) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinById(id,localization,tickers,marketData,communityData,developerData,sparkline)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinById(id, localization, tickers, marketData, communityData, developerData, sparkline)); } @Override public CoinTickerById getCoinTickerById(String id) { - return getCoinTickerById(id,null,null,null); + return getCoinTickerById(id, null, null, null); } @Override public CoinTickerById getCoinTickerById(String id, String exchangeIds, Integer page, String order) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinTickerById(id,exchangeIds,page,order)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinTickerById(id, exchangeIds, page, order)); } @Override public CoinHistoryById getCoinHistoryById(String id, String date) { - return getCoinHistoryById(id,date,true); + return getCoinHistoryById(id, date, true); } @Override public CoinHistoryById getCoinHistoryById(String id, String date, boolean localization) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinHistoryById(id,date,localization)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinHistoryById(id, date, localization)); } @Override public MarketChart getCoinMarketChartById(String id, String vsCurrency, Integer days) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinMarketChartById(id,vsCurrency,days)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinMarketChartById(id, vsCurrency, days)); } @Override @@ -133,31 +152,31 @@ public MarketChart getCoinMarketChartById(String id, String vsCurrency, Integer @Override public MarketChart getCoinMarketChartRangeById(String id, String vsCurrency, String from, String to) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinMarketChartRangeById(id,vsCurrency,from,to)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinMarketChartRangeById(id, vsCurrency, from, to)); } @Override public List> getCoinOHLC(String id, String vsCurrency, Integer days) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinOHLC(id,vsCurrency,days)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinOHLC(id, vsCurrency, days)); } @Override public StatusUpdates getCoinStatusUpdateById(String id) { - return getCoinStatusUpdateById(id,null,null); + return getCoinStatusUpdateById(id, null, null); } @Override public StatusUpdates getCoinStatusUpdateById(String id, Integer perPage, Integer page) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinStatusUpdateById(id,perPage,page)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinStatusUpdateById(id, perPage, page)); } @Override public CoinFullData getCoinInfoByContractAddress(String id, String contractAddress) { - return coinGeckoApi.executeSync(coinGeckoApiService.getCoinInfoByContractAddress(id,contractAddress)); + return coinGeckoApi.executeSync(coinGeckoApiService.getCoinInfoByContractAddress(id, contractAddress)); } @Override - public List getAssetPlatforms(){ + public List getAssetPlatforms() { return coinGeckoApi.executeSync(coinGeckoApiService.getAssetPlatforms()); } @@ -183,27 +202,27 @@ public ExchangeById getExchangesById(String id) { @Override public ExchangesTickersById getExchangesTickersById(String id) { - return getExchangesTickersById(id,null,null,null); + return getExchangesTickersById(id, null, null, null); } @Override public ExchangesTickersById getExchangesTickersById(String id, String coinIds, Integer page, String order) { - return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesTickersById(id,coinIds,page,order)); + return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesTickersById(id, coinIds, page, order)); } @Override public StatusUpdates getExchangesStatusUpdatesById(String id) { - return getExchangesStatusUpdatesById(id,null,null); + return getExchangesStatusUpdatesById(id, null, null); } @Override public StatusUpdates getExchangesStatusUpdatesById(String id, Integer perPage, Integer page) { - return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesStatusUpdatesById(id,perPage,page)); + return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesStatusUpdatesById(id, perPage, page)); } @Override public List> getExchangesVolumeChart(String id, Integer days) { - return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesVolumeChart(id,days)); + return coinGeckoApi.executeSync(coinGeckoApiService.getExchangesVolumeChart(id, days)); } @Deprecated @@ -215,7 +234,7 @@ public StatusUpdates getStatusUpdates() { @Deprecated @Override public StatusUpdates getStatusUpdates(String category, String projectType, Integer perPage, Integer page) { - return coinGeckoApi.executeSync(coinGeckoApiService.getStatusUpdates(category, projectType,perPage,page)); + return coinGeckoApi.executeSync(coinGeckoApiService.getStatusUpdates(category, projectType, perPage, page)); } @Deprecated @@ -227,7 +246,7 @@ public Events getEvents() { @Deprecated @Override public Events getEvents(String countryCode, String type, Integer page, boolean upcomingEventsOnly, String fromDate, String toDate) { - return coinGeckoApi.executeSync(coinGeckoApiService.getEvents(countryCode,type,page,upcomingEventsOnly,fromDate,toDate)); + return coinGeckoApi.executeSync(coinGeckoApiService.getEvents(countryCode, type, page, upcomingEventsOnly, fromDate, toDate)); } @Deprecated @@ -248,12 +267,14 @@ public ExchangeRates getExchangeRates() { } @Override - public Trending getTrending(){ + public Trending getTrending() { return coinGeckoApi.executeSync(coinGeckoApiService.getTrending()); } @Override - public Search getSearchResult(String query) {return coinGeckoApi.executeSync(coinGeckoApiService.getSearch(query));} + public Search getSearchResult(String query) { + return coinGeckoApi.executeSync(coinGeckoApiService.getSearch(query)); + } @Override public Global getGlobal() { @@ -261,7 +282,7 @@ public Global getGlobal() { } @Override - public DecentralizedFinanceDefi getDecentralizedFinanceDefi(){ + public DecentralizedFinanceDefi getDecentralizedFinanceDefi() { return coinGeckoApi.executeSync(coinGeckoApiService.getDecentralizedFinanceDefi()); } @@ -269,4 +290,4 @@ public DecentralizedFinanceDefi getDecentralizedFinanceDefi(){ public void shutdown() { coinGeckoApi.shutdown(); } -} +} \ No newline at end of file diff --git a/src/test/java/com/litesoftwares/coingecko/examples/SearchExample.java b/src/test/java/com/litesoftwares/coingecko/examples/SearchExample.java index a1b021f..a1c75e7 100644 --- a/src/test/java/com/litesoftwares/coingecko/examples/SearchExample.java +++ b/src/test/java/com/litesoftwares/coingecko/examples/SearchExample.java @@ -16,4 +16,4 @@ public static void main(String[] args) { System.out.println(search); } -} +} \ No newline at end of file