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 the league-v4/entries/by-puuid endpoint #248

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ raised as HTTPError exceptions from the Requests library.

# all objects are returned (by default) as a dict
# lets see if i got diamond yet (i probably didnt)
my_ranked_stats = lol_watcher.league.by_summoner(my_region, me['id'])
my_ranked_stats = lol_watcher.league.by_puuid(my_region, me['puuid'])
print(my_ranked_stats)

# First we get the latest version of the game from data dragon
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ raised as HTTPError exceptions from the Requests library.

# all objects are returned (by default) as a dict
# lets see if i got diamond yet (i probably didnt)
my_ranked_stats = lol_watcher.league.by_summoner(my_region, me['id'])
my_ranked_stats = lol_watcher.league.by_puuid(my_region, me['puuid'])
print(my_ranked_stats)

# First we get the latest version of the game from data dragon
Expand Down
16 changes: 16 additions & 0 deletions src/riotwatcher/_apis/league_of_legends/LeagueApiV4.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def by_summoner(self, region: str, encrypted_summoner_id: str):
encrypted_summoner_id=encrypted_summoner_id,
)

def by_puuid(self, region: str, puuid: str):
"""
Get league entries in all queues for a given puuid

:param string region: the region to execute this request on
:param string puuid: the puuid to query

:returns: Set[LeagueEntryDTO]
"""
return self._request_endpoint(
self.by_puuid.__name__,
region,
LeagueApiV4Urls.by_puuid,
puuid=puuid,
)

def entries(self, region: str, queue: str, tier: str, division: str, page: int = 1):
"""
Get all the league entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class LeagueApiV4Urls:
by_id = LeagueV4Endpoint("/leagues/{league_id}")
master_by_queue = LeagueV4Endpoint("/masterleagues/by-queue/{queue}")
by_summoner = LeagueV4Endpoint("/entries/by-summoner/{encrypted_summoner_id}")
by_puuid = LeagueV4Endpoint("/entries/by-puuid/{puuid}")
entries = LeagueV4Endpoint("/entries/{queue}/{tier}/{division}", page=int)
21 changes: 21 additions & 0 deletions tests/_apis/league_of_legends/test_LeagueApiV4.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@ def test_by_summoner(self):

assert ret is expected_return

def test_by_puuid(self):
mock_base_api = MagicMock()
expected_return = object()
mock_base_api.raw_request.return_value = expected_return

league = LeagueApiV4(mock_base_api)
region = "fdsga"
puuid = "puuid_1"

ret = league.by_puuid(region, puuid)

mock_base_api.raw_request.assert_called_once_with(
LeagueApiV4.__name__,
league.by_puuid.__name__,
region,
f"https://{region}.api.riotgames.com/lol/league/v4/entries/by-puuid/{puuid}",
{},
)

assert ret is expected_return

def test_entries(self):
mock_base_api = MagicMock()
expected_return = object()
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/league_of_legends/test_LeagueApiV4.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def test_by_id(self, lol_context, region, league_id):
actual_response = lol_context.watcher.league.by_id(region, league_id)

lol_context.verify_api_call(
region, f"/lol/league/v4/leagues/{league_id}", {}, actual_response,
region,
f"/lol/league/v4/leagues/{league_id}",
{},
actual_response,
)

@pytest.mark.parametrize(
Expand All @@ -82,6 +85,17 @@ def test_by_summoner(self, lol_context, region, encrypted_summoner_id):
actual_response,
)

@pytest.mark.parametrize("puuid", ["dQw4w9WgXcQ", "12093qowie"])
def test_by_puuid(self, lol_context, region, puuid):
actual_response = lol_context.watcher.league.by_puuid(region, puuid)

lol_context.verify_api_call(
region,
f"/lol/league/v4/entries/by-puuid/{puuid}",
{},
actual_response,
)

@pytest.mark.parametrize("queue", queues)
@pytest.mark.parametrize("tier", ["IRON", "SILVER", "DIAMOND"])
@pytest.mark.parametrize("division", ["I", "IV"])
Expand Down
Loading