From 6e008b546166165bfa870b9b2bb3dd2d284e2994 Mon Sep 17 00:00:00 2001 From: Viktor geozukunft Date: Mon, 8 Apr 2024 20:18:47 +0200 Subject: [PATCH 1/2] Add the new Spectator-V5 API and remove deprecated Spectator-V4 --- src/riotwatcher/LolWatcher.py | 6 ++--- .../{SpectatorApiV4.py => SpectatorApiV5.py} | 22 +++++++++---------- .../_apis/league_of_legends/__init__.py | 2 +- .../urls/SpectatorApiUrls.py | 12 +++++----- .../_apis/league_of_legends/urls/__init__.py | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) rename src/riotwatcher/_apis/league_of_legends/{SpectatorApiV4.py => SpectatorApiV5.py} (60%) diff --git a/src/riotwatcher/LolWatcher.py b/src/riotwatcher/LolWatcher.py index 8c8755a..ad447e2 100644 --- a/src/riotwatcher/LolWatcher.py +++ b/src/riotwatcher/LolWatcher.py @@ -25,7 +25,7 @@ LeagueApiV4, LolStatusApiV3, LolStatusApiV4, - SpectatorApiV4, + SpectatorApiV5, SummonerApiV4, MatchApiV5, ChallengesApiV1, @@ -105,7 +105,7 @@ def __init__( self._champion_mastery = ChampionMasteryApiV4(self._base_api) self._league = LeagueApiV4(self._base_api) self._match = MatchApiV5(self._base_api) - self._spectator = SpectatorApiV4(self._base_api) + self._spectator = SpectatorApiV5(self._base_api) self._challenges = ChallengesApiV1(self._base_api) self._summoner = SummonerApiV4(self._base_api) @@ -211,7 +211,7 @@ def match_v5(self): ) @property - def spectator(self) -> SpectatorApiV4: + def spectator(self) -> SpectatorApiV5: """ Interface to the Spectator Endpoint diff --git a/src/riotwatcher/_apis/league_of_legends/SpectatorApiV4.py b/src/riotwatcher/_apis/league_of_legends/SpectatorApiV5.py similarity index 60% rename from src/riotwatcher/_apis/league_of_legends/SpectatorApiV4.py rename to src/riotwatcher/_apis/league_of_legends/SpectatorApiV5.py index 618f846..133fdb0 100644 --- a/src/riotwatcher/_apis/league_of_legends/SpectatorApiV4.py +++ b/src/riotwatcher/_apis/league_of_legends/SpectatorApiV5.py @@ -1,37 +1,37 @@ from .. import BaseApi, NamedEndpoint -from .urls import SpectatorApiV4Urls +from .urls import SpectatorApiV5Urls -class SpectatorApiV4(NamedEndpoint): +class SpectatorApiV5(NamedEndpoint): """ - This class wraps the Spectator-v4 endpoint calls provided by the Riot API. + This class wraps the Spectator-v5 endpoint calls provided by the Riot API. - See https://developer.riotgames.com/api-methods/#spectator-v4 for more detailed + See https://developer.riotgames.com/api-methods/#spectator-v5 for more detailed information """ def __init__(self, base_api: BaseApi): """ - Initialize a new SpectatorApiV3 which uses the provided base_api + Initialize a new SpectatorApiV5 which uses the provided base_api :param BaseApi base_api: the root API object to use for making all requests. """ super().__init__(base_api, self.__class__.__name__) - def by_summoner(self, region: str, encrypted_summoner_id: str): + def by_summoner(self, region: str, encrypted_puuid: str): """ - Get current game information for the given summoner ID + Get current game information for the given PUUID :param string region: The region to execute this request on - :param string encrypted_summoner_id: The ID of the summoner. + :param string encrypted_puuid: The PUUID of the summoner. :returns: CurrentGameInfo """ return self._request_endpoint( self.by_summoner.__name__, region, - SpectatorApiV4Urls.by_summoner, - encrypted_summoner_id=encrypted_summoner_id, + SpectatorApiV5Urls.by_summoner, + encrypted_puuid=encrypted_puuid, ) def featured_games(self, region: str): @@ -43,5 +43,5 @@ def featured_games(self, region: str): :returns: FeaturedGames """ return self._request_endpoint( - self.featured_games.__name__, region, SpectatorApiV4Urls.featured_games + self.featured_games.__name__, region, SpectatorApiV5Urls.featured_games ) diff --git a/src/riotwatcher/_apis/league_of_legends/__init__.py b/src/riotwatcher/_apis/league_of_legends/__init__.py index 0ef0397..c6d2440 100644 --- a/src/riotwatcher/_apis/league_of_legends/__init__.py +++ b/src/riotwatcher/_apis/league_of_legends/__init__.py @@ -5,7 +5,7 @@ from .LeagueApiV4 import LeagueApiV4 from .LolStatusApiV3 import LolStatusApiV3 from .LolStatusApiV4 import LolStatusApiV4 -from .SpectatorApiV4 import SpectatorApiV4 +from .SpectatorApiV5 import SpectatorApiV5 from .SummonerApiV4 import SummonerApiV4 from .MatchApiV5 import MatchApiV5 from .ChallengesApiV1 import ChallengesApiV1 \ No newline at end of file diff --git a/src/riotwatcher/_apis/league_of_legends/urls/SpectatorApiUrls.py b/src/riotwatcher/_apis/league_of_legends/urls/SpectatorApiUrls.py index 813b6d5..04d5258 100644 --- a/src/riotwatcher/_apis/league_of_legends/urls/SpectatorApiUrls.py +++ b/src/riotwatcher/_apis/league_of_legends/urls/SpectatorApiUrls.py @@ -1,14 +1,14 @@ from .LeagueEndpoint import LeagueEndpoint -class SpecatorV4Endpoint(LeagueEndpoint): +class SpecatorV5Endpoint(LeagueEndpoint): def __init__(self, url, **kwargs): - nurl = f"/spectator/v4{url}" + nurl = f"/spectator/v5{url}" super().__init__(nurl, **kwargs) -class SpectatorApiV4Urls: - by_summoner = SpecatorV4Endpoint( - "/active-games/by-summoner/{encrypted_summoner_id}" +class SpectatorApiV5Urls: + by_summoner = SpecatorV5Endpoint( + "/active-games/by-summoner/{encrypted_puuid}" ) - featured_games = SpecatorV4Endpoint("/featured-games") + featured_games = SpecatorV5Endpoint("/featured-games") diff --git a/src/riotwatcher/_apis/league_of_legends/urls/__init__.py b/src/riotwatcher/_apis/league_of_legends/urls/__init__.py index 69ebd70..c61e55b 100644 --- a/src/riotwatcher/_apis/league_of_legends/urls/__init__.py +++ b/src/riotwatcher/_apis/league_of_legends/urls/__init__.py @@ -5,7 +5,7 @@ from .LeagueApiUrls import LeagueApiV4Urls from .LolStatusApiUrls import LolStatusApiV3Urls from .LolStatusApiV4Urls import LolStatusApiV4Urls -from .SpectatorApiUrls import SpectatorApiV4Urls +from .SpectatorApiUrls import SpectatorApiV5Urls from .SummonerApiUrls import SummonerApiV4Urls from .ThirdPartyCodeApiUrls import ThirdPartyCodeApiV4Urls from .MatchApiV5Urls import MatchApiV5Urls From f11b0e6d8e157dc921548680da1afd4e8c3c544d Mon Sep 17 00:00:00 2001 From: Viktor geozukunft Date: Mon, 8 Apr 2024 20:43:27 +0200 Subject: [PATCH 2/2] Update Tests for Spectator-V5 --- ...{SpectatorApiV4.rst => SpectatorApiV5.rst} | 4 ++-- docs/riotwatcher/LeagueOfLegends/index.rst | 2 +- ...ectatorApiV4.py => test_SpectatorApiV5.py} | 20 +++++++++---------- ...ectatorApiV4.py => test_SpectatorApiV5.py} | 12 +++++------ 4 files changed, 19 insertions(+), 19 deletions(-) rename docs/riotwatcher/LeagueOfLegends/{SpectatorApiV4.rst => SpectatorApiV5.rst} (89%) rename tests/_apis/league_of_legends/{test_SpectatorApiV4.py => test_SpectatorApiV5.py} (70%) rename tests/integration/league_of_legends/{test_SpectatorApiV4.py => test_SpectatorApiV5.py} (64%) diff --git a/docs/riotwatcher/LeagueOfLegends/SpectatorApiV4.rst b/docs/riotwatcher/LeagueOfLegends/SpectatorApiV5.rst similarity index 89% rename from docs/riotwatcher/LeagueOfLegends/SpectatorApiV4.rst rename to docs/riotwatcher/LeagueOfLegends/SpectatorApiV5.rst index 41c2dc4..83a42cf 100644 --- a/docs/riotwatcher/LeagueOfLegends/SpectatorApiV4.rst +++ b/docs/riotwatcher/LeagueOfLegends/SpectatorApiV5.rst @@ -1,8 +1,8 @@ -SpectatorApiV4 +SpectatorApiV5 ============== .. py:currentmodule:: riotwatcher -.. autoclass:: riotwatcher._apis.league_of_legends.SpectatorApiV4 +.. autoclass:: riotwatcher._apis.league_of_legends.SpectatorApiV5 :members: :undoc-members: diff --git a/docs/riotwatcher/LeagueOfLegends/index.rst b/docs/riotwatcher/LeagueOfLegends/index.rst index cc3a25d..5d60786 100644 --- a/docs/riotwatcher/LeagueOfLegends/index.rst +++ b/docs/riotwatcher/LeagueOfLegends/index.rst @@ -23,5 +23,5 @@ All APIs LolStatusApiV4.rst MatchApiV5.rst ChallengesApiV1.rst - SpectatorApiV4.rst + SpectatorApiV5.rst SummonerApiV4.rst diff --git a/tests/_apis/league_of_legends/test_SpectatorApiV4.py b/tests/_apis/league_of_legends/test_SpectatorApiV5.py similarity index 70% rename from tests/_apis/league_of_legends/test_SpectatorApiV4.py rename to tests/_apis/league_of_legends/test_SpectatorApiV5.py index 3808723..0aa5c5f 100644 --- a/tests/_apis/league_of_legends/test_SpectatorApiV4.py +++ b/tests/_apis/league_of_legends/test_SpectatorApiV5.py @@ -2,28 +2,28 @@ import pytest -from riotwatcher._apis.league_of_legends import SpectatorApiV4 +from riotwatcher._apis.league_of_legends import SpectatorApiV5 @pytest.mark.lol @pytest.mark.unit -class TestSpectatorApiV4: +class TestSpectatorApiV5: def test_by_summoner(self): mock_base_api = MagicMock() expected_return = object() mock_base_api.raw_request.return_value = expected_return - spectator = SpectatorApiV4(mock_base_api) + spectator = SpectatorApiV5(mock_base_api) region = "agagd" - encrypted_summoner_id = "98532" + encrypted_puuid = "98532" - ret = spectator.by_summoner(region, encrypted_summoner_id) + ret = spectator.by_summoner(region, encrypted_puuid) mock_base_api.raw_request.assert_called_once_with( - SpectatorApiV4.__name__, + SpectatorApiV5.__name__, spectator.by_summoner.__name__, region, - f"https://{region}.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/{encrypted_summoner_id}", + f"https://{region}.api.riotgames.com/lol/spectator/v5/active-games/by-summoner/{encrypted_puuid}", {}, ) @@ -34,16 +34,16 @@ def test_featured_games(self): expected_return = object() mock_base_api.raw_request.return_value = expected_return - spectator = SpectatorApiV4(mock_base_api) + spectator = SpectatorApiV5(mock_base_api) region = "hfh42" ret = spectator.featured_games(region) mock_base_api.raw_request.assert_called_once_with( - SpectatorApiV4.__name__, + SpectatorApiV5.__name__, spectator.featured_games.__name__, region, - f"https://{region}.api.riotgames.com/lol/spectator/v4/featured-games", + f"https://{region}.api.riotgames.com/lol/spectator/v5/featured-games", {}, ) diff --git a/tests/integration/league_of_legends/test_SpectatorApiV4.py b/tests/integration/league_of_legends/test_SpectatorApiV5.py similarity index 64% rename from tests/integration/league_of_legends/test_SpectatorApiV4.py rename to tests/integration/league_of_legends/test_SpectatorApiV5.py index 858b512..0a140d5 100644 --- a/tests/integration/league_of_legends/test_SpectatorApiV4.py +++ b/tests/integration/league_of_legends/test_SpectatorApiV5.py @@ -21,16 +21,16 @@ "pbe1", ], ) -class TestSpectatorApiV4: - @pytest.mark.parametrize("encrypted_summoner_id", ["12345", "99999999999999999"]) - def test_by_summoner(self, lol_context, region, encrypted_summoner_id): +class TestSpectatorApiV5: + @pytest.mark.parametrize("encrypted_puuid", ["12345", "99999999999999999"]) + def test_by_summoner(self, lol_context, region, encrypted_puuid): actual_response = lol_context.watcher.spectator.by_summoner( - region, encrypted_summoner_id + region, encrypted_puuid ) lol_context.verify_api_call( region, - f"/lol/spectator/v4/active-games/by-summoner/{encrypted_summoner_id}", + f"/lol/spectator/v5/active-games/by-summoner/{encrypted_puuid}", {}, actual_response, ) @@ -39,5 +39,5 @@ def test_featured_games(self, lol_context, region): actual_response = lol_context.watcher.spectator.featured_games(region) lol_context.verify_api_call( - region, "/lol/spectator/v4/featured-games", {}, actual_response + region, "/lol/spectator/v5/featured-games", {}, actual_response )