clashofclans.js 1.5.4 → 2.0.0-dev.2c5b083

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +2 -1
  3. package/README.md +39 -110
  4. package/dist/client/Client.d.ts +177 -0
  5. package/dist/client/Client.js +237 -0
  6. package/dist/client/EventManager.d.ts +86 -0
  7. package/dist/client/EventManager.js +279 -0
  8. package/dist/index.d.ts +9 -0
  9. package/dist/index.js +21 -0
  10. package/dist/rest/HTTPError.d.ts +24 -0
  11. package/dist/rest/HTTPError.js +42 -0
  12. package/dist/rest/RESTManager.d.ts +56 -0
  13. package/dist/rest/RESTManager.js +123 -0
  14. package/dist/rest/RequestHandler.d.ts +162 -0
  15. package/dist/rest/RequestHandler.js +198 -0
  16. package/dist/rest/Throttler.d.ts +31 -0
  17. package/dist/rest/Throttler.js +86 -0
  18. package/dist/struct/Achievement.d.ts +25 -0
  19. package/dist/struct/Achievement.js +28 -0
  20. package/dist/struct/Badge.d.ts +16 -0
  21. package/dist/struct/Badge.js +27 -0
  22. package/dist/struct/ChatLanguage.d.ts +11 -0
  23. package/dist/struct/ChatLanguage.js +12 -0
  24. package/dist/struct/Clan.d.ts +64 -0
  25. package/dist/struct/Clan.js +44 -0
  26. package/dist/struct/ClanMember.d.ts +32 -0
  27. package/dist/struct/ClanMember.js +28 -0
  28. package/dist/struct/ClanWar.d.ts +137 -0
  29. package/dist/struct/ClanWar.js +198 -0
  30. package/dist/struct/ClanWarLeagueGroup.d.ts +63 -0
  31. package/dist/struct/ClanWarLeagueGroup.js +85 -0
  32. package/dist/struct/ClanWarLog.d.ts +54 -0
  33. package/dist/struct/ClanWarLog.js +46 -0
  34. package/dist/struct/Icon.d.ts +16 -0
  35. package/dist/struct/Icon.js +27 -0
  36. package/dist/struct/Label.d.ts +12 -0
  37. package/dist/struct/Label.js +13 -0
  38. package/dist/struct/League.d.ts +14 -0
  39. package/dist/struct/League.js +18 -0
  40. package/dist/struct/LegendStatistics.d.ts +18 -0
  41. package/dist/struct/LegendStatistics.js +17 -0
  42. package/dist/struct/Location.d.ts +15 -0
  43. package/dist/struct/Location.js +14 -0
  44. package/dist/struct/Player.d.ts +78 -0
  45. package/dist/struct/Player.js +72 -0
  46. package/dist/struct/PlayerClan.d.ts +19 -0
  47. package/dist/struct/PlayerClan.js +19 -0
  48. package/dist/struct/Ranking.d.ts +58 -0
  49. package/dist/struct/Ranking.js +50 -0
  50. package/dist/struct/Season.d.ts +19 -0
  51. package/dist/struct/Season.js +21 -0
  52. package/dist/struct/Unit.d.ts +68 -0
  53. package/dist/struct/Unit.js +90 -0
  54. package/dist/struct/WarLeague.d.ts +11 -0
  55. package/dist/struct/WarLeague.js +16 -0
  56. package/dist/struct/index.d.ts +19 -0
  57. package/dist/struct/index.js +31 -0
  58. package/dist/types/index.d.ts +350 -0
  59. package/dist/types/index.js +2 -0
  60. package/dist/util/Constants.d.ts +41 -0
  61. package/dist/util/Constants.js +122 -0
  62. package/dist/util/Util.d.ts +18 -0
  63. package/dist/util/Util.js +53 -0
  64. package/dist/util/raw.json +1 -0
  65. package/package.json +109 -36
  66. package/src/index.d.ts +0 -811
  67. package/src/index.js +0 -5
  68. package/src/struct/Client.js +0 -481
  69. package/src/util/Extension.js +0 -130
