Module valolyticspy.services.api.riot

Expand source code
import requests, sys
sys.path.append("")
from valolyticspy.exceptions import FailedAPIRequestException
from valolyticspy.dtos.riot.enums import AccountRegion, MatchRegion
from valolyticspy.dtos.riot.account import AccountDto
from valolyticspy.dtos.riot.active_shard import ActiveShardDto
from valolyticspy.dtos.riot.match import MatchDto
from valolyticspy.dtos.riot.matchlist import MatchlistDto
from valolyticspy.dtos.riot.recent_matches import RecentMatchesDto
from valolyticspy.models.match import MatchModel

class RiotClient:
    """
    A client for interacting with the Riot Games API.

    Attributes:
        RIOT_API_KEY (str): The API key used for making requests to the Riot Games API.

    Methods:
        __init__(api_key: str): Initializes a new instance of the RiotClient class.
        get_account_by_riot_id(game_name: str, tag_line: str, region: AccountRegion) -> AccountDto:
            Retrieves the account information by Riot ID.
        get_account_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto:
            Retrieves the account information by PUUID.
        get_active_shard_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto:
            Retrieves the active shard information by PUUID.
        get_match_by_match_id(matchid: str, region: MatchRegion) -> MatchModel:
            Retrieves the match information by match ID.
        get_matchlist_by_puuid(puuid: str, region: MatchRegion) -> MatchlistDto:
            Retrieves the matchlist information by PUUID.
        get_recent_matches_by_queue(queue: str, region: MatchRegion) -> MatchlistDto:
            Retrieves the recent matches information by queue.
        handle_request(url: str) -> dict:
            Handles the HTTP request to the Riot Games API.

    """

    RIOT_API_KEY: str

    def __init__(self, api_key: str) -> None:
        """
        Initializes a new instance of the RiotClient class.

        Args:
            api_key (str): The API key used for making requests to the Riot Games API.

        """
        self.RIOT_API_KEY = api_key

    def get_account_by_riot_id(self, game_name: str, tag_line: str, region: AccountRegion) -> AccountDto:
        """
        Retrieves the account information by Riot ID.

        Args:
            game_name (str): The game name associated with the Riot ID.
            tag_line (str): The tag line associated with the Riot ID.
            region (AccountRegion): The region where the account is located.

        Returns:
            AccountDto: The account information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-riot-id/{game_name}/{tag_line}")
        return AccountDto(**data)

    def get_account_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto:
        """
        Retrieves the account information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

        Returns:
            AccountDto: The account information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-puuid/{puuid}")
        return AccountDto(**data)

    def get_active_shard_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto:
        """
        Retrieves the active shard information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

        Returns:
            ActiveShardDto: The active shard information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/active-shards/by-game/val/by-puuid/{puuid}")
        return ActiveShardDto(**data)

    def get_match_by_match_id(self, matchid: str, region: MatchRegion) -> MatchModel:
        """
        Retrieves the match information by match ID.

        Args:
            matchid (str): The ID of the match.
            region (MatchRegion): The region where the match is located.

        Returns:
            MatchModel: The match information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matches/{matchid}")
        return MatchModel(MatchDto(**data))

    def get_matchlist_by_puuid(self, puuid: str, region: MatchRegion) -> MatchlistDto:
        """
        Retrieves the matchlist information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (MatchRegion): The region where the account is located.

        Returns:
            MatchlistDto: The matchlist information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matchlists/by-puuid/{puuid}")
        return MatchlistDto(**data)
    
    def get_recent_matches_by_queue(self, queue: str, region: MatchRegion) -> MatchlistDto:
        """
        Retrieves the recent matches information by queue.

        Args:
            queue (str): The queue type.
            region (MatchRegion): The region where the matches are located.

        Returns:
            RecentMatchesDto: The recent matches information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/recent-matches/by-queue/{queue}")
        return RecentMatchesDto(**data)
    
    def handle_request(self, url: str) -> dict:
        """
        Handles the HTTP request to the Riot Games API.

        Args:
            url (str): The URL of the API endpoint.

        Returns:
            dict: The response data as a dictionary.

        Raises:
            FailedAPIRequestException: If the API request fails.

        """
        response = requests.get(url, headers={'user-agent': 'mozilla/5.0', 'X-Riot-Token': self.RIOT_API_KEY})
        if(response.status_code != 200):
            raise FailedAPIRequestException()
        return response.json()

Classes

class RiotClient (api_key: str)

A client for interacting with the Riot Games API.

Attributes

RIOT_API_KEY : str
The API key used for making requests to the Riot Games API.

Methods

