Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_shards():
"""
https://developer.riotgames.com/api/methods#!/908/3143
Returns:
list: the shards (unfortunately neither Crystal nor Kirby's)
"""
request = "http://status.leagueoflegends.com/shards"
return [cassiopeia.type.dto.status.Shard(shard) for shard in cassiopeia.dto.requests.get(request, static=True, include_base=False)]
def get_champion_status(id_):
"""
https://developer.riotgames.com/api/methods#!/1015/3443
Args:
id (int): the ID of the champion to look up
Returns:
Champion: the champion
"""
request = "{version}/champion/{id_}".format(version=cassiopeia.dto.requests.api_versions["champion"], id_=id_)
return cassiopeia.type.dto.champion.Champion(cassiopeia.dto.requests.get(request))
def get_recent_games(summoner_id):
"""
https://developer.riotgames.com/api/methods#!/1016/3445
Args:
summoner_id (int): the ID of the summoner to find recent games for
Returns:
RecentGames: the summoner's recent games
"""
request = "{version}/game/by-summoner/{summoner_id}/recent".format(version=cassiopeia.dto.requests.api_versions["game"], summoner_id=summoner_id)
return cassiopeia.type.dto.game.RecentGames(cassiopeia.dto.requests.get(request))
Args:
summoner_ids (int | list): the summoner ID(s) to look up
Returns:
dict: the requested summoners
"""
# Can only have 40 summoners max if it's a list
if isinstance(summoner_ids, list) and len(summoner_ids) > 40:
raise ValueError("Can only get up to 40 summoners at once.")
id_string = ",".join(str(x) for x in summoner_ids) if isinstance(summoner_ids, list) else str(summoner_ids)
# Get JSON response
request = "{version}/summoner/{ids}".format(version=cassiopeia.dto.requests.api_versions["summoner"], ids=id_string)
response = cassiopeia.dto.requests.get(request)
# Convert response to Dto type
for id_, summoner in response.items():
response[id_] = cassiopeia.type.dto.summoner.Summoner(summoner)
return response
def get_maps():
"""
https://developer.riotgames.com/api/methods#!/968/3328
Returns:
MapData: specific information about each map
"""
request = "{version}/map".format(version=cassiopeia.dto.requests.api_versions["staticdata"])
params = {}
if _locale:
params["locale"] = _locale
return cassiopeia.type.dto.staticdata.MapData(cassiopeia.dto.requests.get(request, params, True))
def get_tournament_code(tournament_code):
"""
https://developer.riotgames.com/api/methods#!/1057/3643
Args:
tournament_code (str): the tournament code to get information about
Returns:
TournamentCode: information about the tournament code
"""
request = "https://{server}.api.pvp.net/tournament/public/{version}/code/{code}".format(server=cassiopeia.dto.requests.region, version=cassiopeia.dto.requests.api_versions["tournament"], code=tournament_code)
return cassiopeia.type.dto.tournament.TournamentCode(cassiopeia.dto.requests.get(request, include_base=False, tournament=True))
Args:
summoner_ids (int | list): the summoner ID(s) to get leagues for
Returns:
dict>: the summoner(s)' leagues
"""
# Can only have 10 summoners max if it's a list
if isinstance(summoner_ids, list) and len(summoner_ids) > 10:
raise ValueError("Can only get leagues for up to 10 summoners at once.")
id_string = ",".join(str(x) for x in summoner_ids) if isinstance(summoner_ids, list) else str(summoner_ids)
# Get JSON response
request = "{version}/league/by-summoner/{ids}".format(version=cassiopeia.dto.requests.api_versions["league"], ids=id_string)
response = cassiopeia.dto.requests.get(request)
# Convert response to Dto type
for id_, leagues in response.items():
for i, league in enumerate(leagues):
leagues[i] = cassiopeia.type.dto.league.League(league)
return response
def get_champion_mastery_score(summoner_id):
"""
https://developer.riotgames.com/api/methods#!/1034/3546
Args:
summoner_id (int): the summoner ID to get champion masteries for
Returns:
int: the summoner's total champion mastery score
"""
region = cassiopeia.type.core.common.Region(cassiopeia.dto.requests.region)
platform = cassiopeia.type.core.common.Platform[region.name]
# Get JSON response
request = "https://{server}.api.pvp.net/championmastery/location/{platform}/player/{summonerId}/score".format(server=cassiopeia.dto.requests.region, platform=platform.value, summonerId=summoner_id)
return cassiopeia.dto.requests.get(request, include_base=False)
"""
https://developer.riotgames.com/api/methods#!/1034/3540
Args:
summoner_id (int): the summoner ID to get champion masteries for
count (int): the maximum number of entires to retrieve (default 3)
Returns:
list: the summoner's top champion masteries
"""
region = cassiopeia.type.core.common.Region(cassiopeia.dto.requests.region)
platform = cassiopeia.type.core.common.Platform[region.name]
# Get JSON response
request = "https://{server}.api.pvp.net/championmastery/location/{platform}/player/{summonerId}/topchampions".format(server=cassiopeia.dto.requests.region, platform=platform.value, summonerId=summoner_id)
response = cassiopeia.dto.requests.get(request, {"count": count}, include_base=False)
# Convert response to Dto type
return [cassiopeia.type.dto.championmastery.ChampionMastery(cm) for cm in response]
def get_challenger(queue_type):
"""
https://developer.riotgames.com/api/methods#!/985/3353
Args:
queue_type (str): the queue type to get the challenger league for ("RANKED_SOLO_5x5", "RANKED_TEAM_3x3", "RANKED_TEAM_5x5")
Returns:
League: the challenger league
"""
request = "{version}/league/challenger".format(version=cassiopeia.dto.requests.api_versions["league"])
return cassiopeia.type.dto.league.League(cassiopeia.dto.requests.get(request, {"type": queue_type}))