File tree Expand file tree Collapse file tree 7 files changed +137
-0
lines changed Expand file tree Collapse file tree 7 files changed +137
-0
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,11 @@ All api calls are asynchronous and used in the same way as above in the getCards
113113- ` getPlayerRankingsForLocation(id: string, params: ILocationFullRequestParams) ` - Get player rankings for a specific location.
114114- ` getClanWarRankingsForLocation(id: string, params: ILocationFullRequestParams) ` - Get clan rankings for a specific location.
115115
116+ ** Leaderboards**
117+
118+ - ` getLeaderboards() ` - List leaderboards for different trophy roads.
119+ - ` getLeaderboardById(leaderboardId: number, params: ILeaderboardRequestParams) ` - Get players on a specific leaderboard.
120+
116121## Configuration Objects
117122
118123** IClanRequestParams**
@@ -222,6 +227,29 @@ export interface ILocationRequestParams {
222227}
223228```
224229
230+ ** ILeaderboardRequestParams**
231+
232+ ``` typescript
233+ export interface ILeaderboardRequestParams {
234+ /**
235+ * Limit the number of items returned in the response.
236+ */
237+ limit? : number
238+ /**
239+ * Return only items that occur after this marker.
240+ * After marker can be found from the response, inside the 'paging' property.
241+ * Note that only after or before can be specified for a request, not both.
242+ */
243+ after? : string
244+ /**
245+ * Return only items that occur before this marker.
246+ * Before marker can be found from the response, inside the 'paging' property.
247+ * Note that only after or before can be specified for a request, not both.
248+ */
249+ before? : string
250+ }
251+ ```
252+
225253[ LICENSE - MIT] ( LICENSE )
226254
227255---
Original file line number Diff line number Diff line change @@ -6,4 +6,9 @@ describe('ClashRoyaleAPI', () => {
66 test ( 'should have been successfully instantiated' , ( ) => {
77 expect ( ClashRoyale ) . toBeDefined ( )
88 } )
9+
10+ test ( 'should have leaderboard methods' , ( ) => {
11+ expect ( ClashRoyale . getLeaderboards ) . toBeDefined ( )
12+ expect ( ClashRoyale . getLeaderboardById ) . toBeDefined ( )
13+ } )
914} )
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export * from './clans.endpoint'
33export * from './players.endpoint'
44export * from './tournaments.endpoint'
55export * from './locations.endpoint'
6+ export * from './leaderboards.endpoint'
Original file line number Diff line number Diff line change 1+ import { AxiosInstance } from 'axios'
2+
3+ import {
4+ ILeaderboard ,
5+ ILeaderboardPlayer ,
6+ ILeaderboardRequestParams ,
7+ } from '../interfaces'
8+
9+ /**
10+ * List leaderboards for different trophy roads.
11+ *
12+ * @param {AxiosInstance } apiClient
13+ */
14+ const getLeaderboards = async (
15+ apiClient : AxiosInstance ,
16+ ) : Promise < ILeaderboard [ ] > => {
17+ const leaderboards = await apiClient . get ( '/leaderboards' )
18+ return leaderboards . data . items
19+ }
20+
21+ /**
22+ * Get players on a specific leaderboard.
23+ *
24+ * @param {number } leaderboardId
25+ * @param {ILeaderboardRequestParams } params
26+ * @param {AxiosInstance } apiClient
27+ */
28+ const getLeaderboardById = async (
29+ leaderboardId : number ,
30+ params : ILeaderboardRequestParams ,
31+ apiClient : AxiosInstance ,
32+ ) : Promise < ILeaderboardPlayer [ ] > => {
33+ const leaderboard = await apiClient . get ( `/leaderboard/${ leaderboardId } ` , {
34+ params,
35+ } )
36+ return leaderboard . data . items
37+ }
38+
39+ export { getLeaderboards , getLeaderboardById }
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import {
1111 getClans ,
1212 getClanWarlog ,
1313 getGlobalTournaments ,
14+ getLeaderboardById ,
15+ getLeaderboards ,
1416 getLocationById ,
1517 getLocations ,
1618 getPlayerBattleLog ,
@@ -31,6 +33,9 @@ import {
3133 ICurrentRiverRace ,
3234 ICurrentWar ,
3335 IGlobalTournaments ,
36+ ILeaderboard ,
37+ ILeaderboardPlayer ,
38+ ILeaderboardRequestParams ,
3439 ILocation ,
3540 ILocationFullRequestParams ,
3641 ILocationRequestParams ,
@@ -247,4 +252,24 @@ export class ClashRoyaleAPI {
247252 ) : Promise < IClan [ ] > {
248253 return await getClanRankingsForLocation ( id , params , this . apiClient )
249254 }
255+
256+ /**
257+ * List leaderboards for different trophy roads.
258+ */
259+ public async getLeaderboards ( ) : Promise < ILeaderboard [ ] > {
260+ return await getLeaderboards ( this . apiClient )
261+ }
262+
263+ /**
264+ * Get players on a specific leaderboard.
265+ *
266+ * @param {number } leaderboardId
267+ * @param {ILeaderboardRequestParams } params
268+ */
269+ public async getLeaderboardById (
270+ leaderboardId : number ,
271+ params : ILeaderboardRequestParams = { } ,
272+ ) : Promise < ILeaderboardPlayer [ ] > {
273+ return await getLeaderboardById ( leaderboardId , params , this . apiClient )
274+ }
250275}
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ export * from './war.interface'
99export * from './battle.interface'
1010export * from './river_race.interface'
1111export * from './CardResponse.interface'
12+ export * from './leaderboard.interface'
Original file line number Diff line number Diff line change 1+ export interface ILeaderboard {
2+ id : number
3+ name : string
4+ iconUrl ?: string
5+ }
6+
7+ export interface ILeaderboardPlayer {
8+ tag : string
9+ name : string
10+ expLevel : number
11+ trophies : number
12+ rank : number
13+ previousRank ?: number
14+ clan ?: {
15+ tag : string
16+ name : string
17+ badgeId : number
18+ }
19+ }
20+
21+ export interface ILeaderboardRequestParams {
22+ /**
23+ * Limit the number of items returned in the response.
24+ */
25+ limit ?: number
26+ /**
27+ * Return only items that occur after this marker.
28+ * After marker can be found from the response, inside the 'paging' property.
29+ * Note that only after or before can be specified for a request, not both.
30+ */
31+ after ?: string
32+ /**
33+ * Return only items that occur before this marker.
34+ * Before marker can be found from the response, inside the 'paging' property.
35+ * Note that only after or before can be specified for a request, not both.
36+ */
37+ before ?: string
38+ }
You can’t perform that action at this time.
0 commit comments