init(api_key: str): Initializes a new instance of the RiotClient class. get_account_by_riot_id(game_name: str, tag_line: str, region: AccountRegion) -> AccountDto: Retrieves the account information by Riot ID. get_account_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto: Retrieves the account information by PUUID. get_active_shard_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto: Retrieves the active shard information by PUUID. get_match_by_match_id(matchid: str, region: MatchRegion) -> MatchModel: Retrieves the match information by match ID. get_matchlist_by_puuid(puuid: str, region: MatchRegion) -> MatchlistDto: Retrieves the matchlist information by PUUID. get_recent_matches_by_queue(queue: str, region: MatchRegion) -> MatchlistDto: Retrieves the recent matches information by queue. handle_request(url: str) -> dict: Handles the HTTP request to the Riot Games API.

Initializes a new instance of the RiotClient class.

Args

api_key : str
The API key used for making requests to the Riot Games API.
Expand source code
class RiotClient:
    """
    A client for interacting with the Riot Games API.

    Attributes:
        RIOT_API_KEY (str): The API key used for making requests to the Riot Games API.

    Methods:
        __init__(api_key: str): Initializes a new instance of the RiotClient class.
        get_account_by_riot_id(game_name: str, tag_line: str, region: AccountRegion) -> AccountDto:
            Retrieves the account information by Riot ID.
        get_account_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto:
            Retrieves the account information by PUUID.
        get_active_shard_by_puuid(puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto:
            Retrieves the active shard information by PUUID.
        get_match_by_match_id(matchid: str, region: MatchRegion) -> MatchModel:
            Retrieves the match information by match ID.
        get_matchlist_by_puuid(puuid: str, region: MatchRegion) -> MatchlistDto:
            Retrieves the matchlist information by PUUID.
        get_recent_matches_by_queue(queue: str, region: MatchRegion) -> MatchlistDto:
            Retrieves the recent matches information by queue.
        handle_request(url: str) -> dict:
            Handles the HTTP request to the Riot Games API.

    """

    RIOT_API_KEY: str

    def __init__(self, api_key: str) -> None:
        """
        Initializes a new instance of the RiotClient class.

        Args:
            api_key (str): The API key used for making requests to the Riot Games API.

        """
        self.RIOT_API_KEY = api_key

    def get_account_by_riot_id(self, game_name: str, tag_line: str, region: AccountRegion) -> AccountDto:
        """
        Retrieves the account information by Riot ID.

        Args:
            game_name (str): The game name associated with the Riot ID.
            tag_line (str): The tag line associated with the Riot ID.
            region (AccountRegion): The region where the account is located.

        Returns:
            AccountDto: The account information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-riot-id/{game_name}/{tag_line}")
        return AccountDto(**data)

    def get_account_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto:
        """
        Retrieves the account information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

        Returns:
            AccountDto: The account information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-puuid/{puuid}")
        return AccountDto(**data)

    def get_active_shard_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto:
        """
        Retrieves the active shard information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

        Returns:
            ActiveShardDto: The active shard information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/active-shards/by-game/val/by-puuid/{puuid}")
        return ActiveShardDto(**data)

    def get_match_by_match_id(self, matchid: str, region: MatchRegion) -> MatchModel:
        """
        Retrieves the match information by match ID.

        Args:
            matchid (str): The ID of the match.
            region (MatchRegion): The region where the match is located.

        Returns:
            MatchModel: The match information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matches/{matchid}")
        return MatchModel(MatchDto(**data))

    def get_matchlist_by_puuid(self, puuid: str, region: MatchRegion) -> MatchlistDto:
        """
        Retrieves the matchlist information by PUUID.

        Args:
            puuid (str): The PUUID associated with the account.
            region (MatchRegion): The region where the account is located.

        Returns:
            MatchlistDto: The matchlist information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matchlists/by-puuid/{puuid}")
        return MatchlistDto(**data)
    
    def get_recent_matches_by_queue(self, queue: str, region: MatchRegion) -> MatchlistDto:
        """
        Retrieves the recent matches information by queue.

        Args:
            queue (str): The queue type.
            region (MatchRegion): The region where the matches are located.

        Returns:
            RecentMatchesDto: The recent matches information.

        """
        data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/recent-matches/by-queue/{queue}")
        return RecentMatchesDto(**data)
    
    def handle_request(self, url: str) -> dict:
        """
        Handles the HTTP request to the Riot Games API.

        Args:
            url (str): The URL of the API endpoint.

        Returns:
            dict: The response data as a dictionary.

        Raises:
            FailedAPIRequestException: If the API request fails.

        """
        response = requests.get(url, headers={'user-agent': 'mozilla/5.0', 'X-Riot-Token': self.RIOT_API_KEY})
        if(response.status_code != 200):
            raise FailedAPIRequestException()
        return response.json()

Class variables

var RIOT_API_KEY : str

Methods

def get_account_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) ‑> AccountDto

Retrieves the account information by PUUID.

Args

puuid : str
The PUUID associated with the account.
region : AccountRegion, optional
The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

Returns

AccountDto
The account information.
Expand source code
def get_account_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> AccountDto:
    """
    Retrieves the account information by PUUID.

    Args:
        puuid (str): The PUUID associated with the account.
        region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

    Returns:
        AccountDto: The account information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-puuid/{puuid}")
    return AccountDto(**data)
def get_account_by_riot_id(self, game_name: str, tag_line: str, region: AccountRegion) ‑> AccountDto

Retrieves the account information by Riot ID.

Args

game_name : str
The game name associated with the Riot ID.
tag_line : str
The tag line associated with the Riot ID.
region : AccountRegion
The region where the account is located.

Returns

AccountDto
The account information.
Expand source code
def get_account_by_riot_id(self, game_name: str, tag_line: str, region: AccountRegion) -> AccountDto:
    """
    Retrieves the account information by Riot ID.

    Args:
        game_name (str): The game name associated with the Riot ID.
        tag_line (str): The tag line associated with the Riot ID.
        region (AccountRegion): The region where the account is located.

    Returns:
        AccountDto: The account information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/accounts/by-riot-id/{game_name}/{tag_line}")
    return AccountDto(**data)
def get_active_shard_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) ‑> ActiveShardDto

Retrieves the active shard information by PUUID.

Args

puuid : str
The PUUID associated with the account.
region : AccountRegion, optional
The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

Returns

ActiveShardDto
The active shard information.
Expand source code
def get_active_shard_by_puuid(self, puuid: str, region: AccountRegion = AccountRegion.AMERICAS) -> ActiveShardDto:
    """
    Retrieves the active shard information by PUUID.

    Args:
        puuid (str): The PUUID associated with the account.
        region (AccountRegion, optional): The region where the request should be sent. Defaults to AccountRegion.AMERICAS.

    Returns:
        ActiveShardDto: The active shard information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/riot/account/v1/active-shards/by-game/val/by-puuid/{puuid}")
    return ActiveShardDto(**data)
def get_match_by_match_id(self, matchid: str, region: MatchRegion) ‑> MatchModel

Retrieves the match information by match ID.

Args

matchid : str
The ID of the match.
region : MatchRegion
The region where the match is located.

Returns

MatchModel
The match information.
Expand source code
def get_match_by_match_id(self, matchid: str, region: MatchRegion) -> MatchModel:
    """
    Retrieves the match information by match ID.

    Args:
        matchid (str): The ID of the match.
        region (MatchRegion): The region where the match is located.

    Returns:
        MatchModel: The match information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matches/{matchid}")
    return MatchModel(MatchDto(**data))
def get_matchlist_by_puuid(self, puuid: str, region: MatchRegion) ‑> MatchlistDto

Retrieves the matchlist information by PUUID.

Args

puuid : str
The PUUID associated with the account.
region : MatchRegion
The region where the account is located.

Returns

MatchlistDto
The matchlist information.
Expand source code
def get_matchlist_by_puuid(self, puuid: str, region: MatchRegion) -> MatchlistDto:
    """
    Retrieves the matchlist information by PUUID.

    Args:
        puuid (str): The PUUID associated with the account.
        region (MatchRegion): The region where the account is located.

    Returns:
        MatchlistDto: The matchlist information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/matchlists/by-puuid/{puuid}")
    return MatchlistDto(**data)
def get_recent_matches_by_queue(self, queue: str, region: MatchRegion) ‑> MatchlistDto

Retrieves the recent matches information by queue.

Args

queue : str
The queue type.
region : MatchRegion
The region where the matches are located.

Returns

RecentMatchesDto
The recent matches information.
Expand source code
def get_recent_matches_by_queue(self, queue: str, region: MatchRegion) -> MatchlistDto:
    """
    Retrieves the recent matches information by queue.

    Args:
        queue (str): The queue type.
        region (MatchRegion): The region where the matches are located.

    Returns:
        RecentMatchesDto: The recent matches information.

    """
    data = self.handle_request(f"https://{region.value}.api.riotgames.com/val/match/v1/recent-matches/by-queue/{queue}")
    return RecentMatchesDto(**data)
def handle_request(self, url: str) ‑> dict

Handles the HTTP request to the Riot Games API.

Args

url : str
The URL of the API endpoint.

Returns

dict
The response data as a dictionary.

Raises

FailedAPIRequestException
If the API request fails.
Expand source code
def handle_request(self, url: str) -> dict:
    """
    Handles the HTTP request to the Riot Games API.

    Args:
        url (str): The URL of the API endpoint.

    Returns:
        dict: The response data as a dictionary.

    Raises:
        FailedAPIRequestException: If the API request fails.

    """
    response = requests.get(url, headers={'user-agent': 'mozilla/5.0', 'X-Riot-Token': self.RIOT_API_KEY})
    if(response.status_code != 200):
        raise FailedAPIRequestException()
    return response.json()