Module valolyticspy.services.api.henrikdev

Expand source code
import requests, sys
sys.path.append("")
from valolyticspy.exceptions import FailedAPIRequestException

class HenrikDevApiClient():
    """
    A client for interacting with the HenrikDev API.

    Attributes:
    - base_url (str): The base URL of the HenrikDev API.

    Methods:
    - get_account_by_riot_id(name: str, tag: str, force: bool = False) -> dict:
        Retrieves the account information by Riot ID.

    - get_account_by_puuid(puuid: str, force: bool = False) -> dict:
        Retrieves the account information by PUUID.

    - get_lifetime_matches_by_puuid(affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict:
        Retrieves the lifetime matches by PUUID.

    - handle_request(endpoint: str, headers: dict = {'user-agent': 'mozilla/5.0'}) -> dict:
        Handles the API request and returns the response data.
    """

    base_url:str = "https://api.henrikdev.xyz/"

    def get_account_by_riot_id(self, name: str, tag: str, force: bool = False) -> dict:
        """
        Retrieves the account information for a given Riot ID.

        Args:
            name (str): The name part of the Riot ID.
            tag (str): The tag part of the Riot ID.
            force (bool, optional): Whether to force the request even if the data is already cached. Defaults to False.

        Returns:
            dict: The account information for the given Riot ID.
        """
        data = self.handle_request(f"/valorant/v1/account/{name}/{tag}?force={force}")
        return data
    
    def get_account_by_puuid(self, puuid:str, force:bool=False) -> dict:
            """
            Retrieves the account information associated with the given PUUID.

            Args:
                puuid (str): The PUUID of the account.
                force (bool, optional): Whether to force the API to fetch the data again. Defaults to False.

            Returns:
                dict: The account information as a dictionary.
            """
            data = self.handle_request(f"/valorant/v1/by-puuid/account/{puuid}?force={force}")
            return data
    
    def get_lifetime_matches_by_puuid(self, affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict:
        """
        Retrieves lifetime matches for a player by their PUUID.

        Args:
            affinity (str): The affinity of the player.
            puuid (str): The PUUID of the player.
            mode (str, optional): The game mode. Defaults to None.
            map (str, optional): The map. Defaults to None.
            page (int, optional): The page number. Defaults to None.
            size (int, optional): The number of matches per page. Defaults to None.

        Returns:
            dict: The lifetime matches data for the player.
        """
        url = f"/valorant/v1/by-puuid/lifetime/{affinity}/{puuid}?"
        url += f"mode={mode}&" if mode else ""
        url += f"map={map}&" if map else ""
        url += f"page={page}&" if page else ""
        url += f"size={size}" if size else ""
        data = self.handle_request(url)
        return data
    
    def handle_request(self, endpoint:str, headers:dict={'user-agent': 'mozilla/5.0'}) -> dict:
        """
        Sends a GET request to the specified endpoint with the given headers.

        Args:
            endpoint (str): The endpoint to send the request to.
            headers (dict, optional): The headers to include in the request. Defaults to {'user-agent': 'mozilla/5.0'}.

        Returns:
            dict: The JSON response from the API.

        Raises:
            FailedAPIRequestException: If the response status code is not 200.
        """
        response = requests.get(f"{self.base_url}{endpoint}", headers=headers)
        if(response.status_code != 200):
            raise FailedAPIRequestException()
        return response.json()

Classes

class HenrikDevApiClient

A client for interacting with the HenrikDev API.

Attributes: - base_url (str): The base URL of the HenrikDev API.

Methods: - get_account_by_riot_id(name: str, tag: str, force: bool = False) -> dict: Retrieves the account information by Riot ID.

  • get_account_by_puuid(puuid: str, force: bool = False) -> dict: Retrieves the account information by PUUID.

  • get_lifetime_matches_by_puuid(affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict: Retrieves the lifetime matches by PUUID.

  • handle_request(endpoint: str, headers: dict = {'user-agent': 'mozilla/5.0'}) -> dict: Handles the API request and returns the response data.

Expand source code
class HenrikDevApiClient():
    """
    A client for interacting with the HenrikDev API.

    Attributes:
    - base_url (str): The base URL of the HenrikDev API.

    Methods:
    - get_account_by_riot_id(name: str, tag: str, force: bool = False) -> dict:
        Retrieves the account information by Riot ID.

    - get_account_by_puuid(puuid: str, force: bool = False) -> dict:
        Retrieves the account information by PUUID.

    - get_lifetime_matches_by_puuid(affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict:
        Retrieves the lifetime matches by PUUID.

    - handle_request(endpoint: str, headers: dict = {'user-agent': 'mozilla/5.0'}) -> dict:
        Handles the API request and returns the response data.
    """

    base_url:str = "https://api.henrikdev.xyz/"

    def get_account_by_riot_id(self, name: str, tag: str, force: bool = False) -> dict:
        """
        Retrieves the account information for a given Riot ID.

        Args:
            name (str): The name part of the Riot ID.
            tag (str): The tag part of the Riot ID.
            force (bool, optional): Whether to force the request even if the data is already cached. Defaults to False.

        Returns:
            dict: The account information for the given Riot ID.
        """
        data = self.handle_request(f"/valorant/v1/account/{name}/{tag}?force={force}")
        return data
    
    def get_account_by_puuid(self, puuid:str, force:bool=False) -> dict:
            """
            Retrieves the account information associated with the given PUUID.

            Args:
                puuid (str): The PUUID of the account.
                force (bool, optional): Whether to force the API to fetch the data again. Defaults to False.

            Returns:
                dict: The account information as a dictionary.
            """
            data = self.handle_request(f"/valorant/v1/by-puuid/account/{puuid}?force={force}")
            return data
    
    def get_lifetime_matches_by_puuid(self, affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict:
        """
        Retrieves lifetime matches for a player by their PUUID.

        Args:
            affinity (str): The affinity of the player.
            puuid (str): The PUUID of the player.
            mode (str, optional): The game mode. Defaults to None.
            map (str, optional): The map. Defaults to None.
            page (int, optional): The page number. Defaults to None.
            size (int, optional): The number of matches per page. Defaults to None.

        Returns:
            dict: The lifetime matches data for the player.
        """
        url = f"/valorant/v1/by-puuid/lifetime/{affinity}/{puuid}?"
        url += f"mode={mode}&" if mode else ""
        url += f"map={map}&" if map else ""
        url += f"page={page}&" if page else ""
        url += f"size={size}" if size else ""
        data = self.handle_request(url)
        return data
    
    def handle_request(self, endpoint:str, headers:dict={'user-agent': 'mozilla/5.0'}) -> dict:
        """
        Sends a GET request to the specified endpoint with the given headers.

        Args:
            endpoint (str): The endpoint to send the request to.
            headers (dict, optional): The headers to include in the request. Defaults to {'user-agent': 'mozilla/5.0'}.

        Returns:
            dict: The JSON response from the API.

        Raises:
            FailedAPIRequestException: If the response status code is not 200.
        """
        response = requests.get(f"{self.base_url}{endpoint}", headers=headers)
        if(response.status_code != 200):
            raise FailedAPIRequestException()
        return response.json()

Class variables

var base_url : str

Methods

def get_account_by_puuid(self, puuid: str, force: bool = False) ‑> dict

Retrieves the account information associated with the given PUUID.

Args

puuid : str
The PUUID of the account.
force : bool, optional
Whether to force the API to fetch the data again. Defaults to False.

Returns

dict
The account information as a dictionary.
Expand source code
def get_account_by_puuid(self, puuid:str, force:bool=False) -> dict:
        """
        Retrieves the account information associated with the given PUUID.

        Args:
            puuid (str): The PUUID of the account.
            force (bool, optional): Whether to force the API to fetch the data again. Defaults to False.

        Returns:
            dict: The account information as a dictionary.
        """
        data = self.handle_request(f"/valorant/v1/by-puuid/account/{puuid}?force={force}")
        return data
def get_account_by_riot_id(self, name: str, tag: str, force: bool = False) ‑> dict

Retrieves the account information for a given Riot ID.

Args

name : str
The name part of the Riot ID.
tag : str
The tag part of the Riot ID.
force : bool, optional
Whether to force the request even if the data is already cached. Defaults to False.

Returns

dict
The account information for the given Riot ID.
Expand source code
def get_account_by_riot_id(self, name: str, tag: str, force: bool = False) -> dict:
    """
    Retrieves the account information for a given Riot ID.

    Args:
        name (str): The name part of the Riot ID.
        tag (str): The tag part of the Riot ID.
        force (bool, optional): Whether to force the request even if the data is already cached. Defaults to False.

    Returns:
        dict: The account information for the given Riot ID.
    """
    data = self.handle_request(f"/valorant/v1/account/{name}/{tag}?force={force}")
    return data
def get_lifetime_matches_by_puuid(self, affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) ‑> dict

Retrieves lifetime matches for a player by their PUUID.

Args

affinity : str
The affinity of the player.
puuid : str
The PUUID of the player.
mode : str, optional
The game mode. Defaults to None.
map : str, optional
The map. Defaults to None.
page : int, optional
The page number. Defaults to None.
size : int, optional
The number of matches per page. Defaults to None.

Returns

dict
The lifetime matches data for the player.
Expand source code
def get_lifetime_matches_by_puuid(self, affinity: str, puuid: str, mode: str = None, map: str = None, page: int = None, size: int = None) -> dict:
    """
    Retrieves lifetime matches for a player by their PUUID.

    Args:
        affinity (str): The affinity of the player.
        puuid (str): The PUUID of the player.
        mode (str, optional): The game mode. Defaults to None.
        map (str, optional): The map. Defaults to None.
        page (int, optional): The page number. Defaults to None.
        size (int, optional): The number of matches per page. Defaults to None.

    Returns:
        dict: The lifetime matches data for the player.
    """
    url = f"/valorant/v1/by-puuid/lifetime/{affinity}/{puuid}?"
    url += f"mode={mode}&" if mode else ""
    url += f"map={map}&" if map else ""
    url += f"page={page}&" if page else ""
    url += f"size={size}" if size else ""
    data = self.handle_request(url)
    return data
def handle_request(self, endpoint: str, headers: dict = {'user-agent': 'mozilla/5.0'}) ‑> dict

Sends a GET request to the specified endpoint with the given headers.

Args

endpoint : str
The endpoint to send the request to.
headers : dict, optional
The headers to include in the request. Defaults to {'user-agent': 'mozilla/5.0'}.

Returns

dict
The JSON response from the API.

Raises

FailedAPIRequestException
If the response status code is not 200.
Expand source code
def handle_request(self, endpoint:str, headers:dict={'user-agent': 'mozilla/5.0'}) -> dict:
    """
    Sends a GET request to the specified endpoint with the given headers.

    Args:
        endpoint (str): The endpoint to send the request to.
        headers (dict, optional): The headers to include in the request. Defaults to {'user-agent': 'mozilla/5.0'}.

    Returns:
        dict: The JSON response from the API.

    Raises:
        FailedAPIRequestException: If the response status code is not 200.
    """
    response = requests.get(f"{self.base_url}{endpoint}", headers=headers)
    if(response.status_code != 200):
        raise FailedAPIRequestException()
    return response.json()