Skip to content

Commit

Permalink
Full support for match-v5; bump version (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudonym117 authored Jul 4, 2021
1 parent f07a035 commit 78d6551
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 52 deletions.
48 changes: 44 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RiotWatcher v3.1.1
RiotWatcher v3.1.2
==================

|pypi| |docs| |coverage| |lgmt| |black|
Expand All @@ -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 10/3/2020 are supported in full.
of 7/4/2021 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 @@ -84,6 +84,42 @@ raised as HTTPError exceptions from the Requests library.
else:
raise
MatchApiV5
----------

As of 7/4/2021, both the v4 and v5 versions of the Match API are supported by Riot. As such, RiotWatcher provides a
method to use both. By default, the v4 API will be used for backwards compatibility.

To use the v5 API by default, use the following to initialize your LolWatcher instance:

.. code:: python
from riotwatcher import LolWatcher
lol_watcher = LolWatcher('<your-api-key>', default_default_match_v5=True)
# example call
matchlist = lol_watcher.match.matchlist_by_puuid('AMERICAS', 'fake-puuid')
To explicitly use v4 or v5 during the deprecation period, you can use the following properties:

.. code:: python
from riotwatcher import LolWatcher
lol_watcher = LolWatcher('<your-api-key>')
# use v5 explicitly
matchlist = lol_watcher.match_v5.matchlist_by_puuid('AMERICAS', 'fake-puuid')
# use v4 explicitly
old_matchlist = lol_watcher.match_v4.matchlist_by_account('na1', 'fake-account-id')
Note: this will not be supported after v4 is completely deprecated! Both match_v4 and match_v5 properties will be removed,
and the change will happen with a minor version increase. If you desire seamless backwards compatibility, do not use these
properies.


Use with kernel
---------------

Expand Down Expand Up @@ -113,11 +149,15 @@ Rate limiter has some race conditions when used concurrently.

Changelog
---------
v3.1.1 - TBD
v3.1.2 - 7/4/2021
~~~~~~~~~~~~
Add support for LoL MatchAPI v5

v3.1.1 - 10/4/2020
~~~~~~~~~~~~~~~~~~
Add support for Valorant recent match API.

Add support for LoR MatchAPI.
Add support for LoR MatchAPI.

v3.1.0 - 9/1/2020
~~~~~~~~~~~~~~~~~
Expand Down
37 changes: 36 additions & 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 10/3/2020 are supported in full.
of 7/4/2021 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 @@ -80,6 +80,41 @@ raised as HTTPError exceptions from the Requests library.
else:
raise
MatchApiV5
----------

As of 7/4/2021, both the v4 and v5 versions of the Match API are supported by Riot. As such, RiotWatcher provides a
method to use both. By default, the v4 API will be used for backwards compatibility.

To use the v5 API by default, use the following to initialize your LolWatcher instance:

.. code:: python
from riotwatcher import LolWatcher
lol_watcher = LolWatcher('<your-api-key>', default_default_match_v5=True)
# example call
matchlist = lol_watcher.match.matchlist_by_puuid('AMERICAS', 'fake-puuid')
To explicitly use v4 or v5 during the deprecation period, you can use the following properties:

.. code:: python
from riotwatcher import LolWatcher
lol_watcher = LolWatcher('<your-api-key>')
# use v5 explicitly
matchlist = lol_watcher.match_v5.matchlist_by_puuid('AMERICAS', 'fake-puuid')
# use v4 explicitly
old_matchlist = lol_watcher.match_v4.matchlist_by_account('na1', 'fake-account-id')
Note: this will not be supported after v4 is completely deprecated! Both match_v4 and match_v5 properties will be removed,
and the change will happen with a minor version increase. If you desire seamless backwards compatibility, do not use these
properies.


Use with kernel
---------------
Expand Down
8 changes: 8 additions & 0 deletions docs/riotwatcher/LeagueOfLegends/MatchApiV5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MatchApiV4
==========

.. py:currentmodule:: riotwatcher
.. autoclass:: riotwatcher._apis.league_of_legends.MatchApiV5
:members:
:undoc-members:
1 change: 1 addition & 0 deletions docs/riotwatcher/LeagueOfLegends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All APIs
LeagueApiV4.rst
LolStatusApiV3.rst
MatchApiV4.rst
MatchApiV5.rst
SpectatorApiV4.rst
SummonerApiV4.rst
ThirdPartyCodeApiV4.rst
Expand Down
49 changes: 31 additions & 18 deletions src/riotwatcher/LolWatcher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union
from .Deserializer import Deserializer
from .RateLimiter import RateLimiter

Expand All @@ -24,7 +25,7 @@
SpectatorApiV4,
SummonerApiV4,
MatchApiV5,
ThirdPartyCodeApiV4,
ThirdPartyCodeApiV4,
)


