diff --git a/README.rst b/README.rst index 21938eb..97f146b 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Check for full (read: slightly better) documentation `here `__. All public methods as -of 9/1/2020 are supported in full. +of 10/3/2020 are supported in full. RiotWatcher by default supports a naive rate limiter. This rate limiter will try to stop you from making too many requests, and in a single threaded test @@ -117,6 +117,8 @@ v3.1.1 - TBD ~~~~~~~~~~~~ Add support for Valorant recent match API. +Add support for LoR MatchAPI. + v3.1.0 - 9/1/2020 ~~~~~~~~~~~~~~~~~ Add support for Clash API's diff --git a/docs/index.rst b/docs/index.rst index 71b6556..db800ed 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,7 @@ Welcome to RiotWatcher's documentation! RiotWatcher is a thin wrapper on top of the `Riot Games API for League of Legends `__. All public methods as -of 9/1/2020 are supported in full. +of 10/3/2020 are supported in full. RiotWatcher by default supports a naive rate limiter. This rate limiter will try to stop you from making too many requests, and in a single threaded test diff --git a/docs/riotwatcher/LegendsOfRuneterra/MatchApi.rst b/docs/riotwatcher/LegendsOfRuneterra/MatchApi.rst new file mode 100644 index 0000000..81bd3f3 --- /dev/null +++ b/docs/riotwatcher/LegendsOfRuneterra/MatchApi.rst @@ -0,0 +1,8 @@ +MatchApi +======== + +.. py:currentmodule:: riotwatcher + +.. autoclass:: riotwatcher._apis.legends_of_runeterra.MatchApi + :members: + :undoc-members: diff --git a/docs/riotwatcher/LegendsOfRuneterra/index.rst b/docs/riotwatcher/LegendsOfRuneterra/index.rst index 59e2ebe..5e02de3 100644 --- a/docs/riotwatcher/LegendsOfRuneterra/index.rst +++ b/docs/riotwatcher/LegendsOfRuneterra/index.rst @@ -12,8 +12,7 @@ All APIs -------- .. toctree:: - :maxdepth: 1 - - RankedApi.rst - + :maxdepth: 1 + MatchApi.rst + RankedApi.rst diff --git a/src/riotwatcher/LorWatcher.py b/src/riotwatcher/LorWatcher.py index 9afa055..a9d8c53 100644 --- a/src/riotwatcher/LorWatcher.py +++ b/src/riotwatcher/LorWatcher.py @@ -12,7 +12,7 @@ from .Handlers.RateLimit import BasicRateLimiter from ._apis import BaseApi -from ._apis.legends_of_runeterra import RankedApi +from ._apis.legends_of_runeterra import MatchApi, RankedApi class LorWatcher: @@ -51,8 +51,18 @@ def __init__( self._base_api = BaseApi(api_key, handler_chain, timeout=timeout) + self._match = MatchApi(self._base_api) self._ranked = RankedApi(self._base_api) + @property + def match(self) -> MatchApi: + """ + Interface to the Match Endpoint + + :rtype: legends_of_runeterra.MatchApi + """ + return self._match + @property def ranked(self) -> RankedApi: """ diff --git a/src/riotwatcher/__version__.py b/src/riotwatcher/__version__.py index b74a684..be3c421 100644 --- a/src/riotwatcher/__version__.py +++ b/src/riotwatcher/__version__.py @@ -1,3 +1,3 @@ -__version__ = "3.1.0" +__version__ = "3.1.1" __author__ = "pseudonym117" __title__ = "RiotWatcher" diff --git a/src/riotwatcher/_apis/legends_of_runeterra/MatchApi.py b/src/riotwatcher/_apis/legends_of_runeterra/MatchApi.py new file mode 100644 index 0000000..f3d71cc --- /dev/null +++ b/src/riotwatcher/_apis/legends_of_runeterra/MatchApi.py @@ -0,0 +1,39 @@ +from .. import BaseApi, NamedEndpoint +from .urls import MatchApiUrls + + +class MatchApi(NamedEndpoint): + """ + This class wraps the LoR-Match-V1 Api calls provided by the Riot API. + + See https://developer.riotgames.com/apis#lor-match-v1 for more detailed + information + """ + + def __init__(self, base_api: BaseApi): + """ + Initialize a new MatchApi 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_puuid(self, region: str, puuid: str): + """ + Get a list of match ids by PUUID. + + :returns: List[string] + """ + return self._request_endpoint( + self.by_puuid.__name__, region, MatchApiUrls.by_puuid, puuid=puuid + ) + + def by_id(self, region: str, match_id: str): + """ + Get match by id. + + :returns: MatchDto + """ + return self._request_endpoint( + self.by_id.__name__, region, MatchApiUrls.by_id, match_id=match_id + ) diff --git a/src/riotwatcher/_apis/legends_of_runeterra/__init__.py b/src/riotwatcher/_apis/legends_of_runeterra/__init__.py index 9eb99e8..f0a5504 100644 --- a/src/riotwatcher/_apis/legends_of_runeterra/__init__.py +++ b/src/riotwatcher/_apis/legends_of_runeterra/__init__.py @@ -1 +1,2 @@ +from .MatchApi import MatchApi from .RankedApi import RankedApi diff --git a/src/riotwatcher/_apis/legends_of_runeterra/urls/MatchApiUrls.py b/src/riotwatcher/_apis/legends_of_runeterra/urls/MatchApiUrls.py new file mode 100644 index 0000000..08bc9b5 --- /dev/null +++ b/src/riotwatcher/_apis/legends_of_runeterra/urls/MatchApiUrls.py @@ -0,0 +1,11 @@ +from .LorEndpoint import LorEndpoint + + +class MatchEndpoint(LorEndpoint): + def __init__(self, url: str, **kwargs): + super().__init__(f"/match/v1{url}", **kwargs) + + +class MatchApiUrls: + by_puuid = MatchEndpoint("/matches/by-puuid/{puuid}/ids") + by_id = MatchEndpoint("/matches/{match_id}") diff --git a/src/riotwatcher/_apis/legends_of_runeterra/urls/__init__.py b/src/riotwatcher/_apis/legends_of_runeterra/urls/__init__.py index 867628c..b3de6c0 100644 --- a/src/riotwatcher/_apis/legends_of_runeterra/urls/__init__.py +++ b/src/riotwatcher/_apis/legends_of_runeterra/urls/__init__.py @@ -1 +1,2 @@ +from .MatchApiUrls import MatchApiUrls from .RankedApiUrls import RankedApiUrls diff --git a/tests/_apis/legends_of_runeterra/test_MatchApi.py b/tests/_apis/legends_of_runeterra/test_MatchApi.py new file mode 100644 index 0000000..5389e8c --- /dev/null +++ b/tests/_apis/legends_of_runeterra/test_MatchApi.py @@ -0,0 +1,52 @@ +from unittest.mock import MagicMock + +import pytest + +from riotwatcher._apis.legends_of_runeterra import MatchApi + + +@pytest.fixture(params=["match_id_001122"]) +def match_id(request): + return request.param + + +@pytest.mark.lor +@pytest.mark.unit +class TestMatchApi: + def test_by_puuid(self, region, puuid): + mock_base_api = MagicMock() + expected_return = object() + mock_base_api.raw_request.return_value = expected_return + + match = MatchApi(mock_base_api) + + ret = match.by_puuid(region, puuid) + + mock_base_api.raw_request.assert_called_once_with( + MatchApi.__name__, + match.by_puuid.__name__, + region, + f"https://{region}.api.riotgames.com/lor/match/v1/matches/by-puuid/{puuid}/ids", + {}, + ) + + assert ret is expected_return + + def test_by_id(self, region, match_id): + mock_base_api = MagicMock() + expected_return = object() + mock_base_api.raw_request.return_value = expected_return + + match = MatchApi(mock_base_api) + + ret = match.by_id(region, match_id) + + mock_base_api.raw_request.assert_called_once_with( + MatchApi.__name__, + match.by_id.__name__, + region, + f"https://{region}.api.riotgames.com/lor/match/v1/matches/{match_id}", + {}, + ) + + assert ret is expected_return diff --git a/tests/integration/legends_of_runeterra/conftest.py b/tests/integration/legends_of_runeterra/conftest.py new file mode 100644 index 0000000..120debc --- /dev/null +++ b/tests/integration/legends_of_runeterra/conftest.py @@ -0,0 +1,6 @@ +import pytest + + +@pytest.fixture(params=["EUROPE", "ASIA", "AMERICAS"]) +def region(request): + return request.param diff --git a/tests/integration/legends_of_runeterra/test_MatchApi.py b/tests/integration/legends_of_runeterra/test_MatchApi.py new file mode 100644 index 0000000..640ac6b --- /dev/null +++ b/tests/integration/legends_of_runeterra/test_MatchApi.py @@ -0,0 +1,24 @@ +import pytest + + +@pytest.fixture(params=["533c8122-f17b-44c1-9254-81a9288a9a6b"]) +def match_id(request): + return request.param + + +@pytest.mark.lor +@pytest.mark.integration +class TestRankedApi: + def test_by_puuid(self, lor_context, region, puuid): + actual_response = lor_context.watcher.match.by_puuid(region, puuid) + + lor_context.verify_api_call( + region, f"/lor/match/v1/matches/by-puuid/{puuid}/ids", {}, actual_response, + ) + + def test_by_id(self, lor_context, region, match_id): + actual_response = lor_context.watcher.match.by_id(region, match_id) + + lor_context.verify_api_call( + region, f"/lor/match/v1/matches/{match_id}", {}, actual_response, + ) diff --git a/tests/integration/legends_of_runeterra/test_RankedApi.py b/tests/integration/legends_of_runeterra/test_RankedApi.py index 597d337..2ee1680 100644 --- a/tests/integration/legends_of_runeterra/test_RankedApi.py +++ b/tests/integration/legends_of_runeterra/test_RankedApi.py @@ -3,9 +3,6 @@ @pytest.mark.lor @pytest.mark.integration -@pytest.mark.parametrize( - "region", ["EUROPE", "ASIA", "AMERICAS",], -) class TestRankedApi: def test_leaderboards(self, lor_context, region): actual_response = lor_context.watcher.ranked.leaderboards(region)