Skip to content

Commit

Permalink
Add Player.get_battle_logs #93
Browse files Browse the repository at this point in the history
  • Loading branch information
SharpBit committed Oct 7, 2024
1 parent b894839 commit 1a1bf30
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.

## [development] - 10/6/24
### Added
- Implemented an endpoint with `Client.get_event_rotation` which gets the events in the current rotation.
- Added a method `Player.get_battle_logs` which directly gets the player's battle log.
### Fixed
- Client actually uses session passed into parameters now instead of creating a new one anyways
- `UnexpectedError` now properly shows the returned text in the message
Expand Down
25 changes: 18 additions & 7 deletions brawlstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def __repr__(self):
return f'<Members object count={len(self)}>'


class BattleLog(BaseBoxList):
"""A player battle object with all of its attributes."""

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


class Club(BaseBox):
"""A club object with all of its attributes."""

Expand Down Expand Up @@ -106,6 +113,17 @@ async def wrapper():
url = f'{self.client.api.CLUB}/{bstag(self.club.tag)}'
return self.client._get_model(url, model=Club)

def get_battle_logs(self) -> BattleLog:
"""Gets the player's battle logs.
Returns
-------
BattleLog
The battle log containing the player's most recent battles.
"""
url = f'{self.client.api.PROFILE}/{bstag(self.tag)}/battlelog'
return self.client._get_model(url, model=BattleLog)


class Ranking(BaseBoxList):
"""A player or club ranking that contains a list of players or clubs."""
Expand All @@ -117,13 +135,6 @@ def __repr__(self):
return '<Ranking object count={}>'.format(len(self))


class BattleLog(BaseBoxList):
"""A player battle object with all of its attributes."""

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


class Constants(BaseBox):
"""Data containing some Brawl Stars constants."""
pass
Expand Down
3 changes: 3 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ async def test_get_player(self):
self.assertIsInstance(club, brawlstats.Club)
self.assertEqual(club.tag, self.CLUB_TAG)

battle_logs = await player.get_battle_logs()
self.assertIsInstance(battle_logs, brawlstats.BattleLog)

with self.assertRaises(brawlstats.NotFoundError):
await self.client.get_player('2PPPPPPP')

Expand Down
3 changes: 3 additions & 0 deletions tests/test_blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_get_player(self):
self.assertIsInstance(club, brawlstats.Club)
self.assertEqual(club.tag, self.CLUB_TAG)

battle_logs = player.get_battle_logs()
self.assertIsInstance(battle_logs, brawlstats.BattleLog)

self.assertRaises(brawlstats.NotFoundError, self.client.get_player, '2PPPPPPP')
self.assertRaises(brawlstats.NotFoundError, self.client.get_player, 'P')
self.assertRaises(brawlstats.NotFoundError, self.client.get_player, 'AAA')
Expand Down

0 comments on commit 1a1bf30

Please sign in to comment.