io.github.sornerol.chess.pubapi.client.DailyPuzzleClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chesscom-pubapi-wrapper Show documentation
Show all versions of chesscom-pubapi-wrapper Show documentation
A wrapper for Chess.com's PubAPI.
The newest version!
package io.github.sornerol.chess.pubapi.client;
import io.github.sornerol.chess.pubapi.domain.puzzle.DailyPuzzle;
import io.github.sornerol.chess.pubapi.exception.ChessComPubApiException;
import java.io.IOException;
/**
* Client for fetching daily puzzles.
*
* @see Chess.com PubAPI documentation
*/
public class DailyPuzzleClient extends PubApiClientBase {
private static final String ENDPOINT_BASE = "https://api.chess.com/pub/puzzle";
/**
* Fetch today's daily puzzle
*
* @return Today's {@link DailyPuzzle}.
* @throws IOException if there is a problem connecting to Chess.com.
* @throws ChessComPubApiException if Chess.com returns a non-success response code.
* @see Chess.com PubAPI documentation
*/
public DailyPuzzle getTodaysDailyPuzzle() throws IOException, ChessComPubApiException {
return getRequest(ENDPOINT_BASE, DailyPuzzle.class);
}
/**
* Fetch a random daily puzzle. Note that, according to Chess.com's API documentation, this endpoint has around 15 seconds
* of caching latency.
*
* @return A random {@link DailyPuzzle}.
* @throws IOException if there is a problem connecting to Chess.com.
* @throws ChessComPubApiException if Chess.com returns a non-success response code.
* @see Chess.com PubAPI documentation
*/
public DailyPuzzle getRandomDailyPuzzle() throws IOException, ChessComPubApiException {
return getRequest(ENDPOINT_BASE + "/random", DailyPuzzle.class);
}
}