@@ -196,7 +196,7 @@ def _get_model(self, url, model, key=None):
196196 # Calls the async function
197197 return self ._aget_model (url , model = model , key = key )
198198
199- data = self ._request (url )
199+ data , resp = self ._request (url )
200200 if self .prevent_ratelimit :
201201 time .sleep (1 / self .ratelimit [0 ])
202202
@@ -259,74 +259,45 @@ def get_club_members(self, tag: bstag):
259259 url = '{}/{}/members' .format (self .api .CLUB , tag )
260260 return self ._get_model (url , model = Members )
261261
262- def get_player_rankings (self , limit = 200 , region = 'global' ):
262+ def get_rankings (self , ranking_type : str , limit : int = 200 , region = 'global' , brawler = None ):
263263 """
264- Get the top players.
264+ Get the top count players/clubs/brawlers .
265265
266266 Parameters
267267 ----------
268+ ranking_type: str
269+ The type of ranking. Must be "players", "clubs", "brawlers".
270+ Anything else will return a ValueError.
268271 limit: Optional[int] = 200
269272 The number of top players or clubs to fetch.
270- If count > 200, it will set the limit to 200 .
273+ If count > 200, it will return a ValueError .
271274 region: Optional[str] = "global"
272275 The region to retrieve from. Must be a 2 letter country code or "global".
276+ brawler: Optional[Union[str, int]] = None
277+ The brawler name or ID.
273278
274279 Returns Ranking
275280 """
281+ if brawler :
282+ brawler = brawler .lower ()
283+ if brawler not in self .api .BRAWLERS :
284+ raise ValueError ('Invalid brawler.' )
285+
286+ # Check for invalid parameters
287+ if ranking_type not in ('players' , 'clubs' , 'brawlers' ):
288+ raise ValueError ("'lb_type' must be 'players', 'clubs' or 'brawlers'." )
276289 if not 0 < limit <= 200 :
277- limit = 200
278-
279- url = '{}/{}/players?limit={}' .format (self .api .RANKINGS , region , limit )
280- return self ._get_model (url , model = Ranking )
281-
282- def get_club_rankings (self , limit = 200 , region = 'global' ):
283- """
284- Get the top clubs.
285-
286- Parameters
287- ----------
288- limit: Optional[int] = 200
289- The number of top players or clubs to fetch.
290- If count > 200, it will set the limit to 200.
291- region: Optional[str] = "global"
292- The region to retrieve from. Must be a 2 letter country code or "global".
293-
294- Returns Ranking
295- """
296- if not 0 < limit <= 200 :
297- limit = 200
298-
299- url = '{}/{}/clubs?limit={}' .format (self .api .RANKINGS , region , limit )
300- return self ._get_model (url , model = Ranking )
301-
302- def get_brawler_rankings (self , brawler , limit = 200 , region = 'global' ):
303- """
304- Get the leaderboard for a certain brawler.
305-
306- Parameters
307- ----------
308- brawler: Union[str, int]
309- The brawler name or ID
310- limit: Optional[int] = 200
311- The number of top players or clubs to fetch.
312- If count > 200, it will set the limit to 200.
313- region: Optional[str] = "global"
314- The region to retrieve from. Must be a 2 letter country code or "global".
315-
316- Returns Ranking
317- """
318- brawler = brawler .lower ()
319- if brawler not in self .api .BRAWLERS :
320- raise ValueError ('Invalid brawler.' )
321-
322- if not 0 < limit <= 200 :
323- limit = 200
290+ raise ValueError ('Make sure limit is between 1 and 200.' )
324291
325292 # Replace brawler name with ID
326293 if brawler in self .api .BRAWLERS .keys ():
327294 brawler = self .api .BRAWLERS [brawler ]
328295
329- url = '{}/{}/brawlers/{}?limit={}' .format (self .api .RANKINGS , region , brawler , limit )
296+ # Construct URL
297+ url = '{}/{}/{}?limit={}' .format (self .api .RANKINGS , region , ranking_type , limit )
298+ if ranking_type == 'brawlers' :
299+ url = '{}/{}/{}/{}?limit={}' .format (self .api .RANKINGS , region , ranking_type , brawler , limit )
300+
330301 return self ._get_model (url , model = Ranking )
331302
332303 @typecasted
0 commit comments