Skip to content

Commit

Permalink
Split get_score into get_score and get_lazer_score (#251)
Browse files Browse the repository at this point in the history
* add get_lazer_score

* update docs

* apply code review changes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add tests, rename

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: NiceAesth <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2024
1 parent 81367bf commit 14f49f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
32 changes: 27 additions & 5 deletions aiosu/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,19 +1761,18 @@ async def get_beatmapset_discussion_votes(
@requires_scope(Scopes.PUBLIC)
async def get_score(
self,
score_id: int,
legacy_score_id: int,
mode: Gamemode,
**kwargs: Any,
) -> Union[Score, LazerScore]:
r"""Gets data about a score.
:param score_id: The ID of the score
:type score_id: int
:param legacy_score_id: The ID of the score
:type legacy_score_id: int
:param mode: The gamemode to search for
:type mode: aiosu.models.gamemode.Gamemode
:param \**kwargs:
See below
:Keyword Arguments:
* *new_format* (``bool``) --
Optional, whether to use the new score format, defaults to ``False``
Expand All @@ -1783,7 +1782,7 @@ async def get_score(
:return: Score data object
:rtype: aiosu.models.score.Score
"""
url = f"{self.base_url}/api/v2/scores/{mode}/{score_id}"
url = f"{self.base_url}/api/v2/scores/{mode}/{legacy_score_id}"
headers = {}
new_format = kwargs.pop("new_format", False)
if new_format:
Expand All @@ -1794,6 +1793,29 @@ async def get_score(
return LazerScore.model_validate(json)
return Score.model_validate(json)

@prepare_token
@check_token
@requires_scope(Scopes.PUBLIC)
async def get_score_lazer(
self,
score_id: int,
) -> LazerScore:
r"""Gets data about a score.
:param score_id: The ID of the score
:type score_id: int
:raises APIException: Contains status code and error message
:raises RefreshTokenExpiredError: If the client refresh token has expired
:return: LazerScore data object
:rtype: aiosu.models.score.LazerScore
"""
url = f"{self.base_url}/api/v2/scores/{score_id}"
headers = {"x-api-version": "20220705"}

json = await self._request("GET", url, headers=headers)
return LazerScore.model_validate(json)

@prepare_token
@check_token
@requires_scope(Scopes.PUBLIC)
Expand Down
9 changes: 7 additions & 2 deletions tests/test_v2/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,17 @@ async def test_generated(status_code, content_type, token, mocker):
generate_test(
aiosu.v2.Client.get_score,
STATUS_CAN_404,
func_kwargs={"score_id": 4220635589, "mode": "osu"},
func_kwargs={"legacy_score_id": 4220635589, "mode": "osu"},
),
generate_test(
aiosu.v2.Client.get_score,
STATUS_CAN_404,
func_kwargs={"score_id": 4220635589, "mode": "osu", "new_format": True},
func_kwargs={"legacy_score_id": 4220635589, "mode": "osu", "new_format": True},
),
generate_test(
aiosu.v2.Client.get_score_lazer,
STATUS_CAN_404,
func_kwargs={"score_id": 1581778626},
),
generate_test(
aiosu.v2.Client.get_score_replay,
Expand Down

0 comments on commit 14f49f2

Please sign in to comment.