Skip to content

Commit 6e5aa9c

Browse files
committed
constants
1 parent fcf038e commit 6e5aa9c

File tree

12 files changed

+71
-7
lines changed

12 files changed

+71
-7
lines changed

CHANGELOG.md

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

4+
## [2.1.6] - 12/8/18
5+
### Added
6+
- Constants extracted from the Brawl Stars App using `Client.get_constants`
7+
48
## [2.1.5] - 12/5/18
59
BREAKING CHANGES: Brawl Stars dev team changed "Band" to "Club". This update fixes all of that.
610
### Changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include brawlstats/constants.json

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Documentation is being hosted on `Read the Docs`_
4444
Misc
4545
~~~~
4646

47+
| If you are currently using this wrapper, feel free to star this repository :)
4748
| If you come across an issue in the wrapper, please `create an issue`_ and I will look into it ASAP.
4849
| If you need help or an API Key, join the API’s `discord server`_.
49-
| If you are currently using this wrapper, feel free to star this repository :)
5050
5151
Examples
5252
~~~~~~~~

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__ = 'v2.1.5'
10+
__version__ = 'v2.1.6'
1111
__title__ = 'brawlstats'
1212
__license__ = 'MIT'
1313
__author__ = 'SharpBit'

brawlstats/constants.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

brawlstats/core.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def get_leaderboard(self, player_or_club: str, count: int=200):
189189
"""
190190
if type(count) != int:
191191
raise ValueError("Make sure 'count' is an int")
192-
if player_or_club.lower() not in ('players', 'clubs') or count > 200 or count < 1:
192+
if player_or_club.lower() not in ('players', 'clubs') or not 0 < count <= 200:
193193
raise ValueError("Please enter 'players' or 'clubs' or make sure 'count' is between 1 and 200.")
194194
url = self.api.leaderboard + '/' + player_or_club + '/' + str(count)
195195
if self.is_async:
@@ -212,6 +212,34 @@ def get_events(self):
212212

213213
return Events(self, resp, data)
214214

215+
async def _get_constants_async(self, key):
216+
data, resp = await self._aget(self.api.constants)
217+
if key and not data.get(key):
218+
raise KeyError('No such key for Brawl Stars constants "{}"'.format(key))
219+
if key and data.get(key):
220+
return Constants(self, resp, data.get(key))
221+
return Constants(self, resp, data)
222+
223+
def get_constants(self, key=None):
224+
"""Gets Brawl Stars constants extracted from the app.
225+
226+
Parameters
227+
----------
228+
key: Optional[str] = None
229+
Any key to get specific data.
230+
231+
Returns Constants
232+
"""
233+
if self.is_async:
234+
return self._get_constants_async(key)
235+
data, resp = await self._get(self.api.constants)
236+
if key and not data.get(key):
237+
raise KeyError('No such key for Brawl Stars constants "{}"'.format(key))
238+
if key and data.get(key):
239+
return Constants(self, resp, data.get(key))
240+
return Constants(self, resp, data)
241+
242+
215243
class Profile(BaseBox):
216244
"""
217245
Returns a full player object with all of its attributes.
@@ -298,5 +326,11 @@ class Events(BaseBox):
298326
def __repr__(self):
299327
return '<Events object>'
300328

301-
def __str__(self):
302-
return 'Events object'
329+
330+
class Constants(BaseBox):
331+
"""
332+
Returns some Brawl Stars constants.
333+
"""
334+
335+
def __repr__(self):
336+
return '<Constants object>'

brawlstats/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ def __init__(self, base_url):
55
self.club = self.base + '/clubs'
66
self.leaderboard = self.base + '/leaderboards'
77
self.events = self.base + '/events'
8+
self.constants = 'https://fourjr.herokuapp.com/bs/constants/'

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Data Models
2222
.. autoclass:: brawlstats.core.Events
2323
:members:
2424

25+
.. autoclass:: brawlstats.core.Constants
26+
:members:
27+
2528
Profile
2629
-------
2730

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# The short X.Y version
2727
version = '2.1'
2828
# The full version, including alpha/beta/rc tags
29-
release = '2.1.5'
29+
release = '2.1.6'
3030

3131

3232
# -- General configuration ---------------------------------------------------

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='brawlstats',
8-
version='2.1.5',
8+
version='2.1.6',
99
description='An async Python API wrapper for the unofficial Brawl Stars API',
1010
long_description=long_description,
1111
long_description_content_type='text/x-rst',

0 commit comments

Comments
 (0)