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