Skip to content

Commit

Permalink
add support for LoR Match API
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudonym117 committed Oct 4, 2020
1 parent 2010aee commit a6ba4c9
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Check for full (read: slightly better) documentation `here <http://riot-watcher.

RiotWatcher is a thin wrapper on top of the `Riot Games API for League
of Legends <https://developer.riotgames.com/>`__. 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://developer.riotgames.com/>`__. 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
Expand Down
8 changes: 8 additions & 0 deletions docs/riotwatcher/LegendsOfRuneterra/MatchApi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MatchApi
========

.. py:currentmodule:: riotwatcher
.. autoclass:: riotwatcher._apis.legends_of_runeterra.MatchApi
:members:
:undoc-members:
7 changes: 3 additions & 4 deletions docs/riotwatcher/LegendsOfRuneterra/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ All APIs
--------

.. toctree::
:maxdepth: 1

RankedApi.rst

:maxdepth: 1

MatchApi.rst
RankedApi.rst
12 changes: 11 additions & 1 deletion src/riotwatcher/LorWatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/riotwatcher/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "3.1.0"
__version__ = "3.1.1"
__author__ = "pseudonym117"
__title__ = "RiotWatcher"
39 changes: 39 additions & 0 deletions src/riotwatcher/_apis/legends_of_runeterra/MatchApi.py
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions src/riotwatcher/_apis/legends_of_runeterra/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .MatchApi import MatchApi
from .RankedApi import RankedApi
11 changes: 11 additions & 0 deletions src/riotwatcher/_apis/legends_of_runeterra/urls/MatchApiUrls.py
Original file line number Diff line number Diff line change
@@ -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}")
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .MatchApiUrls import MatchApiUrls
from .RankedApiUrls import RankedApiUrls
52 changes: 52 additions & 0 deletions tests/_apis/legends_of_runeterra/test_MatchApi.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/integration/legends_of_runeterra/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture(params=["EUROPE", "ASIA", "AMERICAS"])
def region(request):
return request.param
24 changes: 24 additions & 0 deletions tests/integration/legends_of_runeterra/test_MatchApi.py
Original file line number Diff line number Diff line change
@@ -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,
)
3 changes: 0 additions & 3 deletions tests/integration/legends_of_runeterra/test_RankedApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a6ba4c9

Please sign in to comment.