Skip to content

Commit df7c3ac

Browse files
authored
Merge pull request #77 from SharpBit/development
4.0.6
2 parents 87a817f + ab7e8d6 commit df7c3ac

15 files changed

Lines changed: 191 additions & 156 deletions

File tree

.github/FUNDING.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [4.0.6] - 10/6/20
5+
### Changed
6+
- Format of the string of `utils.get_datetime`
7+
### Fixed
8+
- `Player.get_club` now works for the async client if the player is not in a club
9+
410
## [4.0.5] - 7/27/20
511
### Fixed
612
- Removed the print statement on client initialization
713
- Actually uses asyncio.Lock properly if the async client has the option `prevent_ratelimit=True`
814

9-
1015
## [4.0.4] - 7/22/20
1116
### Added
1217
- `get_brawlers` function to get available brawlers

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Special thanks to this project's contributors ❤️
8383
- `Stitch`_
8484

8585
If you want to contribute, whether it be a bug fix or new feature, make sure to follow the `contributing guidelines`_.
86+
This project is no longer actively maintained. No new features will be added, only bugfixes and security fixes will be accepted.
8687

8788
.. _create an issue: https://github.com/SharpBit/brawlstats/issues
8889
.. _Read the Docs: https://brawlstats.rtfd.io/

brawlstats/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
############
88

99

10-
__version__ = 'v4.0.5'
10+
__version__ = 'v4.0.6'
1111
__title__ = 'brawlstats'
1212
__license__ = 'MIT'
1313
__author__ = 'SharpBit'

brawlstats/core.py

Lines changed: 83 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import sys
55
import time
6+
from typing import Union
67

78
import aiohttp
89
import requests
@@ -16,30 +17,28 @@
1617

1718

1819
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
2121
2222
Parameters
2323
------------
2424
token: str
2525
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
4342
"""
4443

4544
REQUEST_LOG = '{method} {url} recieved {text} has returned {status}'
@@ -202,88 +201,106 @@ def _get_model(self, url, model, key=None):
202201
return model(self, data)
203202

204203
@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.
208206
209207
Parameters
210208
----------
211-
tag: str
209+
tag : str
212210
A valid player tag.
213211
Valid characters: 0289PYLQGRJCUV
214212
215-
Returns Player
213+
Returns
214+
-------
215+
Player
216+
A player object with all of its attributes.
216217
"""
217218
url = '{}/{}'.format(self.api.PROFILE, tag)
218219
return self._get_model(url, model=Player)
219220

220221
get_profile = get_player
221222

222223
@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.
225226
226227
Parameters
227228
----------
228-
tag: str
229+
tag : str
229230
A valid player tag.
230231
Valid characters: 0289PYLQGRJCUV
231232
232-
Returns BattleLog
233+
Returns
234+
-------
235+
BattleLog
236+
A player battle object with all of its attributes.
233237
"""
234238
url = '{}/{}/battlelog'.format(self.api.PROFILE, tag)
235239
return self._get_model(url, model=BattleLog)
236240

237241
@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.
241244
242245
Parameters
243246
----------
244-
tag: str
247+
tag : str
245248
A valid club tag.
246249
Valid characters: 0289PYLQGRJCUV
247250
248-
Returns Club
251+
Returns
252+
-------
253+
Club
254+
A club object with all of its attributes.
249255
"""
250256
url = '{}/{}'.format(self.api.CLUB, tag)
251257
return self._get_model(url, model=Club)
252258

253259
@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.
257262
258263
Parameters
259264
----------
260-
tag: str
265+
tag : str
261266
A valid club tag.
262267
Valid characters: 0289PYLQGRJCUV
263268
264-
Returns Members
269+
Returns
270+
-------
271+
Members
272+
A list of the members in a club.
265273
"""
266274
url = '{}/{}/members'.format(self.api.CLUB, tag)
267275
return self._get_model(url, model=Members)
268276

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.
272279
273280
Parameters
274281
----------
275-
ranking: str
282+
ranking : str
276283
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.
287304
"""
288305
if brawler is not None:
289306
if isinstance(brawler, str):
@@ -312,25 +329,27 @@ def get_rankings(self, *, ranking: str, region=None, limit: int=200, brawler=Non
312329

313330
return self._get_model(url, model=Ranking)
314331

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.
318334
319335
Parameters
320336
----------
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
323339
324-
Returns Constants
340+
Returns
341+
-------
342+
Constants
343+
Data containing some Brawl Stars constants.
325344
"""
326345
return self._get_model(self.api.CONSTANTS, model=Constants, key=key)
327346

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.
333349
334-
Returns Brawlers
350+
Returns
351+
-------
352+
Brawlers
353+
A list of available brawlers and information about them.
335354
"""
336355
return self._get_model(self.api.BRAWLERS, model=Brawlers)

brawlstats/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, code, **kwargs):
3535

3636
class RateLimitError(RequestError):
3737
"""Raised when the rate limit is reached."""
38+
3839
def __init__(self, code, url):
3940
self.code = code
4041
self.url = url

0 commit comments

Comments
 (0)