All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.sornerol.chess.pubapi.client.DailyPuzzleClient Maven / Gradle / Ivy

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy