UNPKG

@varandas/clash-royale-api

Version:

A Clash Royale API official wrapper for seamless integration with your applications.

194 lines 6.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClashRoyaleAPI = void 0; const communications_1 = require("./communications"); const endpoints_1 = require("./endpoints"); /** * @namespace ClashRoyaleAPI * * @class ClashRoyaleAPI */ class ClashRoyaleAPI { apiClient; /** * Initializes the axios instance with the token * from the developer site https://developer.clashroyale.com * * @param {string} token - The api token from https://developer.clashroyale.com * @param {string} baseUrl - The base url for the api (optional) */ constructor(token, baseUrl) { this.apiClient = (0, communications_1.getAxiosInstance)(token, baseUrl); } /** * Search all clans by name and/or filtering the results using various criteria. * * @param {object:IClanRequestParams} params - Object used to filter results. */ async getClans(params) { return await (0, endpoints_1.getClans)(params, this.apiClient); } /** * Get information about a single clan by clan tag. * Clan tags can be found using clan search operation. * * @param {string} tag */ async getClanByTag(tag) { return await (0, endpoints_1.getClanByTag)(tag, this.apiClient); } /** * List clan members * * @param {string} tag */ async getClanMembers(tag) { return await (0, endpoints_1.getClanMembers)(tag, this.apiClient); } /** * Retrieve clan's clan war log * * @param {string} tag */ async getClanWarlog(tag) { return await (0, endpoints_1.getClanWarlog)(tag, this.apiClient); } /** * Retrieve information about clan's current clan war * * Note: * When ICurrentWar.warEndTime is undefined, the war is still in collection. * Search for ICurrentWar.collectionEndTime instead * * @param {string} tag */ async getClanCurrentWar(tag) { return await (0, endpoints_1.getClanCurrentWar)(tag, this.apiClient); } /** * Retrieve information about clan's current river race * * Note: * When ICurrentWar.warEndTime is undefined, the war is still in collection. * Search for ICurrentWar.collectionEndTime instead * * @param {string} tag */ async getClanCurrentRiverRace(tag) { return await (0, endpoints_1.getClanCurrentRiverRace)(tag, this.apiClient); } /** * Get information about a single player by player tag. * Player tags can be found either in game or by from clan member lists. * * @param {string} tag */ getPlayerByTag = async (tag) => { return await (0, endpoints_1.getPlayerByTag)(tag, this.apiClient); }; /** * Get list of reward chests that the player will receive next in the game. * * @param {string} tag */ getPlayerUpcomingChests = async (tag) => { return await (0, endpoints_1.getPlayerUpcomingChests)(tag, this.apiClient); }; /** * Get list of recent battle results for a player. * * @param {string} tag */ getPlayerBattleLog = async (tag) => { return await (0, endpoints_1.getPlayerBattleLog)(tag, this.apiClient); }; /** * Search all tournaments by name. * * @param {object:ITournamentRequestParams} params */ getTournaments = async (params) => { return await (0, endpoints_1.getTournaments)(params, this.apiClient); }; /** * Get information about a single tournament by a tournament tag. * * @param {string} tag */ getTournamentByTag = async (tag) => { return await (0, endpoints_1.getTournamentByTag)(tag, this.apiClient); }; /** * List all available global tournaments. */ getGlobalTournaments = async () => { return await (0, endpoints_1.getGlobalTournaments)(this.apiClient); }; /** * Get list of all available cards. */ async getCards() { return await (0, endpoints_1.getCards)(this.apiClient); } /** * List all available locations * * @param {ILocationRequestParams} params */ async getLocations(params) { return await (0, endpoints_1.getLocations)(params, this.apiClient); } /** * Get information about specific location * * @param {string} id * @param {ILocationFullRequestParams} params */ async getLocationById(id) { return await (0, endpoints_1.getLocationById)(id, this.apiClient); } /** * Get clan rankings for a specific location. * * @param {string} id * @param {ILocationFullRequestParams} params */ async getClanRankinsForLocation(id, params) { return await (0, endpoints_1.getClanRankingsForLocation)(id, params, this.apiClient); } /** * Get player rankings for a specific location * * @param {string} id * @param {ILocationFullRequestParams} params */ async getPlayerRankingsForLocation(id, params) { return await (0, endpoints_1.getPlayerRankingsForLocation)(id, params, this.apiClient); } /** * Get clan rankings for a specific location * * @param {string} id * @param {ILocationFullRequestParams} params */ async getClanWarRankingsForLocation(id, params) { return await (0, endpoints_1.getClanRankingsForLocation)(id, params, this.apiClient); } /** * List leaderboards for different trophy roads. */ async getLeaderboards() { return await (0, endpoints_1.getLeaderboards)(this.apiClient); } /** * Get players on a specific leaderboard. * * @param {number} leaderboardId * @param {ILeaderboardRequestParams} params */ async getLeaderboardById(leaderboardId, params = {}) { return await (0, endpoints_1.getLeaderboardById)(leaderboardId, params, this.apiClient); } } exports.ClashRoyaleAPI = ClashRoyaleAPI; //# sourceMappingURL=index.js.map