Expand All @@ -40,6 +41,7 @@ def __init__(
kernel_url: str = None,
rate_limiter: RateLimiter = BasicRateLimiter(),
deserializer: Deserializer = DictionaryDeserializer(),
default_match_v5: bool = False,
):
"""
Initialize a new instance of the RiotWatcher class.
Expand Down Expand Up @@ -88,13 +90,13 @@ def __init__(
self._clash = ClashApiV1(self._base_api)
self._champion_mastery = ChampionMasteryApiV4(self._base_api)
self._league = LeagueApiV4(self._base_api)
self._match = MatchApiV4(self._base_api)
self._match_v4 = MatchApiV4(self._base_api)
self._match_v5 = MatchApiV5(self._base_api)
self._spectator = SpectatorApiV4(self._base_api)
self._summoner = SummonerApiV4(self._base_api)

self._matchv5 = MatchApiV5(self._base_api)

self._third_party_code = ThirdPartyCodeApiV4(self._base_api)
self._third_party_code = ThirdPartyCodeApiV4(self._base_api)

self._match = self._match_v5 if default_match_v5 else self._match_v4
# todo: tournament-stub
# todo: tournament

Expand Down Expand Up @@ -144,14 +146,34 @@ def lol_status(self) -> LolStatusApiV3:
return self._lol_status

@property
def match(self) -> MatchApiV4:
def match(self) -> Union[MatchApiV4, MatchApiV5]:
"""
Interface to the Match Endpoint
:rtype: league_of_legends.MatchApiV5
"""
return self._match

@property
def match_v4(self) -> MatchApiV4:
"""
Temporary explicit interface to match-v4 endpoint.
Will be removed when matchv4 is deprecated.
:rtype: league_of_legends.MatchApiV4
"""
return self._match


@property
def match_v5(self) -> MatchApiV5:
"""
Temporary explicit interface to match-v5 endpoint.
Will be removed when matchv4 is deprecated.
:rtype: league_of_legends.MatchApiV5
"""
return self._match_v5

@property
def spectator(self) -> SpectatorApiV4:
"""
Expand All @@ -178,15 +200,6 @@ def summoner(self) -> SummonerApiV4:
:rtype: league_of_legends.SummonerApiV4
"""
return self._summoner

@property
def matchv5(self) -> MatchApiV5:
"""
Interface to the Match Endpoint
:rtype: league_of_legends.MatchApiV5
"""
return self._matchv5

@property
def third_party_code(self) -> ThirdPartyCodeApiV4:
Expand All @@ -195,4 +208,4 @@ def third_party_code(self) -> ThirdPartyCodeApiV4:
:rtype: league_of_legends.ThirdPartyCodeApiV4
"""
return self._third_party_code
return self._third_party_code
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.1"
__version__ = "3.1.2"
__author__ = "pseudonym117"
__title__ = "RiotWatcher"
8 changes: 5 additions & 3 deletions tests/integration/league_of_legends/test_MatchApiV4.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class TestMatchApiV4:
@pytest.mark.parametrize("match_id", [12345, 54321, 2, 222222222222222222222])
def test_by_id(self, lol_context, region, match_id):
actual_response = lol_context.watcher.match.by_id(region, match_id)
actual_response = lol_context.watcher.match_v4.by_id(region, match_id)

