|
8 | 8 | import requests |
9 | 9 | from cachetools import TTLCache |
10 | 10 |
|
| 11 | +from typing import Union |
| 12 | + |
11 | 13 | from .errors import Forbidden, NotFoundError, RateLimitError, ServerError, UnexpectedError |
12 | 14 | from .models import BattleLog, Brawlers, Club, Constants, Members, Player, Ranking |
13 | 15 | from .utils import API, bstag, typecasted |
|
16 | 18 |
|
17 | 19 |
|
18 | 20 | class Client: |
19 | | - """ |
20 | | - This is a sync/async client class that lets you access the Brawl Stars API |
| 21 | + """A sync/async client class that lets you access the Brawl Stars API |
21 | 22 |
|
22 | 23 | Parameters |
23 | 24 | ------------ |
24 | 25 | token: str |
25 | 26 | The API Key that you can get from https://developer.brawlstars.com |
26 | | - timeout: Optional[int] = 30 |
27 | | - How long to wait in seconds before shutting down requests. |
28 | | - is_async: Optional[bool] = False |
29 | | - Setting this to ``True`` makes the client async. Default is ``False`` |
30 | | - session: Optional[Union[requests.Session, aiohttp.ClientSession]] = None |
31 | | - Use a current session or a make new one. |
32 | | - loop: Optional[asyncio.window_events._WindowsSelectorEventLoop] |
33 | | - The event loop to use for asynchronous operations. Defaults to ``None``, |
34 | | - in which case the default event loop is ``asyncio.get_event_loop()``. |
35 | | - connector: Optional[aiohttp.TCPConnector] |
36 | | - Pass a TCPConnector into the client (aiohttp). Defaults to ``None``. |
37 | | - debug: Optional[bool] = False |
38 | | - Whether or not to log info for debugging. |
39 | | - prevent_ratelimit: Optional[bool] = False |
40 | | - Whether or not to wait between requests to prevent being ratelimited. |
41 | | - base_url: Optional[str] = None |
42 | | - Sets a different base URL to make request to. |
| 27 | + session: Union[requests.Session, aiohttp.ClientSession], optional |
| 28 | + Use a current session or a make new one, by default None |
| 29 | + timeout: int, optional |
| 30 | + How long to wait in seconds before shutting down requests, by default 30 |
| 31 | + is_async: bool, optional |
| 32 | + Setting this to ``True`` makes the client async, by default False |
| 33 | + loop: asyncio.window_events._WindowsSelectorEventLoop, optional |
| 34 | + The event loop to use for asynchronous operations, by default None |
| 35 | + connector: aiohttp.TCPConnector, optional |
| 36 | + Pass a TCPConnector into the client (aiohttp), by default None |
| 37 | + debug: bool, optional |
| 38 | + Whether or not to log info for debugging, by default False |
| 39 | + prevent_ratelimit: bool, optional |
| 40 | + Whether or not to wait between requests to prevent being ratelimited, by default False |
| 41 | + base_url: str, optional |
| 42 | + Sets a different base URL to make request to, by default None |
43 | 43 | """ |
44 | 44 |
|
45 | 45 | REQUEST_LOG = '{method} {url} recieved {text} has returned {status}' |
@@ -202,88 +202,106 @@ def _get_model(self, url, model, key=None): |
202 | 202 | return model(self, data) |
203 | 203 |
|
204 | 204 | @typecasted |
205 | | - def get_player(self, tag: bstag): |
206 | | - """ |
207 | | - Get a player's stats. |
| 205 | + def get_player(self, tag: bstag) -> Player: |
| 206 | + """Gets a player's stats. |
208 | 207 |
|
209 | 208 | Parameters |
210 | 209 | ---------- |
211 | | - tag: str |
| 210 | + tag : str |
212 | 211 | A valid player tag. |
213 | 212 | Valid characters: 0289PYLQGRJCUV |
214 | 213 |
|
215 | | - Returns Player |
| 214 | + Returns |
| 215 | + ------- |
| 216 | + Player |
| 217 | + A player object with all of its attributes. |
216 | 218 | """ |
217 | 219 | url = '{}/{}'.format(self.api.PROFILE, tag) |
218 | 220 | return self._get_model(url, model=Player) |
219 | 221 |
|
220 | 222 | get_profile = get_player |
221 | 223 |
|
222 | 224 | @typecasted |
223 | | - def get_battle_logs(self, tag: bstag): |
224 | | - """Get a player's battle logs. |
| 225 | + def get_battle_logs(self, tag: bstag) -> BattleLog: |
| 226 | + """Gets a player's battle logs. |
225 | 227 |
|
226 | 228 | Parameters |
227 | 229 | ---------- |
228 | | - tag: str |
| 230 | + tag : str |
229 | 231 | A valid player tag. |
230 | 232 | Valid characters: 0289PYLQGRJCUV |
231 | 233 |
|
232 | | - Returns BattleLog |
| 234 | + Returns |
| 235 | + ------- |
| 236 | + BattleLog |
| 237 | + A player battle object with all of its attributes. |
233 | 238 | """ |
234 | 239 | url = '{}/{}/battlelog'.format(self.api.PROFILE, tag) |
235 | 240 | return self._get_model(url, model=BattleLog) |
236 | 241 |
|
237 | 242 | @typecasted |
238 | | - def get_club(self, tag: bstag): |
239 | | - """ |
240 | | - Get a club's stats. |
| 243 | + def get_club(self, tag: bstag) -> Club: |
| 244 | + """Gets a club's stats. |
241 | 245 |
|
242 | 246 | Parameters |
243 | 247 | ---------- |
244 | | - tag: str |
| 248 | + tag : str |
245 | 249 | A valid club tag. |
246 | 250 | Valid characters: 0289PYLQGRJCUV |
247 | 251 |
|
248 | | - Returns Club |
| 252 | + Returns |
| 253 | + ------- |
| 254 | + Club |
| 255 | + A club object with all of its attributes. |
249 | 256 | """ |
250 | 257 | url = '{}/{}'.format(self.api.CLUB, tag) |
251 | 258 | return self._get_model(url, model=Club) |
252 | 259 |
|
253 | 260 | @typecasted |
254 | | - def get_club_members(self, tag: bstag): |
255 | | - """ |
256 | | - Get the members of a club. |
| 261 | + def get_club_members(self, tag: bstag) -> Members: |
| 262 | + """Gets the members of a club. |
257 | 263 |
|
258 | 264 | Parameters |
259 | 265 | ---------- |
260 | | - tag: str |
| 266 | + tag : str |
261 | 267 | A valid club tag. |
262 | 268 | Valid characters: 0289PYLQGRJCUV |
263 | 269 |
|
264 | | - Returns Members |
| 270 | + Returns |
| 271 | + ------- |
| 272 | + Members |
| 273 | + A list of the members in a club. |
265 | 274 | """ |
266 | 275 | url = '{}/{}/members'.format(self.api.CLUB, tag) |
267 | 276 | return self._get_model(url, model=Members) |
268 | 277 |
|
269 | | - def get_rankings(self, *, ranking: str, region=None, limit: int=200, brawler=None): |
270 | | - """ |
271 | | - Get the top count players/clubs/brawlers. |
| 278 | + def get_rankings(self, *, ranking: str, region: str=None, limit: int=200, brawler: Union[str, int]=None) -> Ranking: |
| 279 | + """Gets the top count players/clubs/brawlers. |
272 | 280 |
|
273 | 281 | Parameters |
274 | 282 | ---------- |
275 | | - ranking: str |
| 283 | + ranking : str |
276 | 284 | The type of ranking. Must be "players", "clubs", "brawlers". |
277 | | - Anything else will return a ValueError. |
278 | | - region: Optional[str] |
279 | | - The region to retrieve from. Must be a 2 letter country code. |
280 | | - limit: Optional[int] = 200 |
281 | | - The number of top players or clubs to fetch. |
282 | | - If count > 200, it will return a ValueError. |
283 | | - brawler: Optional[Union[str, int]] = None |
284 | | - The brawler name or ID. |
285 | | -
|
286 | | - Returns Ranking |
| 285 | + region : str, optional |
| 286 | + The region to retrieve from. Must be a 2 letter country code, by default None |
| 287 | + limit : int, optional |
| 288 | + The number of top players or clubs to fetch, by default 200 |
| 289 | + brawler : Union[str, int], optional |
| 290 | + The brawler name or ID, by default None |
| 291 | +
|
| 292 | + Returns |
| 293 | + ------- |
| 294 | + Ranking |
| 295 | + A player or club ranking that contains a list of players or clubs. |
| 296 | +
|
| 297 | + Raises |
| 298 | + ------ |
| 299 | + ValueError |
| 300 | + The brawler name or ID is invalid. |
| 301 | + ValueError |
| 302 | + `rankings` is not "players", "clubs", or "brawlers" |
| 303 | + ValueError |
| 304 | + `limit` is not between 1 and 200, inclusive. |
287 | 305 | """ |
288 | 306 | if brawler is not None: |
289 | 307 | if isinstance(brawler, str): |
@@ -312,25 +330,27 @@ def get_rankings(self, *, ranking: str, region=None, limit: int=200, brawler=Non |
312 | 330 |
|
313 | 331 | return self._get_model(url, model=Ranking) |
314 | 332 |
|
315 | | - def get_constants(self, key=None): |
316 | | - """ |
317 | | - Gets Brawl Stars constants extracted from the app. |
| 333 | + def get_constants(self, key: str=None) -> Constants: |
| 334 | + """Gets Brawl Stars constants extracted from the app. |
318 | 335 |
|
319 | 336 | Parameters |
320 | 337 | ---------- |
321 | | - key: Optional[str] = None |
322 | | - Any key to get specific data. |
| 338 | + key : str, optional |
| 339 | + Any key to get specific data, by default None |
323 | 340 |
|
324 | | - Returns Constants |
| 341 | + Returns |
| 342 | + ------- |
| 343 | + Constants |
| 344 | + Data containing some Brawl Stars constants. |
325 | 345 | """ |
326 | 346 | return self._get_model(self.api.CONSTANTS, model=Constants, key=key) |
327 | 347 |
|
328 | | - def get_brawlers(self): |
329 | | - """ |
330 | | - Get available brawlers and information about them. |
331 | | -
|
332 | | - No parameters |
| 348 | + def get_brawlers(self) -> Brawlers: |
| 349 | + """Gets available brawlers and information about them. |
333 | 350 |
|
334 | | - Returns Brawlers |
| 351 | + Returns |
| 352 | + ------- |
| 353 | + Brawlers |
| 354 | + A list of available brawlers and information about them. |
335 | 355 | """ |
336 | 356 | return self._get_model(self.api.BRAWLERS, model=Brawlers) |
0 commit comments