Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split get_score into get_score and get_lazer_score #251

Merged
merged 6 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new_format logic should still remain in both methods to not break existing shit

this stuff should only be removed when the library fully switches to new api models

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