@@ -0,0 +1,86 @@
1
+ import { Clan, ClanWar, Player } from '../struct';
2
+ import { Client } from './Client';
3
+ /** Represents Event Manager of the {@link Client}. */
4
+ export declare class EventManager {
5
+ private readonly client;
6
+ private readonly _clanTags;
7
+ private readonly _playerTags;
8
+ private readonly _warTags;
9
+ private readonly _clans;
10
+ private readonly _players;
11
+ private readonly _wars;
12
+ private readonly _events;
13
+ private _inMaintenance;
14
+ private _maintenanceStartTime;
15
+ constructor(client: Client);
16
+ /** Initialize the Event Manager to start pulling. */
17
+ init(): Promise<string[]>;
18
+ /** Add clan tags to clan events. */
19
+ addClans(tags: string[] | string): this;
20
+ /** Delete clan tags from clan events. */
21
+ deleteClans(tags: string[] | string): this;
22
+ /** Add player tags for player events. */
23
+ addPlayers(tags: string[] | string): this;
24
+ /** Delete player tags from player events. */
25
+ deletePlayers(tags: string[] | string): this;
26
+ /** Add clan tags for war events. */
27
+ addWars(tags: string[] | string): this;
28
+ /** Delete clan tags from war events. */
29
+ deleteWars(tags: string[] | string): this;
30
+ /**
31
+ * Set your own custom clan event.
32
+ *
33
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
34
+ *
35
+ * @example
36
+ * ```js
37
+ * client.events.addClans(['#2PP', '#8QU8J9LP']);
38
+ *
39
+ * client.events.setClanEvent({
40
+ * name: 'clanMemberUpdate',
41
+ * filter: (oldClan, newClan) => {
42
+ * return oldClan.memberCount !== newClan.memberCount;
43
+ * }
44
+ * });
45
+ *
46
+ * client.on('clanMemberUpdate', (oldClan, newClan) => {
47
+ * console.log(oldClan.memberCount, newClan.memberCount);
48
+ * });
49
+ *
50
+ * (async function () {
51
+ * await client.events.init();
52
+ * })();
53
+ * ```
54
+ * @returns
55
+ */
56
+ setClanEvent(event: {
57
+ name: string;
58
+ filter: (oldClan: Clan, newClan: Clan) => boolean;
59
+ }): this;
60
+ /**
61
+ * Set your own custom war event.
62
+ *
63
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
64
+ */
65
+ setWarEvent(event: {
66
+ name: string;
67
+ filter: (oldWar: ClanWar, newWar: ClanWar) => boolean;
68
+ }): this;
69
+ /**
70
+ * Set your own custom player event.
71
+ *
72
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
73
+ */
74
+ setPlayerEvent(event: {
75
+ name: string;
76
+ filter: (oldPlayer: Player, newPlayer: Player) => boolean;
77
+ }): this;
78
+ private maintenanceHandler;
79
+ private seasonEndHandler;
80
+ private clanUpdateHandler;
81
+ private playerUpdateHandler;
82
+ private warUpdateHandler;
83
+ private runClanUpdate;
84
+ private runPlayerUpdate;
85
+ private runWarUpdate;
86
+ }
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventManager = void 0;
4
+ const HTTPError_1 = require("../rest/HTTPError");
5
+ const Constants_1 = require("../util/Constants");
6
+ const Util_1 = require("../util/Util");
7
+ /** Represents Event Manager of the {@link Client}. */
8
+ class EventManager {
9
+ constructor(client) {
10
+ this.client = client;
11
+ this._clanTags = new Set();
12
+ this._playerTags = new Set();
13
+ this._warTags = new Set();
14
+ this._clans = new Map();
15
+ this._players = new Map();
16
+ this._wars = new Map();
17
+ this._events = {
18
+ clans: [],
19
+ wars: [],
20
+ players: []
21
+ };
22
+ this._inMaintenance = Boolean(false);
23
+ this._maintenanceStartTime = null;
24
+ }
25
+ /** Initialize the Event Manager to start pulling. */
26
+ async init() {
27
+ this.seasonEndHandler();
28
+ this.maintenanceHandler();
29
+ this.clanUpdateHandler();
30
+ this.playerUpdateHandler();
31
+ this.warUpdateHandler();
32
+ return Promise.resolve(this.client.eventNames());
33
+ }
34
+ /** Add clan tags to clan events. */
35
+ addClans(tags) {
36
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
37
+ this._clanTags.add(this.client.util.parseTag(tag));
38
+ }
39
+ return this;
40
+ }
41
+ /** Delete clan tags from clan events. */
42
+ deleteClans(tags) {
43
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
44
+ const key = this.client.util.parseTag(tag);
45
+ this._clans.delete(key);
46
+ this._clanTags.delete(key);
47
+ }
48
+ return this;
49
+ }
50
+ /** Add player tags for player events. */
51
+ addPlayers(tags) {
52
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
53
+ this._playerTags.add(this.client.util.parseTag(tag));
54
+ }
55
+ return this;
56
+ }
57
+ /** Delete player tags from player events. */
58
+ deletePlayers(tags) {
59
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
60
+ const key = this.client.util.parseTag(tag);
61
+ this._players.delete(key);
62
+ this._playerTags.delete(key);
63
+ }
64
+ return this;
65
+ }
66
+ /** Add clan tags for war events. */
67
+ addWars(tags) {
68
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
69
+ this._warTags.add(this.client.util.parseTag(tag));
70
+ }
71
+ return this;
72
+ }
73
+ /** Delete clan tags from war events. */
74
+ deleteWars(tags) {
75
+ for (const tag of Array.isArray(tags) ? tags : [tags]) {
76
+ const key = this.client.util.parseTag(tag);
77
+ this._wars.delete(`${key}:${1}`);
78
+ this._wars.delete(`${key}:${2}`);
79
+ this._warTags.delete(key);
80
+ }
81
+ return this;
82
+ }
83
+ /**
84
+ * Set your own custom clan event.
85
+ *
86
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
87
+ *
88
+ * @example
89
+ * ```js
90
+ * client.events.addClans(['#2PP', '#8QU8J9LP']);
91
+ *
92
+ * client.events.setClanEvent({
93
+ * name: 'clanMemberUpdate',
94
+ * filter: (oldClan, newClan) => {
95
+ * return oldClan.memberCount !== newClan.memberCount;
96
+ * }
97
+ * });
98
+ *
99
+ * client.on('clanMemberUpdate', (oldClan, newClan) => {
100
+ * console.log(oldClan.memberCount, newClan.memberCount);
101
+ * });
102
+ *
103
+ * (async function () {
104
+ * await client.events.init();
105
+ * })();
106
+ * ```
107
+ * @returns
108
+ */
109
+ setClanEvent(event) {
110
+ if (!event.name)
111
+ throw new Error('Event name is required.');
112
+ if (typeof event.filter !== 'function')
113
+ throw new Error('Filter function is required.');
114
+ this._events.clans.push(event);
115
+ return this;
116
+ }
117
+ /**
118
+ * Set your own custom war event.
119
+ *
120
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
121
+ */
122
+ setWarEvent(event) {
123
+ if (!event.name)
124
+ throw new Error('Event name is required.');
125
+ if (typeof event.filter !== 'function')
126
+ throw new Error('Filter function is required.');
127
+ this._events.wars.push(event);
128
+ return this;
129
+ }
130
+ /**
131
+ * Set your own custom player event.
132
+ *
133
+ * In order to emit the custom event, you must have this filter function that returns a boolean.
134
+ */
135
+ setPlayerEvent(event) {
136
+ if (!event.name)
137
+ throw new Error('Event name is required.');
138
+ if (typeof event.filter !== 'function')
139
+ throw new Error('Filter function is required.');
140
+ this._events.players.push(event);
141
+ return this;
142
+ }
143
+ async maintenanceHandler() {
144
+ setTimeout(this.maintenanceHandler.bind(this), 10000).unref();
145
+ try {
146
+ const res = await this.client.rest.getClans({ maxMembers: Math.floor(Math.random() * 40) + 10, limit: 1 });
147
+ if (res.status === 200 && this._inMaintenance) {
148
+ this._inMaintenance = Boolean(false);
149
+ const duration = Date.now() - this._maintenanceStartTime.getTime();
150
+ this._maintenanceStartTime = null;
151
+ this.client.emit(Constants_1.EVENTS.MAINTENANCE_END, duration);
152
+ }
153
+ }
154
+ catch (error) {
155
+ if (error instanceof HTTPError_1.HTTPError && error.status === 503 && !this._inMaintenance) {
156
+ this._inMaintenance = Boolean(true);
157
+ this._maintenanceStartTime = new Date();
158
+ this.client.emit(Constants_1.EVENTS.MAINTENANCE_START);
159
+ }
160
+ }
161
+ }
162
+ seasonEndHandler() {
163
+ const end = Util_1.Util.getSeasonEndTime().getTime() - Date.now();
164
+ // Why this? setTimeout can be up to 24.8 days or 2147483647ms [(2^31 - 1) Max 32bit Integer]
165
+ if (end > 24 * 60 * 60 * 1000) {
166
+ setTimeout(this.seasonEndHandler.bind(this), 60 * 60 * 1000).unref();
167
+ }
168
+ else if (end > 0) {
169
+ setTimeout(() => {
170
+ this.client.emit(Constants_1.EVENTS.NEW_SEASON_START, Util_1.Util.getSeasonId());
171
+ }, end + 100).unref();
172
+ }
173
+ }
174
+ async clanUpdateHandler() {
175
+ this.client.emit(Constants_1.EVENTS.CLAN_LOOP_START);
176
+ for (const tag of this._clanTags)
177
+ await this.runClanUpdate(tag);
178
+ this.client.emit(Constants_1.EVENTS.CLAN_LOOP_END);
179
+ setTimeout(this.clanUpdateHandler.bind(this), 10000).unref();
180
+ }
181
+ async playerUpdateHandler() {
182
+ this.client.emit(Constants_1.EVENTS.PLAYER_LOOP_START);
183
+ for (const tag of this._playerTags)
184
+ await this.runPlayerUpdate(tag);
185
+ this.client.emit(Constants_1.EVENTS.PLAYER_LOOP_END);
186
+ setTimeout(this.playerUpdateHandler.bind(this), 10000).unref();
187
+ }
188
+ async warUpdateHandler() {
189
+ this.client.emit(Constants_1.EVENTS.WAR_LOOP_START);
190
+ for (const tag of this._warTags)
191
+ await this.runWarUpdate(tag);
192
+ this.client.emit(Constants_1.EVENTS.WAR_LOOP_END);
193
+ setTimeout(this.warUpdateHandler.bind(this), 10000).unref();
194
+ }
195
+ async runClanUpdate(tag) {
196
+ if (this._inMaintenance)
197
+ return null;
198
+ const clan = await this.client.getClan(tag).catch(() => null);
199
+ if (!clan)
200
+ return null;
201
+ const cached = this._clans.get(clan.tag);
202
+ if (!cached)
203
+ return this._clans.set(clan.tag, clan);
204
+ for (const { name, filter } of this._events.clans) {
205
+ try {
206
+ if (!filter(cached, clan))
207
+ continue;
208
+ this.client.emit(name, cached, clan);
209
+ }
210
+ catch (error) {
211
+ this.client.emit(Constants_1.EVENTS.ERROR, error);
212
+ }
213
+ }
214
+ return this._clans.set(clan.tag, clan);
215
+ }
216
+ async runPlayerUpdate(tag) {
217
+ if (this._inMaintenance)
218
+ return null;
219
+ const player = await this.client.getPlayer(tag).catch(() => null);
220
+ if (!player)
221
+ return null;
222
+ const cached = this._players.get(player.tag);
223
+ if (!cached)
224
+ return this._players.set(player.tag, player);
225
+ for (const { name, filter } of this._events.players) {
226
+ try {
227
+ if (!filter(cached, player))
228
+ continue;
229
+ this.client.emit(name, cached, player);
230
+ }
231
+ catch (error) {
232
+ this.client.emit(Constants_1.EVENTS.ERROR, error);
233
+ }
234
+ }
235
+ return this._players.set(player.tag, player);
236
+ }
237
+ async runWarUpdate(tag) {
238
+ if (this._inMaintenance)
239
+ return null;
240
+ // @ts-expect-error
241
+ const clanWars = await this.client._getClanWars(tag).catch(() => null);
242
+ if (!clanWars?.length)
243
+ return null;
244
+ clanWars.forEach(async (war, index) => {
245
+ const key = `${tag}:${index}`;
246
+ const cached = this._wars.get(key);
247
+ if (!cached)
248
+ return this._wars.set(key, war);
249
+ for (const { name, filter } of this._events.wars) {
250
+ try {
251
+ if (!filter(cached, war))
252
+ continue;
253
+ this.client.emit(name, cached, war);
254
+ }
255
+ catch (error) {
256
+ this.client.emit(Constants_1.EVENTS.ERROR, error);
257
+ }
258
+ }
259
+ // check for war end
260
+ if (index === 1 && cached.warTag !== war.warTag) {
261
+ const data = await this.client.getLeagueWar({ clanTag: tag, round: 'PREVIOUS_ROUND' }).catch(() => null);
262
+ if (data && data.warTag === cached.warTag) {
263
+ for (const { name, filter } of this._events.wars) {
264
+ try {
265
+ if (!filter(cached, data))
266
+ continue;
267
+ this.client.emit(name, cached, data);
268
+ }
269
+ catch (error) {
270
+ this.client.emit(Constants_1.EVENTS.ERROR, error);
271
+ }
272
+ }
273
+ }
274
+ }
275
+ return this._wars.set(key, war);
276
+ });
277
+ }
278
+ }
279
+ exports.EventManager = EventManager;
@@ -0,0 +1,9 @@
1
+ export * from './client/Client';
2
+ export * from './rest/RESTManager';
3
+ export * from './rest/RequestHandler';
4
+ export * from './rest/HTTPError';
5
+ export * from './client/EventManager';
6
+ export * from './rest/Throttler';
7
+ export * from './util/Util';
8
+ export * from './struct';
9
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./client/Client"), exports);
14
+ __exportStar(require("./rest/RESTManager"), exports);
15
+ __exportStar(require("./rest/RequestHandler"), exports);
16
+ __exportStar(require("./rest/HTTPError"), exports);
17
+ __exportStar(require("./client/EventManager"), exports);
18
+ __exportStar(require("./rest/Throttler"), exports);
19
+ __exportStar(require("./util/Util"), exports);
20
+ __exportStar(require("./struct"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,24 @@
1
+ /** Represents an HTTP Error. */
2
+ export declare class HTTPError extends Error {
3
+ /** The message of this error. */
4
+ message: string;
5
+ /** The HTTP method of this request. */
6
+ method: string;
7
+ /** The reason of this error. */
8
+ reason: string;
9
+ /** The HTTP status code of this request. */
10
+ status: number;
11
+ /** The path of this request. */
12
+ path: string;
13
+ /** Maximum number of milliseconds the results can be cached. */
14
+ maxAge: number;
15
+ constructor(error: any, status: number, path: string, maxAge: number, method?: string);
16
+ }
17
+ export declare const NotInWarError: {
18
+ message: string;
19
+ reason: string;
20
+ };
21
+ export declare const PrivateWarLogError: {
22
+ message: string;
23
+ reason: string;
24
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrivateWarLogError = exports.NotInWarError = exports.HTTPError = void 0;
4
+ const messages = {
5
+ 500: 'Unknown error happened when handling the request.',
6
+ 504: 'The user aborted this request.',
7
+ 404: 'Requested resource was not found.',
8
+ 400: 'Client provided incorrect parameters for the request.',
9
+ 503: 'Service is temporarily unavailable because of maintenance.',
10
+ 429: 'Request was throttled, because amount of requests was above the threshold defined for the used API token.',
11
+ 403: 'Access denied, either because of missing/incorrect credentials or used API token does not grant access to the requested resource.'
12
+ };
13
+ const reasons = {
14
+ 503: 'serviceUnavailable',
15
+ 429: 'tooManyRequests',
16
+ 400: 'badRequest',
17
+ 403: 'forbidden',
18
+ 500: 'unknownError',
19
+ 404: 'notFound',
20
+ 504: 'requestAborted'
21
+ };
22
+ /** Represents an HTTP Error. */
23
+ class HTTPError extends Error {
24
+ constructor(error, status, path, maxAge, method) {
25
+ super();
26
+ this.message = error?.message ?? messages[status];
27
+ this.reason = error?.reason ?? reasons[status];
28
+ this.path = path;
29
+ this.method = method ?? 'GET';
30
+ this.status = status;
31
+ this.maxAge = maxAge;
32
+ }
33
+ }
34
+ exports.HTTPError = HTTPError;
35
+ exports.NotInWarError = {
36
+ message: 'Clan is not in war at this moment.',
37
+ reason: 'notInWar'
38
+ };
39
+ exports.PrivateWarLogError = {
40
+ message: 'Access denied, clan war log is private.',
41
+ reason: 'privateWarLog'
42
+ };
@@ -0,0 +1,56 @@
1
+ import { RequestHandler, SearchOptions, ClanSearchOptions, ClientOptions, OverrideOptions } from './RequestHandler';
2
+ import { APIClan, APIClanList, APIClanMemberList, APIClanRankingList, APIClanVersusRankingList, APIClanWar, APIClanWarLeagueGroup, APIClanWarLog, APIGoldPassSeason, APILabelList, APILeague, APILeagueList, APILeagueSeasonList, APILocation, APILocationList, APIPlayer, APIPlayerRankingList, APIPlayerSeasonRankingList, APIPlayerVersusRankingList, APIVerifyToken, APIWarLeague, APIWarLeagueList } from '../types';
3
+ /** Represents a REST Manager of the client. */
4
+ export declare class RESTManager {
5
+ /** Request Handler for the RESTManager. */
6
+ readonly handler: RequestHandler;
7
+ constructor(options?: ClientOptions);
8
+ /** Search all clans by name and/or filtering the results using various criteria. */
9
+ getClans(options: ClanSearchOptions): Promise<import("./RequestHandler").Response<APIClanList>>;
10
+ /** Get information about a clan. */
11
+ getClan(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClan>>;
12
+ /** Get list of clan members. */
13
+ getClanMembers(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanMemberList>>;
14
+ /** Get clan war log. */
15
+ getClanWarLog(clanTag: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanWarLog>>;
16
+ /** Get info about currently running war in the clan. */
17
+ getCurrentWar(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
18
+ /** Get information about clan war league. */
19
+ getClanWarLeagueGroup(clanTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWarLeagueGroup>>;
20
+ /** Get info about a CWL round by WarTag. */
21
+ getClanWarLeagueRound(warTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIClanWar>>;
22
+ /** Get information about a player by tag. */
23
+ getPlayer(playerTag: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIPlayer>>;
24
+ /** Verify Player API token that can be found from the Game settings. */
25
+ verifyPlayerToken(playerTag: string, token: string, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIVerifyToken>>;
26
+ /** Get list of Leagues. */
27
+ getLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueList>>;
28
+ /** Get a League info. */
29
+ getLeague(leagueId: string | number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILeague>>;
30
+ /** Get Legend League season Ids. */
31
+ getLeagueSeasons(leagueId: number, options?: SearchOptions): Promise<import("./RequestHandler").Response<APILeagueSeasonList>>;
32
+ /** Get Legend League season rankings by season Id. */
33
+ getSeasonRankings(leagueId: number, seasonId: string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerSeasonRankingList>>;
34
+ /** Get list of Clan War Leagues. */
35
+ getWarLeagues(options?: SearchOptions): Promise<import("./RequestHandler").Response<APIWarLeagueList>>;
36
+ /** Get info about a Clan War League. */
37
+ getWarLeague(leagueId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIWarLeague>>;
38
+ /** Get list of Locations. */
39
+ getLocations(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILocationList>>;
40
+ /** Get info about a Location. */
41
+ getLocation(locationId: number, options?: OverrideOptions): Promise<import("./RequestHandler").Response<APILocation>>;
42
+ /** Get clan rankings for a specific location. */
43
+ getClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanRankingList>>;
44
+ /** Get player rankings for a specific location. */
45
+ getPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerRankingList>>;
46
+ /** Get clan versus rankings for a specific location. */
47
+ getVersusClanRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIClanVersusRankingList>>;
48
+ /** Get player versus rankings for a specific location. */
49
+ getVersusPlayerRanks(locationId: number | string, options?: SearchOptions): Promise<import("./RequestHandler").Response<APIPlayerVersusRankingList>>;
50
+ /** Get list of clan labels. */
51
+ getClanLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
52
+ /** Get list of player labels. */
53
+ getPlayerLabels(options?: SearchOptions): Promise<import("./RequestHandler").Response<APILabelList>>;
54
+ /** Get info about gold pass season. */
55
+ getGoldPassSeason(options?: OverrideOptions): Promise<import("./RequestHandler").Response<APIGoldPassSeason>>;
56
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESTManager = void 0;
4
+ const RequestHandler_1 = require("./RequestHandler");
5
+ const Util_1 = require("../util/Util");
6
+ /** Represents a REST Manager of the client. */
7
+ class RESTManager {
8
+ constructor(options) {
9
+ this.handler = new RequestHandler_1.RequestHandler(options);
10
+ }
11
+ /** Search all clans by name and/or filtering the results using various criteria. */
12
+ getClans(options) {
13
+ const query = Util_1.Util.queryString(options);
14
+ return this.handler.request(`/clans?${query}`);
15
+ }
16
+ /** Get information about a clan. */
17
+ getClan(clanTag, options) {
18
+ return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}`, options);
19
+ }
20
+ /** Get list of clan members. */
21
+ getClanMembers(clanTag, options) {
22
+ const query = Util_1.Util.queryString(options);
23
+ return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/members?${query}`, options);
24
+ }
25
+ /** Get clan war log. */
26
+ getClanWarLog(clanTag, options) {
27
+ const query = Util_1.Util.queryString(options);
28
+ return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/warlog?${query}`, options);
29
+ }
30
+ /** Get info about currently running war in the clan. */
31
+ getCurrentWar(clanTag, options) {
32
+ return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/currentwar`, options);
33
+ }
34
+ /** Get information about clan war league. */
35
+ getClanWarLeagueGroup(clanTag, options) {
36
+ return this.handler.request(`/clans/${Util_1.Util.encodeTag(clanTag)}/currentwar/leaguegroup`, options);
37
+ }
38
+ /** Get info about a CWL round by WarTag. */
39
+ getClanWarLeagueRound(warTag, options) {
40
+ return this.handler.request(`/clanwarleagues/wars/${Util_1.Util.encodeTag(warTag)}`, options);
41
+ }
42
+ /** Get information about a player by tag. */
43
+ getPlayer(playerTag, options) {
44
+ return this.handler.request(`/players/${Util_1.Util.encodeTag(playerTag)}`, options);
45
+ }
46
+ /** Verify Player API token that can be found from the Game settings. */
47
+ verifyPlayerToken(playerTag, token, options) {
48
+ const opts = { method: 'POST', body: JSON.stringify({ token }), ...options };
49
+ return this.handler.request(`/players/${Util_1.Util.encodeTag(playerTag)}/verifytoken`, opts);
50
+ }
51
+ /** Get list of Leagues. */
52
+ getLeagues(options) {
53
+ const query = Util_1.Util.queryString(options);
54
+ return this.handler.request(`/leagues?${query}`, options);
55
+ }
56
+ /** Get a League info. */
57
+ getLeague(leagueId, options) {
58
+ return this.handler.request(`/leagues/${leagueId}`, options);
59
+ }
60
+ /** Get Legend League season Ids. */
61
+ getLeagueSeasons(leagueId, options) {
62
+ const query = Util_1.Util.queryString(options);
63
+ return this.handler.request(`/leagues/${leagueId}/seasons?${query}`, options);
64
+ }
65
+ /** Get Legend League season rankings by season Id. */
66
+ getSeasonRankings(leagueId, seasonId, options) {
67
+ const query = Util_1.Util.queryString(options);
68
+ return this.handler.request(`/leagues/${leagueId}/seasons/${seasonId}?${query}`, options);
69
+ }
70
+ /** Get list of Clan War Leagues. */
71
+ getWarLeagues(options) {
72
+ const query = Util_1.Util.queryString(options);
73
+ return this.handler.request(`/warleagues?${query}`, options);
74
+ }
75
+ /** Get info about a Clan War League. */
76
+ getWarLeague(leagueId, options) {
77
+ return this.handler.request(`/warleagues/${leagueId}`, options);
78
+ }
79
+ /** Get list of Locations. */
80
+ getLocations(options) {
81
+ const query = Util_1.Util.queryString(options);
82
+ return this.handler.request(`/locations?${query}`, options);
83
+ }
84
+ /** Get info about a Location. */
85
+ getLocation(locationId, options) {
86
+ return this.handler.request(`/locations/${locationId}`, options);
87
+ }
88
+ /** Get clan rankings for a specific location. */
89
+ getClanRanks(locationId, options) {
90
+ const query = Util_1.Util.queryString(options);
91
+ return this.handler.request(`/locations/${locationId}/rankings/clans?${query}`, options);
92
+ }
93
+ /** Get player rankings for a specific location. */
94
+ getPlayerRanks(locationId, options) {
95
+ const query = Util_1.Util.queryString(options);
96
+ return this.handler.request(`/locations/${locationId}/rankings/players?${query}`, options);
97
+ }
98
+ /** Get clan versus rankings for a specific location. */
99
+ getVersusClanRanks(locationId, options) {
100
+ const query = Util_1.Util.queryString(options);
101
+ return this.handler.request(`/locations/${locationId}/rankings/clans-versus?${query}`, options);
102
+ }
103
+ /** Get player versus rankings for a specific location. */
104
+ getVersusPlayerRanks(locationId, options) {
105
+ const query = Util_1.Util.queryString(options);
106
+ return this.handler.request(`/locations/${locationId}/rankings/players-versus?${query}`, options);
107
+ }
108
+ /** Get list of clan labels. */
109
+ getClanLabels(options) {
110
+ const query = Util_1.Util.queryString(options);
111
+ return this.handler.request(`/labels/clans?${query}`, options);
112
+ }
113
+ /** Get list of player labels. */
114
+ getPlayerLabels(options) {
115
+ const query = Util_1.Util.queryString(options);
116
+ return this.handler.request(`/labels/players?${query}`, options);
117
+ }
118
+ /** Get info about gold pass season. */
119
+ getGoldPassSeason(options) {
120
+ return this.handler.request('/goldpass/seasons/current', options);
121
+ }
122
+ }
123
+ exports.RESTManager = RESTManager;