Skip to content

Commit

Permalink
Add Client.get_event_rotation() #94
Browse files Browse the repository at this point in the history
  • Loading branch information
SharpBit committed Oct 7, 2024
1 parent 7574957 commit b894839
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
17 changes: 16 additions & 1 deletion brawlstats/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cachetools import TTLCache

from .errors import Forbidden, NotFoundError, RateLimitError, ServerError, UnexpectedError
from .models import BattleLog, Brawlers, Club, Constants, Members, Player, Ranking
from .models import BattleLog, Brawlers, Club, Constants, EventRotation, Members, Player, Ranking
from .utils import API, bstag, typecasted

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -385,3 +385,18 @@ def get_brawlers(self, use_cache=True) -> Brawlers:
A list of available brawlers and information about them.
"""
return self._get_model(self.api.BRAWLERS, model=Brawlers, use_cache=use_cache)

def get_event_rotation(self, use_cache=True) -> EventRotation:
"""Gets the current events in rotation.
Parameters
----------
use_cache : bool, optional
Whether to use the internal 3 minutes cache, by default True
Returns
-------
Events
A list of the current events in rotation.
"""
return self._get_model(self.api.EVENT_ROTATION, model=EventRotation, use_cache=use_cache)
7 changes: 6 additions & 1 deletion brawlstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .utils import bstag

__all__ = ['Player', 'Club', 'Members', 'Ranking', 'BattleLog', 'Constants', 'Brawlers']
__all__ = ['Player', 'Club', 'Members', 'Ranking', 'BattleLog', 'Constants', 'Brawlers', 'EventRotation']


class BaseBox:
Expand Down Expand Up @@ -134,3 +134,8 @@ class Brawlers(BaseBoxList):

def __init__(self, client, data):
super().__init__(client, data['items'])


class EventRotation(BaseBoxList):
"""A list of events in the current rotation."""
pass
1 change: 1 addition & 0 deletions brawlstats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, base_url, version=1):
self.RANKINGS = self.BASE + '/rankings'
self.CONSTANTS = 'https://fourjr.herokuapp.com/bs/constants'
self.BRAWLERS = self.BASE + '/brawlers'
self.EVENT_ROTATION = self.BASE + '/events/rotation'

# Get package version from __init__.py
path = os.path.dirname(__file__)
Expand Down
22 changes: 21 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Data Models
.. autoclass:: brawlstats.models.Brawlers
:members:

.. autoclass:: brawlstats.models.EventRotation
:members:


Attributes of Data Models
~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -301,7 +304,7 @@ Name Type
Brawlers
~~~~~~~~

Returns list of all brawlers in the game and information,
Represents a list of all brawlers in the game and information,
with each item having the following attributes.
Note: ``Brawlers`` only represents the brawler objects returned
from ``Client.get_brawlers()``.
Expand All @@ -316,3 +319,20 @@ Name Type
``star_powers`` List[`StarPower`_]
``gadgets`` List[`Gadget`_]
==================== ==================

EventRotation
~~~~~~~~~~~~~

Represents a list of events in the current rotation,
each with the following attributes:

Attributes:

============== ========
Name Type
============== ========
``start_time`` str
``end_time`` str
``slot_id`` int
``event`` `Event`_
============== ========
4 changes: 4 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ async def test_get_brawlers(self):
brawlers = await self.client.get_brawlers()
self.assertIsInstance(brawlers, brawlstats.Brawlers)

async def test_get_event_rotation(self):
events = await self.client.get_event_rotation()
self.assertIsInstance(events, brawlstats.EventRotation)


if __name__ == '__main__':
asynctest.main()
4 changes: 4 additions & 0 deletions tests/test_blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def test_get_brawlers(self):
brawlers = self.client.get_brawlers()
self.assertIsInstance(brawlers, brawlstats.Brawlers)

def test_get_event_rotation(self):
events = self.client.get_event_rotation()
self.assertIsInstance(events, brawlstats.EventRotation)


if __name__ == '__main__':
unittest.main()

0 comments on commit b894839

Please sign in to comment.