lol_context.verify_api_call(
region, f"/lol/match/v4/matches/{match_id}", {}, actual_response,
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_matchlist_by_account(
begin_time, end_time = begin_end_time
begin_index, end_index = begin_end_index

actual_response = lol_context.watcher.match.matchlist_by_account(
actual_response = lol_context.watcher.match_v4.matchlist_by_account(
region,
encrypted_account_id,
queue=queue,
Expand Down Expand Up @@ -93,7 +93,9 @@ def test_matchlist_by_account(

@pytest.mark.parametrize("match_id", [0, 54321, 3232323232323223])
def test_timeline_by_match(self, lol_context, region, match_id):
actual_response = lol_context.watcher.match.timeline_by_match(region, match_id)
actual_response = lol_context.watcher.match_v4.timeline_by_match(
region, match_id
)

lol_context.verify_api_call(
region, f"/lol/match/v4/timelines/by-match/{match_id}", {}, actual_response,
Expand Down
43 changes: 18 additions & 25 deletions tests/integration/league_of_legends/test_MatchApiV5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,35 @@
@pytest.mark.lol
@pytest.mark.integration
@pytest.mark.parametrize(
"region",
[
"EUROPE",
"AMERICAS",
"ASIA",
],
"region", ["EUROPE", "AMERICAS", "ASIA",],
)
class TestMatchApiV5:
@pytest.mark.parametrize("match_id", ["EUW1_12345", "EUW1_54321", "EUW1_1", "EUW_1222222222222222222222"])
@pytest.mark.parametrize(
"match_id", ["EUW1_12345", "EUW1_54321", "EUW1_1", "EUW_1222222222222222222222"]
)
def test_by_id(self, lol_context, region, match_id):
actual_response = lol_context.watcher.matchv5.by_id(region, match_id)
actual_response = lol_context.watcher.match_v5.by_id(region, match_id)

lol_context.verify_api_call(
region, f"/lol/match/v5/matches/{match_id}", {}, actual_response,
)

@pytest.mark.parametrize("puuid", ["12345", "3333333333333333333"])
@pytest.mark.parametrize("count", [None, 20])
@pytest.mark.parametrize("start", [None, 0])
@pytest.mark.parametrize("start", [None, 0])
def test_matchlist_by_account(
self,
lol_context,
region,
puuid,
start,
count,
):

actual_response = lol_context.watcher.matchv5.matchlist_by_puuid(
region,
puuid,
start=start,
count=count,
self, lol_context, region, puuid, start, count,
):

actual_response = lol_context.watcher.match_v5.matchlist_by_puuid(
region, puuid, start=start, count=count,
)

expected_params = {}
if count is not None:
expected_params["count"] = count
if start is not None:
expected_params["start"] = start
expected_params["start"] = start

lol_context.verify_api_call(
region,
Expand All @@ -52,9 +41,13 @@ def test_matchlist_by_account(
actual_response,
)

@pytest.mark.parametrize("match_id", ["EUW1_12345", "EUW1_54321", "EUW1_1", "EUW_1222222222222222222222"])
@pytest.mark.parametrize(
"match_id", ["EUW1_12345", "EUW1_54321", "EUW1_1", "EUW_1222222222222222222222"]
)
def test_timeline_by_match(self, lol_context, region, match_id):
actual_response = lol_context.watcher.matchv5.timeline_by_match(region, match_id)
actual_response = lol_context.watcher.match_v5.timeline_by_match(
region, match_id
)

lol_context.verify_api_call(
region, f"/lol/match/v5/matches/{match_id}/timeline", {}, actual_response,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_LolWatcher.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from riotwatcher import LolWatcher
from riotwatcher._apis.league_of_legends import MatchApiV4, MatchApiV5


@pytest.mark.lol
Expand All @@ -18,3 +19,15 @@ def test_allows_keyword_api_key(self):

def test_allows_kernel_url(self):
LolWatcher(kernel_url="https://fake-kernel-server")

def test_defaults_match_v4(self):
watcher = LolWatcher(api_key="RGAPI-this-is-a-fake")
assert isinstance(watcher.match, MatchApiV4)

def test_uses_match_v4_when_false(self):
watcher = LolWatcher(api_key="RGAPI-this-is-a-fake", default_match_v5=False)
assert isinstance(watcher.match, MatchApiV4)

def test_uses_match_v5_when_true(self):
watcher = LolWatcher(api_key="RGAPI-this-is-a-fake", default_match_v5=True)
assert isinstance(watcher.match, MatchApiV5)

0 comments on commit 78d6551

Please sign in to comment.