A Java wrapper for Chess.com's public data API (PubAPI)
Follow these directions to get up-and-running with the Chess.com API wrapper.
To get started, add chesscom-pubapi-wrapper
to your project's dependencies.
Add the following dependency to the dependencies section of your project's pom.xml
file:
<dependencies>
<!-- Other project dependencies -->
<dependency>
<groupId>io.github.sornerol</groupId>
<artifactId>chesscom-pubapi-wrapper</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies
Add the following dependency to the dependencies section of your project's build.gradle
file:
dependencies {
// other project dependencies...
implementation 'io.github.sornerol:chesscom-pubapi-wrapper:1.7.0'
}
The API wrapper consists of different clients, which correspond to different API endpoints within Chess.com's PubAPI:
- ClubClient
- CountryClient
- DailyPuzzleClient
- LeaderboardsClient
- PlayerClient
- StreamersClient
- TeamMatchClient
- TournamentClient
A complete description of these clients is available in the Javadocs.
For our example, let's create a new PlayerClient to retrieve information about a player:
import io.github.sornerol.chess.pubapi.client.PlayerClient;
import io.github.sornerol.chess.pubapi.domain.player.Player;
import io.github.sornerol.chess.pubapi.exception.ChessComPubApiException;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws ChessComPubApiException, IOException {
PlayerClient client = new PlayerClient();
/*
* Setting a user agent with your application name and your contact info is highly recommended in case Chess.com
* needs to block your application due to abnormal or suspicious activity.
*/
client.setUserAgent("My Chess App; username: lrj825; contact: lrj825@example.com");
Player player = client.getPlayerByUsername("erik");
System.out.println(player.toString());
}
}
Chess.com adds new fields to the PubAPI from time to time. If there is a new field in the API you need access to, feel free to open an issue. I can usually have the new field added within a day or two.
If you're interested in helping out, start by reviewing CONTRIBUTING.md. All help is appreciated!