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

Add Spectator-V5 #234

Merged
merged 2 commits into from
Apr 9, 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
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion docs/riotwatcher/LeagueOfLegends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ All APIs
LolStatusApiV4.rst
MatchApiV5.rst
ChallengesApiV1.rst
SpectatorApiV4.rst
SpectatorApiV5.rst
SummonerApiV4.rst
6 changes: 3 additions & 3 deletions src/riotwatcher/LolWatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
LeagueApiV4,
LolStatusApiV3,
LolStatusApiV4,
SpectatorApiV4,
SpectatorApiV5,
SummonerApiV4,
MatchApiV5,
ChallengesApiV1,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -211,7 +211,7 @@ def match_v5(self):
)

@property
def spectator(self) -> SpectatorApiV4:
def spectator(self) -> SpectatorApiV5:
"""
Interface to the Spectator Endpoint

Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
)
2 changes: 1 addition & 1 deletion src/riotwatcher/_apis/league_of_legends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions src/riotwatcher/_apis/league_of_legends/urls/SpectatorApiUrls.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion src/riotwatcher/_apis/league_of_legends/urls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
{},
)

Expand All @@ -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",
{},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
)