chesscom-ts-client
Version:
A TypeScript client for the Chess.com API
108 lines (107 loc) • 4.21 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChessComClient = void 0;
const axios_1 = __importDefault(require("axios"));
class ChessComClient {
constructor() {
this.axiosInstance = axios_1.default.create({
baseURL: "https://api.chess.com/pub",
headers: {
"User-Agent": "chesscom-ts-client/0.0.1 (https://github.com/jeffgodwyll/chesscom-ts-client)", // Replace with your project details
},
});
}
/**
* Get a player's public profile.
* @param username The username of the player.
*/
getPlayerProfile(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}`);
return response.data;
});
}
/**
* Get a player's stats.
* @param username The username of the player.
*/
getPlayerStats(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/stats`);
return response.data;
});
}
/**
* Get a list of a player's games.
* @param username The username of the player.
*/
getPlayerGames(username, year, monthString) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/games/${year}/${monthString}`);
return response.data;
});
}
/**
* Get a list of a player's monthly archives.
* @param username The username of the player.
*/
getPlayerMonthlyArchives(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/games/archives`);
return response.data;
});
}
/**
* Get a list of a player's games to move.
* @param username The username of the player.
*/
getPlayerGamesToMove(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/games/to-move`);
return response.data;
});
}
/**
* Get a list of clubs a player is in.
* @param username The username of the player.
*/
getPlayerClubs(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/clubs`);
return response.data;
});
}
/**
* Get a list of team matches a player is in.
* @param username The username of the player.
*/
getPlayerTeamMatches(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/matches`);
return response.data;
});
}
/**
* Get a list of tournaments a player is in.
* @param username The username of the player.
*/
getPlayerTournaments(username) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(`/player/${username}/tournaments`);
return response.data;
});
}
}
exports.ChessComClient = ChessComClient;