Skip to content

Commit

Permalink
2.0.7: events support
Browse files Browse the repository at this point in the history
  • Loading branch information
SharpBit committed Nov 29, 2018
1 parent 01693b7 commit 7b4c2eb
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion brawlstats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
############


__version__ = 'v2.0.6'
__version__ = 'v2.0.7'
__title__ = 'brawlstats'
__license__ = 'MIT'
__author__ = 'SharpBit'
Expand Down
32 changes: 28 additions & 4 deletions brawlstats/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import aiohttp
import asyncio

from box import Box
from box import Box, BoxKeyError

from .errors import BadRequest, InvalidTag, NotFoundError, Unauthorized, UnexpectedError, ServerError
from .utils import API
Expand Down Expand Up @@ -60,7 +60,7 @@ async def _aget(self, url):
raw_data = await resp.json()
elif resp.status == 400:
raise BadRequest(url, resp.status)
elif resp.status == 403:
elif resp.status == 401:
raise Unauthorized(url, resp.status)
elif resp.status == 404:
raise InvalidTag(url, resp.status)
Expand Down Expand Up @@ -130,6 +130,13 @@ async def get_leaderboard(self, player_or_band: str, count: int=200):

return Leaderboard(response)

async def get_events(self):
"""Get current and upcoming events.
Returns Events"""
response = await self._aget(API.EVENTS)

return Events(response)

class Profile(BaseBox):
"""
Expand Down Expand Up @@ -201,7 +208,24 @@ class Leaderboard(BaseBox):
"""

def __repr__(self):
return '<Leaderboard object count={}'.format(len(self))
try:
return "<Leaderboard object type='players' count={}>".format(len(self.players))
except BoxKeyError:
return "<Leaderboard object type='bands' count={}>".format(len(self.bands))

def __str__(self):
try:
return 'Player Leaderboard containing {} items'.format(len(self.players))
except BoxKeyError:
return 'Band Leaderboard containing {} items'.format(len(self.bands))

class Events(BaseBox):
"""
Returns current and upcoming events.
"""

def __repr__(self):
return '<Events object>'

def __str__(self):
return '{} Leaderboard containing {} items'.format(len(self))
return 'Events object'
1 change: 1 addition & 0 deletions brawlstats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ class API:
PROFILE = BASE + '/players'
BAND = BASE + '/bands'
LEADERBOARD = BASE + '/leaderboards'
EVENTS = BASE + '/events'
30 changes: 30 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Data Models
.. autoclass:: brawlstats.core.Leaderboard
:members:

.. autoclass:: brawlstats.core.Events
:members:

Profile
-------

Expand Down Expand Up @@ -198,6 +201,33 @@ Name Type
``level`` int
==================== =============================

Events
------

Returns a result of current and upcoming events.

Attributes:

============ ===================
Name Type
============ ===================
``current`` List[\Event, Event]
``upcoming`` List[\Event, Event]
============ ===================

Event Attributes:

================= ====
Name Type
================= ====
``slot`` int
``timeInSeconds`` int
``mapId`` int
================= ====




.. _Band: https://brawlstats.readthedocs.io/en/latest/api.html#id1
.. _SimpleBand: https://brawlstats.readthedocs.io/en/latest/api.html#id2
.. _Brawler: https://brawlstats.readthedocs.io/en/latest/api.html#id6
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = '2.0'
# The full version, including alpha/beta/rc tags
release = '2.0.5'
release = '2.0.7'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='brawlstats',
version='2.0.6',
version='2.0.7',
description='An async Python API wrapper for the unofficial Brawl Stars API',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down
4 changes: 4 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ async def test_get_leaderboard_band(self):
lb = await self.client.get_leaderboard('bands')
self.assertTrue(isinstance(lb.bands, list))

async def test_get_events(self):
events = await self.client.get_events()
self.assertTrue(isinstance(events.current, list))

# Other
async def test_invalid_tag(self):
async def request():
Expand Down

0 comments on commit 7b4c2eb

Please sign in to comment.