From 50a44732cd39ae7eb8432e43cb4c45678499532a Mon Sep 17 00:00:00 2001 From: Manuel Raimann Date: Sat, 6 May 2023 00:25:10 +0200 Subject: [PATCH] Huge Refactor --- tests/e2e/test_mmr_details.py | 4 +- tests/e2e/test_store_offers.py | 2 +- tests/unit/endpoints/test_crosshair.py | 1 + tests/unit/endpoints/test_mmr_details.py | 6 +- .../endpoints/test_raw_competitiveupdates.py | 8 +- tests/unit/endpoints/test_raw_matchdetails.py | 8 +- tests/unit/endpoints/test_raw_matchhistory.py | 8 +- tests/unit/endpoints/test_raw_mmr.py | 8 +- tests/unit/endpoints/test_store_offers.py | 4 +- valo_api/endpoint.py | 125 +++++ valo_api/endpoints/__init__.py | 223 +-------- valo_api/endpoints/account_details.py | 240 --------- valo_api/endpoints/content.py | 100 ---- valo_api/endpoints/crosshair.py | 110 ----- valo_api/endpoints/leaderboard.py | 274 ----------- valo_api/endpoints/lifetime_matches.py | 430 ---------------- valo_api/endpoints/match_details.py | 114 ----- valo_api/endpoints/match_history.py | 399 --------------- valo_api/endpoints/mmr_details.py | 458 ------------------ valo_api/endpoints/mmr_history.py | 258 ---------- valo_api/endpoints/raw.py | 213 -------- valo_api/endpoints/status.py | 114 ----- valo_api/endpoints/store_featured.py | 151 ------ valo_api/endpoints/store_offers.py | 145 ------ valo_api/endpoints/version_info.py | 108 ----- valo_api/endpoints/website.py | 114 ----- valo_api/endpoints_config.py | 329 ++++++++++++- 27 files changed, 464 insertions(+), 3490 deletions(-) create mode 100644 valo_api/endpoint.py delete mode 100644 valo_api/endpoints/account_details.py delete mode 100644 valo_api/endpoints/content.py delete mode 100644 valo_api/endpoints/crosshair.py delete mode 100644 valo_api/endpoints/leaderboard.py delete mode 100644 valo_api/endpoints/lifetime_matches.py delete mode 100644 valo_api/endpoints/match_details.py delete mode 100644 valo_api/endpoints/match_history.py delete mode 100644 valo_api/endpoints/mmr_details.py delete mode 100644 valo_api/endpoints/mmr_history.py delete mode 100644 valo_api/endpoints/raw.py delete mode 100644 valo_api/endpoints/status.py delete mode 100644 valo_api/endpoints/store_featured.py delete mode 100644 valo_api/endpoints/store_offers.py delete mode 100644 valo_api/endpoints/version_info.py delete mode 100644 valo_api/endpoints/website.py diff --git a/tests/e2e/test_mmr_details.py b/tests/e2e/test_mmr_details.py index 90652c83..aade1a3f 100644 --- a/tests/e2e/test_mmr_details.py +++ b/tests/e2e/test_mmr_details.py @@ -13,7 +13,7 @@ @settings(deadline=None, max_examples=15) @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), id=st.sampled_from(["ManuelHexe#5777", "jasminaxrose#7024"]), episode=st.one_of( st.none(), @@ -49,7 +49,7 @@ async def test_get_mmr_details_by_name( @settings(deadline=None, max_examples=15) @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), puuid=st.sampled_from( ["ee89b4d9-13d0-5832-8dd7-eb5d8806d918", "930bb0d3-c914-5394-bcf6-0bc81f465bd7"] ), diff --git a/tests/e2e/test_store_offers.py b/tests/e2e/test_store_offers.py index 318b7229..7b4efab2 100644 --- a/tests/e2e/test_store_offers.py +++ b/tests/e2e/test_store_offers.py @@ -10,7 +10,7 @@ @settings(deadline=None, max_examples=15) -@given(version=st.sampled_from(["v1", "v2"])) +@given(version=st.sampled_from(["v2"])) @pytest.mark.asyncio @new_event_loop_decorator async def test_get_store_offers(version: str): diff --git a/tests/unit/endpoints/test_crosshair.py b/tests/unit/endpoints/test_crosshair.py index 480a4291..e05c560d 100644 --- a/tests/unit/endpoints/test_crosshair.py +++ b/tests/unit/endpoints/test_crosshair.py @@ -25,6 +25,7 @@ async def test_get_crosshair_error( url = f"{Config.BASE_URL}/valorant/{version}/crosshair/generate" + crosshair_id = crosshair_id.lower() params = {"id": crosshair_id} responses.add( diff --git a/tests/unit/endpoints/test_mmr_details.py b/tests/unit/endpoints/test_mmr_details.py index d67b722f..e82f47ed 100644 --- a/tests/unit/endpoints/test_mmr_details.py +++ b/tests/unit/endpoints/test_mmr_details.py @@ -21,7 +21,7 @@ @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), region=st.sampled_from(Config.ALL_REGIONS), name=st.text(), tag=st.text(), @@ -83,7 +83,7 @@ async def test_get_mmr_details_by_name( @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), region=st.sampled_from(Config.ALL_REGIONS), name=st.text(), tag=st.text(), @@ -153,7 +153,7 @@ async def test_get_mmr_details_by_name_error( @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), region=st.sampled_from(Config.ALL_REGIONS), puuid=st.uuids(), filter=st.one_of(st.none(), st.sampled_from(["competitive", "unrated"])), diff --git a/tests/unit/endpoints/test_raw_competitiveupdates.py b/tests/unit/endpoints/test_raw_competitiveupdates.py index 69a1bbb3..a1f12687 100644 --- a/tests/unit/endpoints/test_raw_competitiveupdates.py +++ b/tests/unit/endpoints/test_raw_competitiveupdates.py @@ -33,12 +33,12 @@ async def test_get_raw_competitiveupdates(version: str, puuid: UUID, region: str status=200, ) - getattr(valo_api, f"get_raw_data_{version}")( + getattr(valo_api, f"get_raw_competitive_updates_data_{version}")( type=EndpointType.COMPETITIVE_UPDATES, region=region, value=puuid ) assert len(responses.calls) == 1 - getattr(valo_api, "get_raw_data")( + getattr(valo_api, "get_raw_competitive_updates_data")( version=version, type=EndpointType.COMPETITIVE_UPDATES, region=region, @@ -51,7 +51,7 @@ async def test_get_raw_competitiveupdates(version: str, puuid: UUID, region: str f"{url}?region={region}&type=competitiveupdates&value={puuid}", payload=get_mock_response(f"raw_competitiveupdates_{version}.json"), ) - await getattr(valo_api, f"get_raw_data_{version}_async")( + await getattr(valo_api, f"get_raw_competitive_updates_data_{version}_async")( type=EndpointType.COMPETITIVE_UPDATES, region=region, value=puuid ) m.assert_called_once() @@ -61,7 +61,7 @@ async def test_get_raw_competitiveupdates(version: str, puuid: UUID, region: str f"{url}?region={region}&type=competitiveupdates&value={puuid}", payload=get_mock_response(f"raw_competitiveupdates_{version}.json"), ) - await getattr(valo_api, f"get_raw_data_async")( + await getattr(valo_api, f"get_raw_competitive_updates_data_async")( version=version, type=EndpointType.COMPETITIVE_UPDATES, region=region, diff --git a/tests/unit/endpoints/test_raw_matchdetails.py b/tests/unit/endpoints/test_raw_matchdetails.py index da3928f5..1aaf8e21 100644 --- a/tests/unit/endpoints/test_raw_matchdetails.py +++ b/tests/unit/endpoints/test_raw_matchdetails.py @@ -34,12 +34,12 @@ async def test_get_raw_matchdetails(version: str, puuid: UUID, region: str): status=200, ) - getattr(valo_api, f"get_raw_data_{version}")( + getattr(valo_api, f"get_raw_match_details_data_{version}")( type=EndpointType.MATCH_DETAILS, region=region, value=puuid ) assert len(responses.calls) == 1 - getattr(valo_api, "get_raw_data")( + getattr(valo_api, "get_raw_match_details_data")( version=version, type=EndpointType.MATCH_DETAILS, region=region, @@ -52,7 +52,7 @@ async def test_get_raw_matchdetails(version: str, puuid: UUID, region: str): f"{url}?region={region}&type=matchdetails&value={puuid}", payload=get_mock_response(f"raw_matchdetails_{version}.json"), ) - await getattr(valo_api, f"get_raw_data_{version}_async")( + await getattr(valo_api, f"get_raw_match_details_data_{version}_async")( type=EndpointType.MATCH_DETAILS, region=region, value=puuid ) m.assert_called_once() @@ -62,7 +62,7 @@ async def test_get_raw_matchdetails(version: str, puuid: UUID, region: str): f"{url}?region={region}&type=matchdetails&value={puuid}", payload=get_mock_response(f"raw_matchdetails_{version}.json"), ) - await getattr(valo_api, "get_raw_data_async")( + await getattr(valo_api, "get_raw_match_details_data_async")( version=version, type=EndpointType.MATCH_DETAILS, region=region, diff --git a/tests/unit/endpoints/test_raw_matchhistory.py b/tests/unit/endpoints/test_raw_matchhistory.py index d5bd8ecb..a5793179 100644 --- a/tests/unit/endpoints/test_raw_matchhistory.py +++ b/tests/unit/endpoints/test_raw_matchhistory.py @@ -33,12 +33,12 @@ async def test_get_raw_matchhistory(version: str, match_id: UUID, region: str): status=200, ) - getattr(valo_api, f"get_raw_data_{version}")( + getattr(valo_api, f"get_raw_match_history_data_{version}")( type=EndpointType.MATCH_HISTORY, region=region, value=match_id ) assert len(responses.calls) == 1 - getattr(valo_api, "get_raw_data")( + getattr(valo_api, "get_raw_match_history_data")( version=version, type=EndpointType.MATCH_HISTORY, region=region, @@ -51,7 +51,7 @@ async def test_get_raw_matchhistory(version: str, match_id: UUID, region: str): f"{url}?region={region}&type=matchhistory&value={match_id}", payload=get_mock_response(f"raw_matchhistory_{version}.json"), ) - await getattr(valo_api, f"get_raw_data_{version}_async")( + await getattr(valo_api, f"get_raw_match_history_data_{version}_async")( type=EndpointType.MATCH_HISTORY, region=region, value=match_id ) m.assert_called_once() @@ -61,7 +61,7 @@ async def test_get_raw_matchhistory(version: str, match_id: UUID, region: str): f"{url}?region={region}&type=matchhistory&value={match_id}", payload=get_mock_response(f"raw_matchhistory_{version}.json"), ) - await getattr(valo_api, "get_raw_data_async")( + await getattr(valo_api, "get_raw_match_history_data_async")( version=version, type=EndpointType.MATCH_HISTORY, region=region, diff --git a/tests/unit/endpoints/test_raw_mmr.py b/tests/unit/endpoints/test_raw_mmr.py index e582530f..051b4cb1 100644 --- a/tests/unit/endpoints/test_raw_mmr.py +++ b/tests/unit/endpoints/test_raw_mmr.py @@ -33,12 +33,12 @@ async def test_get_raw_mmr(version: str, puuid: UUID, region: str): status=200, ) - getattr(valo_api, f"get_raw_data_{version}")( + getattr(valo_api, f"get_raw_mmr_data_{version}")( type=EndpointType.MMR, region=region, value=puuid ) assert len(responses.calls) == 1 - getattr(valo_api, "get_raw_data")( + getattr(valo_api, "get_raw_mmr_data")( version=version, type=EndpointType.MMR, region=region, @@ -51,7 +51,7 @@ async def test_get_raw_mmr(version: str, puuid: UUID, region: str): f"{url}?region={region}&type=mmr&value={puuid}", payload=get_mock_response(f"raw_mmr_{version}.json"), ) - await getattr(valo_api, f"get_raw_data_{version}_async")( + await getattr(valo_api, f"get_raw_mmr_data_{version}_async")( type=EndpointType.MMR, region=region, value=puuid ) m.assert_called_once() @@ -61,7 +61,7 @@ async def test_get_raw_mmr(version: str, puuid: UUID, region: str): f"{url}?region={region}&type=mmr&value={puuid}", payload=get_mock_response(f"raw_mmr_{version}.json"), ) - await getattr(valo_api, "get_raw_data_async")( + await getattr(valo_api, "get_raw_mmr_data_async")( version=version, type=EndpointType.MMR, region=region, diff --git a/tests/unit/endpoints/test_store_offers.py b/tests/unit/endpoints/test_store_offers.py index 2bd7bcd2..faffdb14 100644 --- a/tests/unit/endpoints/test_store_offers.py +++ b/tests/unit/endpoints/test_store_offers.py @@ -14,7 +14,7 @@ from valo_api.exceptions.valo_api_exception import ValoAPIException -@given(version=st.sampled_from(["v1", "v2"])) +@given(version=st.sampled_from(["v2"])) @responses.activate @pytest.mark.asyncio async def test_get_store_offers(version: str): @@ -53,7 +53,7 @@ async def test_get_store_offers(version: str): @given( - version=st.sampled_from(["v1", "v2"]), + version=st.sampled_from(["v2"]), error_response=st.sampled_from(get_error_responses("store_offers")), ) @responses.activate diff --git a/valo_api/endpoint.py b/valo_api/endpoint.py new file mode 100644 index 00000000..01e82b93 --- /dev/null +++ b/valo_api/endpoint.py @@ -0,0 +1,125 @@ +import json +from typing import ( + Awaitable, + Callable, + Dict, + Generic, + Iterable, + Optional, + Tuple, + Type, + TypeVar, + Union, +) + +import io +from dataclasses import dataclass + +import msgspec +from PIL import Image +from requests import Response +from valo_api.utils.dict_struct import DictStruct + +from valo_api.exceptions.valo_api_exception import ValoAPIException +from valo_api.responses.error_response import ErrorResponse +from valo_api.utils.fetch_endpoint import fetch_endpoint, fetch_endpoint_async + +R = TypeVar("R") + + +def response_type(api_type: R): + class APIResponse(DictStruct): + status: int + data: api_type + + return APIResponse + + +@dataclass +class Endpoint(Generic[R]): + path: str + f_name: str + return_type: R + versions: Iterable[str] = ("v1",) + method: str = "GET" + kwargs: Optional[Dict[str, Type]] = None + query_args: Optional[Dict[str, str]] = None + data_response: bool = True + + def endpoint_wrappers( + self, + ) -> Iterable[Tuple[str, Callable[..., Union[R, Awaitable[R]]]]]: + for version in self.versions: + yield f"{self.f_name}_{version}", self._get_endpoint_wrapper(version) + yield f"{self.f_name}_{version}_async", self._get_endpoint_wrapper( + version, True + ) + yield self.f_name, self._get_endpoint_wrapper() + yield f"{self.f_name}_async", self._get_endpoint_wrapper(async_function=True) + + def _get_endpoint_wrapper( + self, version: Optional[str] = None, async_function: bool = False + ) -> Union[Callable[..., Union[R, Awaitable[R]]]]: + if async_function: + + async def wrapper(**kwargs) -> R: + kwargs["version"] = kwargs.get("version", version) + for k, v in self.kwargs.items(): + kwargs[k] = kwargs.get(k, "") + return await self._get_endpoint_async(**kwargs) + + else: + + def wrapper(**kwargs) -> R: + kwargs["version"] = kwargs.get("version", version) + for k, v in self.kwargs.items(): + kwargs[k] = kwargs.get(k, "") + return self._get_endpoint(**kwargs) + + return wrapper + + def build_query_args(self, **kwargs): + formatted_query_args = ( + { + k: v.format(**kwargs) + for k, v in self.query_args.items() + if v + } + if self.query_args + else None + ) + if formatted_query_args is None: + return {} + filtered_query_args = { + k: str(v).lower() for k, v in formatted_query_args.items() if len(v) > 0 and v.lower() != "none" + } + return filtered_query_args + + def _get_endpoint(self, **kwargs) -> R: + response = fetch_endpoint( + self.path, + method=self.method, + query_args=self.build_query_args(**kwargs), + **kwargs, + ) + return self.parse_response(response, response.content) + + async def _get_endpoint_async(self, **kwargs) -> R: + response, content = await fetch_endpoint_async( + self.path, + method=self.method, + query_args=self.build_query_args(**kwargs), + **kwargs, + ) + return self.parse_response(response, content) + + def parse_response(self, response: Response, content: bytes) -> R: + if response.ok is False: + error = msgspec.json.decode(content, type=ErrorResponse) + error.headers = dict(response.headers) + raise ValoAPIException(error) + if self.return_type == Image.Image: + return Image.open(io.BytesIO(response.content)) + return_type = response_type(self.return_type) if self.data_response else self.return_type + result = msgspec.json.decode(content, type=return_type) + return result.data if self.data_response else result diff --git a/valo_api/endpoints/__init__.py b/valo_api/endpoints/__init__.py index 4f75aa7f..3cac6ee8 100644 --- a/valo_api/endpoints/__init__.py +++ b/valo_api/endpoints/__init__.py @@ -1,216 +1,11 @@ -from valo_api.endpoints.account_details import ( - get_account_details_by_name, - get_account_details_by_name_v1, - get_account_details_by_puuid, - get_account_details_by_puuid_v1, -) -from valo_api.endpoints.content import get_content, get_content_v1 -from valo_api.endpoints.crosshair import get_crosshair, get_crosshair_v1 -from valo_api.endpoints.leaderboard import ( - get_leaderboard, - get_leaderboard_v1, - get_leaderboard_v2, -) -from valo_api.endpoints.lifetime_matches import ( - get_lifetime_matches_by_name, - get_lifetime_matches_by_name_v1, - get_lifetime_matches_by_puuid, - get_lifetime_matches_by_puuid_v1, -) -from valo_api.endpoints.match_details import get_match_details, get_match_details_v2 -from valo_api.endpoints.match_history import ( - get_match_history_by_name, - get_match_history_by_name_v3, - get_match_history_by_puuid, - get_match_history_by_puuid_v3, -) -from valo_api.endpoints.mmr_details import ( - get_mmr_details_by_name, - get_mmr_details_by_name_v1, - get_mmr_details_by_name_v2, - get_mmr_details_by_puuid, - get_mmr_details_by_puuid_v1, - get_mmr_details_by_puuid_v2, -) -from valo_api.endpoints.mmr_history import ( - get_mmr_history_by_name, - get_mmr_history_by_name_v1, - get_mmr_history_by_puuid, - get_mmr_history_by_puuid_v1, -) -from valo_api.endpoints.raw import get_raw_data, get_raw_data_v1 -from valo_api.endpoints.status import get_status, get_status_v1 -from valo_api.endpoints.store_featured import ( - get_store_featured, - get_store_featured_v1, - get_store_featured_v2, -) -from valo_api.endpoints.store_offers import ( - get_store_offers, - get_store_offers_v1, - get_store_offers_v2, -) -from valo_api.endpoints.version_info import get_version_info, get_version_info_v1 -from valo_api.endpoints.website import get_website, get_website_v1 +from valo_api.endpoint import Endpoint +from valo_api.endpoints_config import EndpointsConfig -__all__ = [ - "get_account_details_by_name_v1", - "get_account_details_by_name", - "get_account_details_by_puuid_v1", - "get_account_details_by_puuid", - "get_content_v1", - "get_content", - "get_website_v1", - "get_website", - "get_version_info_v1", - "get_version_info", - "get_store_offers_v1", - "get_store_offers_v2", - "get_store_offers", - "get_store_featured_v1", - "get_store_featured_v2", - "get_store_featured", - "get_status_v1", - "get_status", - "get_mmr_history_by_name_v1", - "get_mmr_history_by_name", - "get_mmr_history_by_puuid_v1", - "get_mmr_history_by_puuid", - "get_mmr_details_by_puuid_v1", - "get_mmr_details_by_puuid_v2", - "get_mmr_details_by_puuid", - "get_mmr_details_by_name_v1", - "get_mmr_details_by_name_v2", - "get_mmr_details_by_name", - "get_match_history_by_puuid_v3", - "get_match_history_by_puuid", - "get_match_history_by_name_v3", - "get_match_history_by_name", - "get_match_details_v2", - "get_match_details", - "get_leaderboard_v1", - "get_leaderboard_v2", - "get_leaderboard", - "get_raw_data_v1", - "get_raw_data", - "get_crosshair_v1", - "get_crosshair", - "get_lifetime_matches_by_name_v1", - "get_lifetime_matches_by_name", - "get_lifetime_matches_by_puuid_v1", - "get_lifetime_matches_by_puuid", -] +function_names = [] +for name, value in EndpointsConfig.__dict__.items(): + if hasattr(value, "value") and isinstance(value.value, Endpoint): + for name, function in value.value.endpoint_wrappers(): + function_names.append(name) + globals()[name] = function -try: - from valo_api.endpoints.account_details import ( - get_account_details_by_name_async, - get_account_details_by_name_v1_async, - get_account_details_by_puuid_async, - get_account_details_by_puuid_v1_async, - ) - from valo_api.endpoints.content import get_content_async, get_content_v1_async - from valo_api.endpoints.crosshair import get_crosshair_async, get_crosshair_v1_async - from valo_api.endpoints.leaderboard import ( - get_leaderboard_async, - get_leaderboard_v1_async, - get_leaderboard_v2_async, - ) - from valo_api.endpoints.lifetime_matches import ( - get_lifetime_matches_by_name_async, - get_lifetime_matches_by_name_v1_async, - get_lifetime_matches_by_puuid_async, - get_lifetime_matches_by_puuid_v1_async, - ) - from valo_api.endpoints.match_details import ( - get_match_details_async, - get_match_details_v2_async, - ) - from valo_api.endpoints.match_history import ( - get_match_history_by_name_async, - get_match_history_by_name_v3_async, - get_match_history_by_puuid_async, - get_match_history_by_puuid_v3_async, - ) - from valo_api.endpoints.mmr_details import ( - get_mmr_details_by_name_async, - get_mmr_details_by_name_v1_async, - get_mmr_details_by_name_v2_async, - get_mmr_details_by_puuid_async, - get_mmr_details_by_puuid_v1_async, - get_mmr_details_by_puuid_v2_async, - ) - from valo_api.endpoints.mmr_history import ( - get_mmr_history_by_name_async, - get_mmr_history_by_name_v1_async, - get_mmr_history_by_puuid_async, - get_mmr_history_by_puuid_v1_async, - ) - from valo_api.endpoints.raw import get_raw_data_async, get_raw_data_v1_async - from valo_api.endpoints.status import get_status_async, get_status_v1_async - from valo_api.endpoints.store_featured import ( - get_store_featured_async, - get_store_featured_v1_async, - get_store_featured_v2_async, - ) - from valo_api.endpoints.store_offers import ( - get_store_offers_async, - get_store_offers_v1_async, - get_store_offers_v2_async, - ) - from valo_api.endpoints.version_info import ( - get_version_info_async, - get_version_info_v1_async, - ) - from valo_api.endpoints.website import get_website_async, get_website_v1_async - - __all__.extend( - [ - "get_account_details_by_name_v1_async", - "get_account_details_by_puuid_v1_async", - "get_account_details_by_name_async", - "get_account_details_by_puuid_async", - "get_content_v1_async", - "get_content_async", - "get_website_v1_async", - "get_website_async", - "get_version_info_v1_async", - "get_version_info_async", - "get_store_offers_v1_async", - "get_store_offers_v2_async", - "get_store_offers_async", - "get_store_featured_v1_async", - "get_store_featured_v2_async", - "get_store_featured_async", - "get_status_v1_async", - "get_status_async", - "get_mmr_history_by_name_v1_async", - "get_mmr_history_by_name_async", - "get_mmr_history_by_puuid_v1_async", - "get_mmr_history_by_puuid_async", - "get_mmr_details_by_puuid_v1_async", - "get_mmr_details_by_puuid_v2_async", - "get_mmr_details_by_puuid_async", - "get_mmr_details_by_name_v1_async", - "get_mmr_details_by_name_v2_async", - "get_mmr_details_by_name_async", - "get_match_history_by_puuid_v3_async", - "get_match_history_by_puuid_async", - "get_match_history_by_name_v3_async", - "get_match_history_by_name_async", - "get_match_details_v2_async", - "get_match_details_async", - "get_leaderboard_v1_async", - "get_leaderboard_v2_async", - "get_leaderboard_async", - "get_raw_data_v1_async", - "get_raw_data_async", - "get_crosshair_v1_async", - "get_crosshair_async", - "get_lifetime_matches_by_name_v1_async", - "get_lifetime_matches_by_name_async", - "get_lifetime_matches_by_puuid_v1_async", - "get_lifetime_matches_by_puuid_async", - ] - ) -except ImportError: - pass +__all__ = function_names diff --git a/valo_api/endpoints/account_details.py b/valo_api/endpoints/account_details.py deleted file mode 100644 index 935073b4..00000000 --- a/valo_api/endpoints/account_details.py +++ /dev/null @@ -1,240 +0,0 @@ -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.account_details import AccountDetailsV1 -from valo_api.responses.error_response import ErrorResponse -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_account_details_by_name_v1( - name: str, tag: str, force_update: bool = False, **kwargs -) -> AccountDetailsV1: - """Get the account details by name for a player using version 1 of the endpoint. - - This is the same as - :py:meth:`get_account_details_by_name(version="v1", name=name, tag=tag, force_update=force_update, **kwargs) ` - - Args: - name: The name of the player to get the account details for. - tag: The tag of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - """ - return get_account_details_by_name("v1", name, tag, force_update, **kwargs) - - -def get_account_details_by_puuid_v1( - puuid: str, force_update: bool = False, **kwargs -) -> AccountDetailsV1: - """Get the account details for a player using version 1 of the endpoint. - - This is the same as - :py:meth:`get_account_details_by_puuid(version="v1", puuid=puuid, force_update=force_update, **kwargs) ` - - Args: - puuid: The puuid of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - """ - return get_account_details_by_puuid("v1", puuid, force_update, **kwargs) - - -def get_account_details_by_name( - version: str, name: str, tag: str, force_update: bool = False, **kwargs -) -> AccountDetailsV1: - """Get the account details by name for a player using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - name: The name of the player to get the account details for. - tag: The tag of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.ACCOUNT_BY_NAME, - version=version, - name=name, - tag=tag, - query_args={"force": str(force_update).lower()}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(AccountDetailsV1) - ).data - - -def get_account_details_by_puuid( - version: str, puuid: str, force_update: bool = False, **kwargs -) -> AccountDetailsV1: - """Get the account details for a player using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - puuid: The puuid of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.ACCOUNT_BY_PUUID, - version=version, - puuid=puuid, - query_args={"force": str(force_update).lower()}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(AccountDetailsV1) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_account_details_by_name_v1_async( - name: str, tag: str, force_update: bool = False, **kwargs - ) -> AccountDetailsV1: - """Get the account details by name for a player using version 1 of the endpoint. - - This is the same as - :py:meth:`get_account_details_by_name_async(version="v1", name=name, tag=tag, force_update=force_update, **kwargs) ` - - Args: - name: The name of the player to get the account details for. - tag: The tag of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - """ - return await get_account_details_by_name_async( - "v1", name, tag, force_update, **kwargs - ) - - async def get_account_details_by_puuid_v1_async( - puuid: str, force_update: bool = False, **kwargs - ): - """Get the account details for a player using version 1 of the endpoint. - - This is the same as - :py:meth:`get_account_details_by_puuid_async(version="v1", puuid=puuid, force_update=force_update, **kwargs) ` - - Args: - puuid: The puuid of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - """ - return await get_account_details_by_puuid_async( - "v1", puuid, force_update, **kwargs - ) - - async def get_account_details_by_name_async( - version: str, name: str, tag: str, force_update: bool = False, **kwargs - ) -> AccountDetailsV1: - """Get the account details by name for a player using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - name: The name of the player to get the account details for. - tag: The tag of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.ACCOUNT_BY_NAME, - version=version, - name=name, - tag=tag, - query_args={"force": str(force_update).lower()}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(content, type=response_type(AccountDetailsV1)).data - - async def get_account_details_by_puuid_async( - version: str, puuid: str, force_update: bool = False, **kwargs - ) -> AccountDetailsV1: - """Get the account details for a player using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - puuid: The puuid of the player to get the account details for. - force_update: Whether to force an update of the account details. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - AccountDetailsV1: Account details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.ACCOUNT_BY_PUUID, - version=version, - puuid=puuid, - query_args={"force": str(force_update).lower()}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(content, type=response_type(AccountDetailsV1)).data - -except ImportError as e: - pass diff --git a/valo_api/endpoints/content.py b/valo_api/endpoints/content.py deleted file mode 100644 index 8a4cb4e4..00000000 --- a/valo_api/endpoints/content.py +++ /dev/null @@ -1,100 +0,0 @@ -from typing import Optional - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.content import ContentV1 -from valo_api.responses.error_response import ErrorResponse -from valo_api.utils.fetch_endpoint import fetch_endpoint - - -def get_content_v1(locale: Optional[str] = None, **kwargs) -> ContentV1: - """Get the content for a specific locale using version 1 of the endpoint. - - This is the same as - :py:meth:`get_content(version="v1", locale=locale, **kwargs) ` - - Args: - locale: The locale to get the content for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - ContentV1: Content fetched from the API. - """ - return get_content("v1", locale, **kwargs) - - -def get_content(version: str, locale: Optional[str] = None, **kwargs) -> ContentV1: - """Get the content for a specific locale using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - locale: The locale to get the content for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - ContentV1: Content fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.CONTENT, - version=version, - query_args={"locale": str(locale).lower()} if locale else None, - **kwargs, - ) - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(response.content, type=ContentV1) - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_content_v1_async(locale: Optional[str] = None, **kwargs) -> ContentV1: - """Get the content for a specific locale using version 1 of the endpoint. - - This is the same as - :py:meth:`get_content_async(version="v1", locale=locale, **kwargs) ` - - Args: - locale: The locale to get the content for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - ContentV1: Content fetched from the API. - """ - return await get_content_async("v1", locale, **kwargs) - - async def get_content_async( - version: str, locale: Optional[str] = None, **kwargs - ) -> ContentV1: - """Get the content for a specific locale using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - locale: The locale to get the content for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - ContentV1: Content fetched from the API. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.CONTENT, - version=version, - query_args={"locale": str(locale).lower()} if locale else None, - **kwargs, - ) - return msgspec.json.decode(content, type=ContentV1) - -except ImportError: - pass diff --git a/valo_api/endpoints/crosshair.py b/valo_api/endpoints/crosshair.py deleted file mode 100644 index 8cbc601d..00000000 --- a/valo_api/endpoints/crosshair.py +++ /dev/null @@ -1,110 +0,0 @@ -import io - -import msgspec.json -from PIL import Image - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.utils.fetch_endpoint import fetch_endpoint - - -def get_crosshair_v1(crosshair_id: str, **kwargs) -> Image.Image: - """Get an image of the crosshair using the v1 endpoint. - - This is the same as - :py:meth:`get_crosshair(version="v1", id=id, **kwargs) ` - - Args: - crosshair_id: The crosshair ID to get the image for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - Image: An image object containing the crosshair image. - """ - return get_crosshair("v1", crosshair_id, **kwargs) - - -def get_crosshair(version: str, crosshair_id: str, **kwargs) -> Image.Image: - """Get an image of the crosshair using the specified endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - crosshair_id: The crosshair ID to get the image for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - Image: An image object containing the crosshair image. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.CROSSHAIR, - version=version, - query_args={"id": crosshair_id}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return Image.open(io.BytesIO(response.content)) - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_crosshair_v1_async(crosshair_id: str, **kwargs) -> Image.Image: - """Get an image of the crosshair using the v1 endpoint. - - This is the same as - :py:meth:`get_crosshair_async(version="v1", id=id, **kwargs) ` - - Args: - crosshair_id: The crosshair ID to get the image for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - Image: An image object containing the crosshair image. - """ - return await get_crosshair_async("v1", crosshair_id, **kwargs) - - async def get_crosshair_async( - version: str, crosshair_id: str, **kwargs - ) -> Image.Image: - """Get an image of the crosshair using the specified endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - crosshair_id: The crosshair ID to get the image for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - Image: An image object containing the crosshair image. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.CROSSHAIR, - version=version, - query_args={"id": crosshair_id}, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return Image.open(io.BytesIO(content)) - -except ImportError: - pass diff --git a/valo_api/endpoints/leaderboard.py b/valo_api/endpoints/leaderboard.py deleted file mode 100644 index 61e87b23..00000000 --- a/valo_api/endpoints/leaderboard.py +++ /dev/null @@ -1,274 +0,0 @@ -from typing import List, Optional, Union - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.leaderboard import LeaderboardPlayerV1, LeaderboardV2 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_leaderboard_v1( - region: str, - puuid: Optional[str] = None, - name: Optional[str] = None, - tag: Optional[str] = None, - season_id: Optional[str] = None, - **kwargs, -) -> List[LeaderboardPlayerV1]: - """Get the leaderboard for a region using version 1 of the endpoint. - - This is the same as - :py:meth:`get_leaderboard(version="v1", region=region, puuid=puuid, name=name, tag=tag, **kwargs) ` - - You can also filter by puuid or name and tag. - - Args: - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the leaderboard for. - name: The name of the player to get the leaderboard for. - tag: The tag of the player to get the leaderboard for. - season_id: The season ID to get the leaderboard for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of LeaderboardPlayerV1 objects. - """ - return get_leaderboard("v1", region, puuid, name, tag, season_id, **kwargs) - - -def get_leaderboard_v2( - region: str, season_id: Optional[str] = None, start: Optional[int] = None, **kwargs -) -> LeaderboardV2: - """Get the leaderboard for a region using version 2 of the endpoint. - - This is the same as :py:meth:`get_leaderboard(version="v2", region=region, **kwargs) ` - - Args: - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - season_id: The season ID to get the leaderboard for. - start: The start index of the leaderboard. Can be used for pagination. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A LeaderboardV2 object. - """ - return get_leaderboard("v2", region, season_id=season_id, start=start, **kwargs) - - -def get_leaderboard( - version: str, - region: str, - puuid: Optional[str] = None, - name: Optional[str] = None, - tag: Optional[str] = None, - season_id: Optional[str] = None, - start: Optional[int] = None, - **kwargs, -) -> Union[LeaderboardV2, List[LeaderboardPlayerV1]]: - """Get the leaderboard for a region using a specific version of the endpoint. - - You can also filter by puuid or name and tag if you are using v1. - - Args: - version: The version of the endpoint. One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the leaderboard for. Only works for leaderboard version 1. - name: The name of the player to get the leaderboard for. Only works for leaderboard version 1. - tag: The tag of the player to get the leaderboard for. Only works for leaderboard version 1. - season_id: The season ID to get the leaderboard for. - start: The start index of the leaderboard. Can be used for pagination. Only works for leaderboard version 1. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - A list of LeaderboardPlayerV1 objects if version is v1. - - A LeaderboardV2 object if version is v2. - - Raises: - ValoAPIException: If the request failed. - """ - if version == "v1" and start is not None: - raise ValoAPIException("start is not allowed for version v1") - if version == "v2": - if puuid is not None or name is not None or tag is not None: - raise ValoAPIException("puuid, name and tag are not allowed for version v2") - - query_args = dict() - if puuid is not None: - query_args["puuid"] = puuid - if name is not None: - query_args["name"] = name - if tag is not None: - query_args["tag"] = tag - if season_id is not None: - query_args["season"] = season_id - if start is not None: - query_args["start"] = start - - response = fetch_endpoint( - EndpointsConfig.LEADERBOARD, - region=region, - version=version, - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - if puuid is not None or name is not None or tag is not None: - return msgspec.json.decode( - response.content, type=response_type(LeaderboardPlayerV1) - ).data - else: - return msgspec.json.decode(response.content, type=List[LeaderboardPlayerV1]) - else: - return msgspec.json.decode(response.content, type=LeaderboardV2) - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_leaderboard_v1_async( - region: str, - puuid: Optional[str] = None, - name: Optional[str] = None, - tag: Optional[str] = None, - season_id: Optional[str] = None, - start: Optional[int] = None, - **kwargs, - ) -> List[LeaderboardPlayerV1]: - """Get the leaderboard for a region using version 1 of the endpoint. - - This is the same as - :py:meth:`get_leaderboard_async(version="v1", region=region, puuid=puuid, name=name, tag=tag, **kwargs) ` - - You can also filter by puuid or name and tag. - - Args: - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the leaderboard for. - name: The name of the player to get the leaderboard for. - tag: The tag of the player to get the leaderboard for. - season_id: The season ID to get the leaderboard for. - start: The start index of the leaderboard. Can be used for pagination. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of LeaderboardPlayerV1 objects. - """ - return await get_leaderboard_async( - "v1", region, puuid, name, tag, season_id, start, **kwargs - ) - - async def get_leaderboard_v2_async( - region: str, season_id: Optional[str] = None, **kwargs - ) -> LeaderboardV2: - """Get the leaderboard for a region using version 2 of the endpoint. - - This is the same as :py:meth:`get_leaderboard_async(version="v2", region=region, **kwargs) ` - - Args: - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - season_id: The season ID to get the leaderboard for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A LeaderboardV2 object. - """ - return await get_leaderboard_async("v2", region, season_id=season_id, **kwargs) - - async def get_leaderboard_async( - version: str, - region: str, - puuid: Optional[str] = None, - name: Optional[str] = None, - tag: Optional[str] = None, - season_id: Optional[str] = None, - start: Optional[int] = None, - **kwargs, - ) -> Union[LeaderboardV2, List[LeaderboardPlayerV1]]: - """Get the leaderboard for a region using a specific version of the endpoint. - - You can also filter by puuid or name and tag if you are using v1. - - Args: - version: The version of the endpoint. One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the leaderboard for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the leaderboard for. Only works for leaderboard version 1. - name: The name of the player to get the leaderboard for. Only works for leaderboard version 1. - tag: The tag of the player to get the leaderboard for. Only works for leaderboard version 1. - season_id: The season ID to get the leaderboard for. - start: The start index of the leaderboard. Can be used for pagination. Only works for leaderboard version 1. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - A list of LeaderboardPlayerV1 objects if version is v1. - - A LeaderboardV2 object if version is v2. - - Raises: - ValoAPIException: If the request failed. - """ - if version == "v2": - if puuid is not None or name is not None or tag is not None: - raise ValoAPIException( - "puuid, name and tag are not allowed for version v2" - ) - if start is not None: - raise ValoAPIException("start is not allowed for version v2") - - query_args = dict() - if puuid is not None: - query_args["puuid"] = puuid - if name is not None: - query_args["name"] = name - if tag is not None: - query_args["tag"] = tag - if season_id is not None: - query_args["season"] = season_id - if start is not None: - query_args["start"] = start - - response, content = await fetch_endpoint_async( - EndpointsConfig.LEADERBOARD, - region=region, - version=version, - query_args=query_args, - **kwargs, - ) - - if response.status != 200: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - if puuid is not None or name is not None or tag is not None: - return msgspec.json.decode( - content, type=response_type(LeaderboardPlayerV1) - ).data - else: - return msgspec.json.decode(content, type=List[LeaderboardPlayerV1]) - else: - return msgspec.json.decode(content, type=LeaderboardV2) - -except ImportError: - pass diff --git a/valo_api/endpoints/lifetime_matches.py b/valo_api/endpoints/lifetime_matches.py deleted file mode 100644 index db6ebe38..00000000 --- a/valo_api/endpoints/lifetime_matches.py +++ /dev/null @@ -1,430 +0,0 @@ -from typing import List, Optional - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.lifetime_match import LifetimeMatchV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_lifetime_matches_by_name_v1( - region: str, - name: str, - tag: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, -) -> LifetimeMatchV1: - """Get the lifetime matches for a player by name using version 1 of the endpoint. - - This is the same as - :py:meth:`get_lifetime_matches_by_name(version="v1", region=region, name=name, tag=tag, mode=mode, map=map, page=page, size=size, **kwargs) ` - - Args: - region: The region to get the match history for. - name: The player's name to get the match history for. - tag: The player's tag to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - return get_lifetime_matches_by_name( - version="v1", - region=region, - name=name, - tag=tag, - mode=mode, - map=map, - page=page, - size=size, - **kwargs, - ) - - -def get_lifetime_matches_by_name( - version: str, - region: str, - name: str, - tag: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, -) -> LifetimeMatchV1: - """Get the lifetime matches for a player by name. - - Args: - version: The version of the endpoint to use. - region: The region to get the match history for. - name: The player's name to get the match history for. - tag: The player's tag to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - assert (size is None) is (page is None), "Page and size must be used together." - assert page is None or page > 0, f"Page must be greater than 0, got {page}." - - query_args = {} - if mode is not None: - query_args["mode"] = mode - if map is not None: - query_args["map"] = map - if page is not None: - query_args["page"] = page - if size is not None: - query_args["size"] = size - - response = fetch_endpoint( - EndpointsConfig.LIFETIME_MATCHES_BY_NAME, - version=version, - query_args=query_args, - region=region, - name=name, - tag=tag, - **kwargs, - ) - - if response.ok is False: - print(response.content) - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[LifetimeMatchV1]) - ).data - - -def get_lifetime_matches_by_puuid_v1( - region: str, - puuid: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, -) -> LifetimeMatchV1: - """Get the lifetime matches for a player by puuid using version 1 of the endpoint. - - This is the same as - :py:meth:`get_lifetime_matches_by_puuid(version="v1", region=region, puuid=puuid, mode=mode, map=map, page=page, size=size, **kwargs) ` - - Args: - region: The region to get the match history for. - puuid: The player's PUUID to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - return get_lifetime_matches_by_puuid( - version="v1", - region=region, - puuid=puuid, - mode=mode, - map=map, - page=page, - size=size, - **kwargs, - ) - - -def get_lifetime_matches_by_puuid( - version: str, - region: str, - puuid: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, -) -> LifetimeMatchV1: - """Get the lifetime matches for a player by puuid. - - Args: - version: The version of the endpoint to use. - region: The region to get the match history for. - puuid: The player's PUUID to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - assert (size is None) is (page is None), "Page and size must be used together." - assert page is None or page > 0, f"Page must be greater than 0, got {page}." - - query_args = {} - if mode is not None: - query_args["mode"] = mode - if map is not None: - query_args["map"] = map - if page is not None: - query_args["page"] = page - if size is not None: - query_args["size"] = size - - response = fetch_endpoint( - EndpointsConfig.LIFETIME_MATCHES_BY_PUUID, - version=version, - query_args=query_args, - region=region, - puuid=puuid, - **kwargs, - ) - - if response.ok is False: - print(response.content) - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[LifetimeMatchV1]) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_lifetime_matches_by_name_v1_async( - region: str, - name: str, - tag: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, - ) -> LifetimeMatchV1: - """Get the lifetime matches for a player by name using version 1 of the endpoint. - - This is the same as - :py:meth:`get_lifetime_matches_by_name(version="v1", region=region, name=name, tag=tag, mode=mode, map=map, page=page, size=size, **kwargs) ` - - Args: - region: The region to get the match history for. - name: The player's name to get the match history for. - tag: The player's tag to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - return await get_lifetime_matches_by_name_async( - version="v1", - region=region, - name=name, - tag=tag, - mode=mode, - map=map, - page=page, - size=size, - **kwargs, - ) - - async def get_lifetime_matches_by_name_async( - version: str, - region: str, - name: str, - tag: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, - ) -> LifetimeMatchV1: - """Get the lifetime matches for a player by name. - - Args: - version: The version of the endpoint to use. - region: The region to get the match history for. - name: The player's name to get the match history for. - tag: The player's tag to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - assert (size is None) is (page is None), "Page and size must be used together." - assert page is None or page > 0, f"Page must be greater than 0, got {page}." - - query_args = {} - if mode is not None: - query_args["mode"] = mode - if map is not None: - query_args["map"] = map - if page is not None: - query_args["page"] = page - if size is not None: - query_args["size"] = size - - response, content = await fetch_endpoint_async( - EndpointsConfig.LIFETIME_MATCHES_BY_NAME, - version=version, - query_args=query_args, - region=region, - name=name, - tag=tag, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[LifetimeMatchV1]) - ).data - - async def get_lifetime_matches_by_puuid_v1_async( - region: str, - puuid: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, - ) -> LifetimeMatchV1: - """Get the lifetime matches for a player by puuid using version 1 of the endpoint. - - This is the same as - :py:meth:`get_lifetime_matches_by_puuid(version="v1", region=region, puuid=puuid, mode=mode, map=map, page=page, size=size, **kwargs) ` - - Args: - region: The region to get the match history for. - puuid: The player's PUUID to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - return await get_lifetime_matches_by_puuid( - version="v1", - region=region, - puuid=puuid, - mode=mode, - map=map, - page=page, - size=size, - **kwargs, - ) - - async def get_lifetime_matches_by_puuid_async( - version: str, - region: str, - puuid: str, - mode: Optional[str] = None, - map: Optional[str] = None, - page: Optional[int] = None, - size: Optional[int] = None, - **kwargs, - ) -> LifetimeMatchV1: - """Get the lifetime matches for a player by puuid. - - Args: - version: The version of the endpoint to use. - region: The region to get the match history for. - puuid: The player's PUUID to get the match history for. - mode: The game mode to get the match history for. - map: The map to get the match history for. - page: The page of the match history to get. - size: The number of matches to get per page. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - LifetimeMatchV1: Match history fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - assert (size is None) is (page is None), "Page and size must be used together." - assert page is None or page > 0, f"Page must be greater than 0, got {page}." - - query_args = {} - if mode is not None: - query_args["mode"] = mode - if map is not None: - query_args["map"] = map - if page is not None: - query_args["page"] = page - if size is not None: - query_args["size"] = size - - response, content = await fetch_endpoint_async( - EndpointsConfig.LIFETIME_MATCHES_BY_PUUID, - version=version, - query_args=query_args, - region=region, - puuid=puuid, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[LifetimeMatchV1]) - ).data - -except ImportError: - pass diff --git a/valo_api/endpoints/match_details.py b/valo_api/endpoints/match_details.py deleted file mode 100644 index 0e28b3b0..00000000 --- a/valo_api/endpoints/match_details.py +++ /dev/null @@ -1,114 +0,0 @@ -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.match_history import MatchHistoryPointV3 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_match_details_v2(match_id: str, **kwargs) -> MatchHistoryPointV3: - """Get the match details for a match using version 2 of the endpoint. - - This is the same as - :py:meth:`get_match_details(version="v2", match_id=match_id, **kwargs) ` - - Args: - match_id: The match ID to get the details for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - MatchHistoryPointV3: Match details fetched from the API. - """ - return get_match_details("v2", match_id, **kwargs) - - -def get_match_details(version: str, match_id: str, **kwargs) -> MatchHistoryPointV3: - """Get the match details for a match using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v2 (Version 2) - match_id: The match ID to get the details for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - MatchHistoryPointV3: Match details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.MATCH_DETAILS, - version=version, - match_id=match_id, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(MatchHistoryPointV3) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_match_details_v2_async( - match_id: str, **kwargs - ) -> MatchHistoryPointV3: - """Get the match details for a match using version 2 of the endpoint. - - This is the same as - :py:meth:`get_match_details_async(version="v2", match_id=match_id, **kwargs) ` - - Args: - match_id: The match ID to get the details for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - MatchHistoryPointV3: Match details fetched from the API. - """ - return await get_match_details_async("v2", match_id, **kwargs) - - async def get_match_details_async( - version: str, match_id: str, **kwargs - ) -> MatchHistoryPointV3: - """Get the match details for a match using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v2 (Version 2) - match_id: The match ID to get the details for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - MatchHistoryPointV3: Match details fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.MATCH_DETAILS, - version=version, - match_id=match_id, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(MatchHistoryPointV3) - ).data - -except ImportError: - pass diff --git a/valo_api/endpoints/match_history.py b/valo_api/endpoints/match_history.py deleted file mode 100644 index b8601ad7..00000000 --- a/valo_api/endpoints/match_history.py +++ /dev/null @@ -1,399 +0,0 @@ -from typing import List, Optional - -import warnings - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.match_history import MatchHistoryPointV3 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_match_history_by_name_v3( - region: str, - name: str, - tag: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, -) -> List[MatchHistoryPointV3]: - """Get the match history for a player by name and tag using version 3 of the endpoint. - - This is the same as :py:meth:`get_match_history_by_name(version="v3", region=region, name=name, tag=tag, - size=size, game_mode=game_mode, **kwargs) ` - - Args: - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player. - tag: The tag of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - """ - return get_match_history_by_name( - "v3", region, name, tag, size, map, game_mode, **kwargs - ) - - -def get_match_history_by_puuid_v3( - region: str, - puuid: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, -) -> List[MatchHistoryPointV3]: - """Get the match history for a player by puuid using version 3 of the endpoint. - - This is the same as :py:meth:`get_match_history_by_puuid(version="v3", region=region, puuid=puuid, size=size, - game_mode=game_mode, **kwargs) ` - - Args: - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - """ - return get_match_history_by_puuid( - "v3", region, puuid, size, map, game_mode, **kwargs - ) - - -def get_match_history_by_name( - version: str, - region: str, - name: str, - tag: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, -) -> List[MatchHistoryPointV3]: - """Get the match history for a player by name and tag using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v3 (Version 3) - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player. - tag: The tag of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - - Raises: - ValoAPIException: If the request failed. - """ - query_args = dict() - if size: - if size > 10: - warnings.warn( - "You cannot fetch more then 10 matches with this endpoint. " - "Size will be reduced to 10. " - "See https://github.com/raimannma/ValorantAPI/issues/181 for a workaround." - ) - query_args["size"] = str(size).lower() - if game_mode: - query_args["filter"] = game_mode.lower() - if map: - query_args["map"] = map.capitalize() - response = fetch_endpoint( - EndpointsConfig.MATCH_HISTORY_BY_NAME, - version=version, - region=region, - name=name, - tag=tag, - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[MatchHistoryPointV3]) - ).data - - -def get_match_history_by_puuid( - version: str, - region: str, - puuid: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, -) -> List[MatchHistoryPointV3]: - """Get the match history for a player by puuid using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v3 (Version 3) - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - - Raises: - ValoAPIException: If the request failed. - """ - query_args = dict() - if size: - if size > 10: - warnings.warn( - "You cannot fetch more then 10 matches with this endpoint. " - "Size will be reduced to 10. " - "See https://github.com/raimannma/ValorantAPI/issues/181 for a workaround." - ) - size = 10 - query_args["size"] = str(size).lower() - if game_mode: - query_args["filter"] = game_mode.lower() - if map: - query_args["map"] = map.capitalize() - response = fetch_endpoint( - EndpointsConfig.MATCH_HISTORY_BY_PUUID, - version=version, - region=region, - puuid=puuid, - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[MatchHistoryPointV3]) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_match_history_by_name_v3_async( - region: str, - name: str, - tag: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, - ) -> List[MatchHistoryPointV3]: - """Get the match history for a player by name and tag using version 3 of the endpoint. - - This is the same as :py:meth:`get_match_history_by_name_async(version="v3", region=region, name=name, tag=tag, - size=size, game_mode=game_mode, **kwargs) ` - - Args: - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player. - tag: The tag of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - """ - return await get_match_history_by_name_async( - "v3", region, name, tag, size, map, game_mode, **kwargs - ) - - async def get_match_history_by_puuid_v3_async( - region: str, - puuid: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, - ) -> List[MatchHistoryPointV3]: - """Get the match history for a player by puuid using version 3 of the endpoint. - - This is the same as :py:meth:`get_match_history_by_puuid_async(version="v3", region=region, puuid=puuid, - size=size, game_mode=game_mode, **kwargs) ` - - Args: - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - """ - return await get_match_history_by_puuid_async( - "v3", region, puuid, size, map, game_mode, **kwargs - ) - - async def get_match_history_by_name_async( - version: str, - region: str, - name: str, - tag: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, - ) -> List[MatchHistoryPointV3]: - """Get the match history for a player by name and tag using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v3 (Version 3) - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player. - tag: The tag of the player. - size: The number of matches to return. Maximum is 10. - map: The map to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - - Raises: - ValoAPIException: If the request failed. - """ - query_args = dict() - if size: - if size > 10: - warnings.warn( - "You cannot fetch more then 10 matches with this endpoint. " - "Size will be reduced to 10. " - "See https://github.com/raimannma/ValorantAPI/issues/181 for a workaround." - ) - size = 10 - query_args["size"] = str(size).lower() - if game_mode: - query_args["filter"] = game_mode.lower() - if map: - query_args["map"] = map.lower() - response, content = await fetch_endpoint_async( - EndpointsConfig.MATCH_HISTORY_BY_NAME, - version=version, - region=region, - name=name, - tag=tag, - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[MatchHistoryPointV3]) - ).data - - async def get_match_history_by_puuid_async( - version: str, - region: str, - puuid: str, - size: Optional[int] = None, - map: Optional[str] = None, - game_mode: Optional[str] = None, - **kwargs, - ) -> List[MatchHistoryPointV3]: - """Get the match history for a player by puuid using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v3 (Version 3) - region: The region of the player. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player. - size: The number of matches to return. Maximum is 10. - map: The game mode to filter by. - game_mode: The game mode to filter by. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MatchHistoryPointV3` objects. - - Raises: - ValoAPIException: If the request failed. - """ - query_args = dict() - if size: - if size > 10: - warnings.warn( - "You cannot fetch more then 10 matches with this endpoint. " - "Size will be reduced to 10. " - "See https://github.com/raimannma/ValorantAPI/issues/181 for a workaround." - ) - size = 10 - query_args["size"] = str(size).lower() - if game_mode: - query_args["filter"] = game_mode.lower() - if map: - query_args["map"] = map.lower() - response, content = await fetch_endpoint_async( - EndpointsConfig.MATCH_HISTORY_BY_PUUID, - version=version, - region=region, - puuid=puuid, - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[MatchHistoryPointV3]) - ).data - -except ImportError: - pass diff --git a/valo_api/endpoints/mmr_details.py b/valo_api/endpoints/mmr_details.py deleted file mode 100644 index 34bf7a81..00000000 --- a/valo_api/endpoints/mmr_details.py +++ /dev/null @@ -1,458 +0,0 @@ -from typing import Optional, Union - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.mmr_details import MMRDetailsV1, MMRDetailsV2, SeasonDataV2 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_mmr_details_by_puuid_v1(region: str, puuid: str, **kwargs) -> MMRDetailsV1: - """Get MMR details by puuid for v1 of the endpoint. - - This is the same as - :py:meth:`get_mmr_details_by_puuid(version="v1", region=region, puuid=puuid, **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - MMRDetailsV1: MMR Details fetched from the API. - """ - return get_mmr_details_by_puuid("v1", region, puuid, **kwargs) - - -def get_mmr_details_by_puuid_v2( - region: str, puuid: str, filter: Optional[str] = None, **kwargs -) -> Union[MMRDetailsV2, SeasonDataV2]: - """Get MMR details by puuid for v2 of the endpoint. - - This is the same as - :py:meth:`get_mmr_details_by_puuid(version="v2", region=region, puuid=puuid, **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - """ - return get_mmr_details_by_puuid("v2", region, puuid, filter, **kwargs) - - -def get_mmr_details_by_name_v1( - region: str, name: str, tag: str, **kwargs -) -> MMRDetailsV1: - """Get MMR details by name for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_name(version="v1", region=region, name=name, tag=tag, - **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - MMRDetailsV1: MMR Details fetched from the API. - """ - return get_mmr_details_by_name("v1", region, name, tag, **kwargs) - - -def get_mmr_details_by_name_v2( - region: str, name: str, tag: str, filter: Optional[str] = None, **kwargs -) -> Union[MMRDetailsV2, SeasonDataV2]: - """Get MMR details by name for v2 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_name(version="v2", region=region, name=name, tag=tag, - **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - """ - return get_mmr_details_by_name("v2", region, name, tag, filter, **kwargs) - - -def get_mmr_details_by_name( - version: str, - region: str, - name: str, - tag: str, - filter: Optional[str] = None, - **kwargs, -) -> Union[MMRDetailsV1, MMRDetailsV2, SeasonDataV2]: - """Get MMR details by name for a specific endpoint version. - - Args: - version: The version of the endpoint to use. - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV1` object. - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the version is not one of the supported versions. - """ - response = fetch_endpoint( - EndpointsConfig.MMR_DETAILS_BY_NAME, - region=region, - name=name, - tag=tag, - version=version, - query_args={"filter": str(filter).lower()} if filter is not None else None, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV1) - ).data - elif version == "v2": - try: - if filter is None or filter == "": - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV2) - ).data - else: - return msgspec.json.decode( - response.content, type=response_type(SeasonDataV2) - ).data - except Exception: - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV2) - ).data - else: - raise ValueError("Invalid version") - - -def get_mmr_details_by_puuid( - version: str, region: str, puuid: str, filter: Optional[str] = None, **kwargs -) -> Union[MMRDetailsV1, MMRDetailsV2, SeasonDataV2]: - """Get MMR details by puuid for a specific endpoint version. - - Args: - version: The version of the endpoint to use. - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV1` object. - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the version is not one of the supported versions. - """ - response = fetch_endpoint( - EndpointsConfig.MMR_DETAILS_BY_PUUID, - region=region, - puuid=puuid, - version=version, - query_args={"filter": str(filter).lower()} if filter is not None else None, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV1) - ).data - elif version == "v2": - try: - if filter is None or filter == "": - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV2) - ).data - else: - return msgspec.json.decode( - response.content, type=response_type(SeasonDataV2) - ).data - except Exception: - return msgspec.json.decode( - response.content, type=response_type(MMRDetailsV2) - ).data - else: - raise ValueError("Invalid version") - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_mmr_details_by_name_v1_async( - region: str, - name: str, - tag: str, - filter: Optional[str] = None, - **kwargs, - ) -> MMRDetailsV1: - """Get MMR details by name for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_name_async(version="v1", region=region, name=name, tag=tag, - filter=filter, **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - MMRDetailsV1: An :class:`.MMRDetailsV1` object. - """ - return await get_mmr_details_by_name_async( - "v1", region, name, tag, filter, **kwargs - ) - - async def get_mmr_details_by_name_v2_async( - region: str, - name: str, - tag: str, - filter: Optional[str] = None, - **kwargs, - ) -> Union[MMRDetailsV2, SeasonDataV2]: - """Get MMR details by name for v2 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_name_async(version="v2", region=region, name=name, tag=tag, - filter=filter, **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - """ - return await get_mmr_details_by_name_async( - "v2", region, name, tag, filter, **kwargs - ) - - async def get_mmr_details_by_name_async( - version: str, - region: str, - name: str, - tag: str, - filter: Optional[str] = None, - **kwargs, - ) -> Union[MMRDetailsV1, MMRDetailsV2, SeasonDataV2]: - """Get MMR details by name for a specific endpoint version. - - Args: - version: The version of the endpoint to use. - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name to get the MMR details for. - tag: The tag to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV1` object. - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the version is not one of the supported versions. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.MMR_DETAILS_BY_NAME, - region=region, - name=name, - tag=tag, - version=version, - query_args={"filter": str(filter).lower()} if filter is not None else None, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode(content, type=response_type(MMRDetailsV1)).data - elif version == "v2": - try: - if filter is None or filter == "": - return msgspec.json.decode( - content, type=response_type(MMRDetailsV2) - ).data - else: - return msgspec.json.decode( - content, type=response_type(SeasonDataV2) - ).data - except Exception: - return msgspec.json.decode( - content, type=response_type(MMRDetailsV2) - ).data - else: - raise ValueError("Invalid version") - - async def get_mmr_details_by_puuid_v1_async( - region: str, - puuid: str, - filter: Optional[str] = None, - **kwargs, - ) -> MMRDetailsV1: - """Get MMR details by puuid for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_puuid_async(version="v1", region=region, puuid=puuid, filter=filter, - **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - MMRDetailsV1: An :class:`.MMRDetailsV1` object. - """ - return await get_mmr_details_by_puuid_async( - "v1", region, puuid, filter, **kwargs - ) - - async def get_mmr_details_by_puuid_v2_async( - region: str, - puuid: str, - filter: Optional[str] = None, - **kwargs, - ) -> Union[MMRDetailsV2, SeasonDataV2]: - """Get MMR details by puuid for v2 of the endpoint. - - This is the same as :py:meth:`get_mmr_details_by_puuid_async(version="v2", region=region, puuid=puuid, filter=filter, - **kwargs) ` - - Args: - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - """ - return await get_mmr_details_by_puuid_async( - "v2", region, puuid, filter, **kwargs - ) - - async def get_mmr_details_by_puuid_async( - version: str, region: str, puuid: str, filter: Optional[str] = None, **kwargs - ) -> Union[MMRDetailsV1, MMRDetailsV2, SeasonDataV2]: - """Get MMR details by puuid for a specific endpoint version. - - Args: - version: The version of the endpoint to use. - region: The region to get the MMR details from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid to get the MMR details for. - filter: The filter to use for filtering data by season. - **kwargs: Any additional keyword arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRDetailsV1` object. - - An :class:`.MMRDetailsV2` object. - - An :class:`.SeasonDataV2` object. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the version is not one of the supported versions. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.MMR_DETAILS_BY_PUUID, - region=region, - puuid=puuid, - version=version, - query_args={"filter": str(filter).lower()} if filter is not None else None, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode(content, type=response_type(MMRDetailsV1)).data - elif version == "v2": - try: - if filter is None or filter == "": - return msgspec.json.decode( - content, type=response_type(MMRDetailsV2) - ).data - else: - return msgspec.json.decode( - content, type=response_type(SeasonDataV2) - ).data - except Exception: - return msgspec.json.decode( - content, type=response_type(MMRDetailsV2) - ).data - else: - raise ValueError("Invalid version") - -except ImportError: - pass diff --git a/valo_api/endpoints/mmr_history.py b/valo_api/endpoints/mmr_history.py deleted file mode 100644 index f070f406..00000000 --- a/valo_api/endpoints/mmr_history.py +++ /dev/null @@ -1,258 +0,0 @@ -from typing import List - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.mmr_history import MMRHistoryPointV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_mmr_history_by_name_v1( - region: str, name: str, tag: str, **kwargs -) -> List[MMRHistoryPointV1]: - """Get MMR history by name for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_history_by_name(version="v1", region=region, name=name, tag=tag, - **kwargs) ` - - Args: - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player to get the MMR history for. - tag: The tag of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - """ - return get_mmr_history_by_name("v1", region, name, tag, **kwargs) - - -def get_mmr_history_by_puuid_v1( - region: str, puuid: str, **kwargs -) -> List[MMRHistoryPointV1]: - """Get MMR history by puuid for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_history_by_puuid(version="v1", region=region, puuid=puuid, **kwargs) - ` - - Args: - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - """ - return get_mmr_history_by_puuid("v1", region, puuid, **kwargs) - - -def get_mmr_history_by_name( - version: str, region: str, name: str, tag: str, **kwargs -) -> List[MMRHistoryPointV1]: - """Get MMR history by name for a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player to get the MMR history for. - tag: The tag of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.MMR_HISTORY_BY_NAME, - region=region, - name=name, - tag=tag, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[MMRHistoryPointV1]) - ).data - - -def get_mmr_history_by_puuid( - version: str, region: str, puuid: str, **kwargs -) -> List[MMRHistoryPointV1]: - """Get MMR history by puuid for a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.MMR_HISTORY_BY_PUUID, - region=region, - puuid=puuid, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[MMRHistoryPointV1]) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_mmr_history_by_name_v1_async( - region: str, name: str, tag: str, **kwargs - ) -> List[MMRHistoryPointV1]: - """Get MMR history by name for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_history_by_name_async(version="v1", region=region, name=name, tag=tag, - **kwargs) ` - - Args: - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player to get the MMR history for. - tag: The tag of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - """ - return await get_mmr_history_by_name_async("v1", region, name, tag, **kwargs) - - async def get_mmr_history_by_puuid_v1_async( - region: str, puuid: str, **kwargs - ) -> List[MMRHistoryPointV1]: - """Get MMR history by puuid for v1 of the endpoint. - - This is the same as :py:meth:`get_mmr_history_by_puuid_async(version="v1", region=region, puuid=puuid, **kwargs) - ` - - Args: - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - """ - return await get_mmr_history_by_puuid_async("v1", region, puuid, **kwargs) - - async def get_mmr_history_by_name_async( - version: str, region: str, name: str, tag: str, **kwargs - ) -> List[MMRHistoryPointV1]: - """Get MMR history by name for a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - name: The name of the player to get the MMR history for. - tag: The tag of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.MMR_HISTORY_BY_NAME, - region=region, - name=name, - tag=tag, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[MMRHistoryPointV1]) - ).data - - async def get_mmr_history_by_puuid_async( - version: str, region: str, puuid: str, **kwargs - ) -> List[MMRHistoryPointV1]: - """Get MMR history by puuid for a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - region: The region to get the MMR history from. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - puuid: The puuid of the player to get the MMR history for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - A list of :class:`.MMRHistoryPointV1` objects. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.MMR_HISTORY_BY_PUUID, - region=region, - puuid=puuid, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[MMRHistoryPointV1]) - ).data - -except ImportError: - pass diff --git a/valo_api/endpoints/raw.py b/valo_api/endpoints/raw.py deleted file mode 100644 index 182a986c..00000000 --- a/valo_api/endpoints/raw.py +++ /dev/null @@ -1,213 +0,0 @@ -from typing import Optional, Union - -import urllib -from enum import Enum - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.competitive_updates_raw import CompetitiveUpdatesRawV1 -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.match_details_raw import MatchDetailsRawV1 -from valo_api.responses.match_history_raw import MatchHistoryRawV1 -from valo_api.responses.mmr_raw import MMRRawV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint - - -class EndpointType(Enum): - COMPETITIVE_UPDATES = "competitiveupdates" - MMR = "mmr" - MATCH_DETAILS = "matchdetails" - MATCH_HISTORY = "matchhistory" - - -def get_raw_data_v1( - type: EndpointType, - value: Optional[str] = None, - region: Optional[str] = None, - queries: Optional[dict] = None, - **kwargs, -) -> Union[MMRRawV1, MatchHistoryRawV1, CompetitiveUpdatesRawV1, MatchDetailsRawV1]: - """Get the raw data for a specific ingame endpoint for version 1. - - This is the same as :py:meth:`get_raw_data(version="v1", type=type, value=value, region=region, queries=queries, - **kwargs) ` - - Args: - type: The type of endpoint to get the raw data for. - value: The value of the endpoint to get the raw data for. - region: The region to get the raw data for. - queries: Any additional queries to pass to the endpoint. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRRawV1` object if the endpoint is of type :class:`.EndpointType.MMR`. - - An :class:`.MatchHistoryRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_HISTORY`. - - An :class:`.CompetitiveUpdatesRawV1` object if the endpoint is of type :class:`.EndpointType.COMPETITIVE_UPDATES`. - - An :class:`.MatchDetailsRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_DETAILS`. - """ - return get_raw_data("v1", type, value, region, queries, **kwargs) - - -def get_raw_data( - version: str, - type: EndpointType, - value: Optional[str] = None, - region: Optional[str] = None, - queries: Optional[dict] = None, - **kwargs, -) -> Union[MMRRawV1, MatchHistoryRawV1, CompetitiveUpdatesRawV1, MatchDetailsRawV1]: - """Get the raw data for a specific ingame endpoint for a specific version. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - type: The type of endpoint to get the raw data for. - value: The value of the endpoint to get the raw data for. - region: The region to get the raw data for. - queries: Any additional queries to pass to the endpoint. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRRawV1` object if the endpoint is of type :class:`.EndpointType.MMR`. - - An :class:`.MatchHistoryRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_HISTORY`. - - An :class:`.CompetitiveUpdatesRawV1` object if the endpoint is of type :class:`.EndpointType.COMPETITIVE_UPDATES`. - - An :class:`.MatchDetailsRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_DETAILS`. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the endpoint type is not one of the valid types. - """ - query_args = { - "type": type.value, - } - if value is not None: - query_args["value"] = value - if region is not None: - query_args["region"] = region - if queries is not None and len(queries) > 0: - query_args["queries"] = f"?{urllib.parse.urlencode(queries)}" - - response = fetch_endpoint( - EndpointsConfig.RAW, - version=version, - method="POST", - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if type == EndpointType.MATCH_DETAILS: - return msgspec.json.decode(response.content, type=MatchDetailsRawV1) - elif type == EndpointType.COMPETITIVE_UPDATES: - return msgspec.json.decode(response.content, type=CompetitiveUpdatesRawV1) - elif type == EndpointType.MMR: - return msgspec.json.decode(response.content, type=MMRRawV1) - elif type == EndpointType.MATCH_HISTORY: - return msgspec.json.decode(response.content, type=MatchHistoryRawV1) - - raise ValueError(f"Unknown endpoint type: {type}") - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_raw_data_v1_async( - type: EndpointType, - value: Optional[str] = None, - region: Optional[str] = None, - queries: Optional[dict] = None, - **kwargs, - ) -> Union[MMRRawV1, MatchHistoryRawV1, CompetitiveUpdatesRawV1, MatchDetailsRawV1]: - """Get the raw data for a specific ingame endpoint for version 1. - - This is the same as :py:meth:`get_raw_data_async(version="v1", type=type, value=value, region=region, queries=queries, - **kwargs) ` - - Args: - type: The type of endpoint to get the raw data for. - value: The value of the endpoint to get the raw data for. - region: The region to get the raw data for. - queries: Any additional queries to pass to the endpoint. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRRawV1` object if the endpoint is of type :class:`.EndpointType.MMR`. - - An :class:`.MatchHistoryRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_HISTORY`. - - An :class:`.CompetitiveUpdatesRawV1` object if the endpoint is of type :class:`.EndpointType.COMPETITIVE_UPDATES`. - - An :class:`.MatchDetailsRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_DETAILS`. - """ - return await get_raw_data_async("v1", type, value, region, queries, **kwargs) - - async def get_raw_data_async( - version: str, - type: EndpointType, - value: Optional[str] = None, - region: Optional[str] = None, - queries: Optional[dict] = None, - **kwargs, - ) -> Union[MMRRawV1, MatchHistoryRawV1, CompetitiveUpdatesRawV1, MatchDetailsRawV1]: - """Get the raw data for a specific ingame endpoint for a specific version. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - type: The type of endpoint to get the raw data for. - value: The value of the endpoint to get the raw data for. - region: The region to get the raw data for. - queries: Any additional queries to pass to the endpoint. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - An :class:`.MMRRawV1` object if the endpoint is of type :class:`.EndpointType.MMR`. - - An :class:`.MatchHistoryRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_HISTORY`. - - An :class:`.CompetitiveUpdatesRawV1` object if the endpoint is of type :class:`.EndpointType.COMPETITIVE_UPDATES`. - - An :class:`.MatchDetailsRawV1` object if the endpoint is of type :class:`.EndpointType.MATCH_DETAILS`. - - Raises: - ValoAPIException: If the request failed. - ValueError: If the endpoint type is not one of the valid types. - """ - query_args = { - "type": type.value, - } - if value is not None: - query_args["value"] = value - if region is not None: - query_args["region"] = region - if queries is not None and len(queries) > 0: - query_args["queries"] = f"?{urllib.parse.urlencode(queries)}" - - response, content = await fetch_endpoint_async( - EndpointsConfig.RAW, - version=version, - method="POST", - query_args=query_args, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if type == EndpointType.MATCH_DETAILS: - return msgspec.json.decode(content, type=MatchDetailsRawV1) - elif type == EndpointType.COMPETITIVE_UPDATES: - return msgspec.json.decode(content, type=CompetitiveUpdatesRawV1) - elif type == EndpointType.MMR: - return msgspec.json.decode(content, type=MMRRawV1) - elif type == EndpointType.MATCH_HISTORY: - return msgspec.json.decode(content, type=MatchHistoryRawV1) - - raise ValueError(f"Unknown endpoint type: {type}") - -except ImportError: - pass diff --git a/valo_api/endpoints/status.py b/valo_api/endpoints/status.py deleted file mode 100644 index 9f2921c1..00000000 --- a/valo_api/endpoints/status.py +++ /dev/null @@ -1,114 +0,0 @@ -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.status import StatusV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_status_v1(region: str, **kwargs) -> StatusV1: - """Get the status for a specific region using version 1 of the endpoint. - - This is the same as - :py:meth:`get_status(version="v1", region=region, **kwargs) ` - - Args: - region: The region to get the status for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StatusV1: Status fetched from the API. - """ - return get_status("v1", region, **kwargs) - - -def get_status(version: str, region: str, **kwargs) -> StatusV1: - """Get the status for a specific region. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - region: The region to get the status for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StatusV1: Status fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.STATUS, - version=version, - region=region, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(response.content, type=response_type(StatusV1)).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_status_v1_async(region: str, **kwargs) -> StatusV1: - """Get the status for a specific region using version 1 of the endpoint. - - This is the same as - :py:meth:`get_status_async(version="v1", region=region, **kwargs) ` - - Args: - region: The region to get the status for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StatusV1: Status fetched from the API. - """ - return await get_status_async("v1", region, **kwargs) - - async def get_status_async(version: str, region: str, **kwargs) -> StatusV1: - """Get the status for a specific region. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - region: The region to get the status for. - One of the following: - eu (Europe), na (North America), ap (Asia Pacific), kr (Korea), latam (Latin America), br (Brazil) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StatusV1: Status fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.STATUS, - version=version, - region=region, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(content, type=response_type(StatusV1)).data - -except ImportError: - pass diff --git a/valo_api/endpoints/store_featured.py b/valo_api/endpoints/store_featured.py deleted file mode 100644 index 3e65ae5f..00000000 --- a/valo_api/endpoints/store_featured.py +++ /dev/null @@ -1,151 +0,0 @@ -from typing import List, Union - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.store_featured import BundleV2, StoreFeaturedV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_store_featured_v1(**kwargs) -> StoreFeaturedV1: - """Get the store featured using version 1 of the endpoint. - - This is the same as - :py:meth:`get_store_featured(version="v1", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreFeaturedV1: Store featured fetched from the API. - """ - return get_store_featured("v1", **kwargs) - - -def get_store_featured_v2(**kwargs) -> List[BundleV2]: - """Get the store featured using version 2 of the endpoint. - - This is the same as - :py:meth:`get_store_featured(version="v2", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - List[BundleV2]: Bundles featured fetched from the API. - """ - return get_store_featured("v2", **kwargs) - - -def get_store_featured( - version: str, **kwargs -) -> Union[StoreFeaturedV1, List[BundleV2]]: - """Get the store featured using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - v2 (Version 2) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreFeaturedV1: Store featured fetched from the API. - List[BundleV2]: Bundles featured fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.STORE_FEATURED, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode( - response.content, type=response_type(StoreFeaturedV1) - ).data - else: - return msgspec.json.decode( - response.content, type=response_type(List[BundleV2]) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_store_featured_v1_async(**kwargs) -> StoreFeaturedV1: - """Get the store featured using version 1 of the endpoint. - - This is the same as - :py:meth:`get_store_featured_async(version="v1", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreFeaturedV1: Store featured fetched from the API. - """ - return await get_store_featured_async("v1", **kwargs) - - async def get_store_featured_v2_async(**kwargs) -> List[BundleV2]: - """Get the store featured using version 2 of the endpoint. - - This is the same as - :py:meth:`get_store_featured_async(version="v2", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - List[BundleV2]: Bundles featured fetched from the API. - """ - return await get_store_featured_async("v2", **kwargs) - - async def get_store_featured_async( - version: str, **kwargs - ) -> Union[StoreFeaturedV1, List[BundleV2]]: - """Get the store featured using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - v2 (Version 2) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreFeaturedV1: Store featured fetched from the API. - List[BundleV2]: Bundles featured fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.STORE_FEATURED, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode( - content, type=response_type(StoreFeaturedV1) - ).data - else: - return msgspec.json.decode(content, type=response_type(List[BundleV2])).data - -except ImportError: - pass diff --git a/valo_api/endpoints/store_offers.py b/valo_api/endpoints/store_offers.py deleted file mode 100644 index 185d4101..00000000 --- a/valo_api/endpoints/store_offers.py +++ /dev/null @@ -1,145 +0,0 @@ -from typing import Union - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.store_offers import StoreOffersV1, StoreOffersV2 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_store_offers_v1(**kwargs) -> StoreOffersV1: - """Get the store offers using version 1 of the endpoint. - - This is the same as - :py:meth:`get_store_offers(version="v1", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreOffersV1: Store Offers fetched from the API. - """ - return get_store_offers("v1", **kwargs) - - -def get_store_offers_v2(**kwargs) -> StoreOffersV2: - """Get the store offers using version 2 of the endpoint. - - This is the same as - :py:meth:`get_store_offers(version="v2", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreOffersV2: Store Offers fetched from the API. - """ - return get_store_offers("v2", **kwargs) - - -def get_store_offers(version: str, **kwargs) -> Union[StoreOffersV1, StoreOffersV2]: - """Get the store offers using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - StoreOffersV1: Store Offers Version 1 fetched from the API. - - StoreOffersV2: Store Offers Version 2 fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.STORE_OFFERS, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode( - response.content, type=response_type(StoreOffersV1) - ).data - else: - return msgspec.json.decode( - response.content, type=response_type(StoreOffersV2) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_store_offers_v1_async(**kwargs) -> StoreOffersV1: - """Get the store offers using version 1 of the endpoint. - - This is the same as - :py:meth:`get_store_offers(version="v1", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreOffersV1: Store Offers fetched from the API. - """ - return await get_store_offers_async("v1", **kwargs) - - async def get_store_offers_v2_async(**kwargs) -> StoreOffersV2: - """Get the store offers using version 1 of the endpoint. - - This is the same as - :py:meth:`get_store_offers(version="v2", **kwargs) ` - - Args: - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - StoreOffersV2: Store Offers fetched from the API. - """ - return await get_store_offers_async("v2", **kwargs) - - async def get_store_offers_async( - version: str, **kwargs - ) -> Union[StoreOffersV1, StoreOffersV2]: - """Get the store offers using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1), v2 (Version 2) - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - - StoreOffersV1: Store Offers fetched from the API. - - StoreOffersV2: Store Offers fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.STORE_OFFERS, - version=version, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - if version == "v1": - return msgspec.json.decode(content, type=response_type(StoreOffersV1)).data - else: - return msgspec.json.decode(content, type=response_type(StoreOffersV2)).data - -except ImportError: - pass diff --git a/valo_api/endpoints/version_info.py b/valo_api/endpoints/version_info.py deleted file mode 100644 index 3e5aadd7..00000000 --- a/valo_api/endpoints/version_info.py +++ /dev/null @@ -1,108 +0,0 @@ -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.version_info import VersionInfoV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_version_info_v1(region: str, **kwargs) -> VersionInfoV1: - """Get the version info using version 1 of the endpoint. - - This is the same as - :py:meth:`get_version_info(version="v1", region=region, **kwargs) ` - - Args: - region: The region to get the version info for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - VersionInfoV1: Version info fetched from the API. - """ - return get_version_info("v1", region, **kwargs) - - -def get_version_info(version: str, region: str, **kwargs) -> VersionInfoV1: - """Get the version info using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - region: The region to get the version info for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - VersionInfoV1: Version info fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.VERSION_INFO, - version=version, - region=region, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(response.content, type=response_type(VersionInfoV1)).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_version_info_v1_async(region: str, **kwargs) -> VersionInfoV1: - """Get the version info using version 1 of the endpoint. - - This is the same as - :py:meth:`get_version_info_async(version="v1", region=region, **kwargs) ` - - Args: - region: The region to get the version info for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - VersionInfoV1: Version info fetched from the API. - """ - return await get_version_info_async("v1", region, **kwargs) - - async def get_version_info_async( - version: str, region: str, **kwargs - ) -> VersionInfoV1: - """Get the version info using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - region: The region to get the version info for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - VersionInfoV1: Version info fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.VERSION_INFO, - version=version, - region=region, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode(content, type=response_type(VersionInfoV1)).data - -except ImportError: - pass diff --git a/valo_api/endpoints/website.py b/valo_api/endpoints/website.py deleted file mode 100644 index bc6e70c8..00000000 --- a/valo_api/endpoints/website.py +++ /dev/null @@ -1,114 +0,0 @@ -from typing import List - -import msgspec.json - -from valo_api.endpoints_config import EndpointsConfig -from valo_api.exceptions.valo_api_exception import ValoAPIException -from valo_api.responses.error_response import ErrorResponse -from valo_api.responses.website import WebsiteBannerV1 -from valo_api.utils.fetch_endpoint import fetch_endpoint, response_type - - -def get_website_v1(countrycode: str, **kwargs) -> List[WebsiteBannerV1]: - """Get the website banners using version 1 of the endpoint. - - This is the same as - :py:meth:`get_website(version="v1", countrycode=countrycode, **kwargs) ` - - Args: - countrycode: The country code to get the website banners for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - WebsiteBannerV1: Website banners fetched from the API. - """ - return get_website("v1", countrycode, **kwargs) - - -def get_website(version: str, countrycode: str, **kwargs) -> List[WebsiteBannerV1]: - """Get the website banners using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - countrycode: The country code to get the website banners for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - WebsiteBannerV1: Website banners fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response = fetch_endpoint( - EndpointsConfig.WEBSITE, - version=version, - countrycode=countrycode, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(response.content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - response.content, type=response_type(List[WebsiteBannerV1]) - ).data - - -try: - from valo_api.utils.fetch_endpoint import fetch_endpoint_async - - async def get_website_v1_async(countrycode: str, **kwargs) -> List[WebsiteBannerV1]: - """Get the website banners using version 1 of the endpoint. - - This is the same as - :py:meth:`get_website_async(version="v1", countrycode=countrycode, **kwargs) ` - - Args: - countrycode: The country code to get the website banners for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - WebsiteBannerV1: Website banners fetched from the API. - """ - return await get_website_async("v1", countrycode, **kwargs) - - async def get_website_async( - version: str, countrycode: str, **kwargs - ) -> List[WebsiteBannerV1]: - """Get the website banners using a specific version of the endpoint. - - Args: - version: The version of the endpoint to use. - One of the following: - v1 (Version 1) - countrycode: The country code to get the website banners for. - **kwargs: Any additional arguments to pass to the endpoint. - - Returns: - WebsiteBannerV1: Website banners fetched from the API. - - Raises: - ValoAPIException: If the request failed. - """ - response, content = await fetch_endpoint_async( - EndpointsConfig.WEBSITE, - version=version, - countrycode=countrycode, - **kwargs, - ) - - if response.ok is False: - error = msgspec.json.decode(content, type=ErrorResponse) - error.headers = dict(response.headers) - raise ValoAPIException(error) - - return msgspec.json.decode( - content, type=response_type(List[WebsiteBannerV1]) - ).data - -except ImportError: - pass diff --git a/valo_api/endpoints_config.py b/valo_api/endpoints_config.py index 9a10eb06..2533fdb5 100644 --- a/valo_api/endpoints_config.py +++ b/valo_api/endpoints_config.py @@ -1,30 +1,311 @@ -class EndpointsConfig: - RAW = "/valorant/{version}/raw" - CONTENT = "/valorant/{version}/content" - STORE_FEATURED = "/valorant/{version}/store-featured" - STORE_OFFERS = "/valorant/{version}/store-offers" - STATUS = "/valorant/{version}/status/{region}" - VERSION_INFO = "/valorant/{version}/version/{region}" - WEBSITE = "/valorant/{version}/website/{countrycode}" - LEADERBOARD = "/valorant/{version}/leaderboard/{region}" - ACCOUNT_BY_NAME = "/valorant/{version}/account/{name}/{tag}" - ACCOUNT_BY_PUUID = "/valorant/{version}/by-puuid/account/{puuid}" - MATCH_DETAILS = "/valorant/{version}/match/{match_id}" +from typing import List, Optional, Union - MMR_DETAILS_BY_PUUID = "/valorant/{version}/by-puuid/mmr/{region}/{puuid}" - MMR_DETAILS_BY_NAME = "/valorant/{version}/mmr/{region}/{name}/{tag}" +from enum import Enum - MMR_HISTORY_BY_PUUID = "/valorant/{version}/by-puuid/mmr-history/{region}/{puuid}" - MMR_HISTORY_BY_NAME = "/valorant/{version}/mmr-history/{region}/{name}/{tag}" +from PIL import Image - MATCH_HISTORY_BY_PUUID = "/valorant/{version}/by-puuid/matches/{region}/{puuid}" - MATCH_HISTORY_BY_NAME = "/valorant/{version}/matches/{region}/{name}/{tag}" +from valo_api.endpoint import Endpoint +from valo_api.responses.account_details import AccountDetailsV1 +from valo_api.responses.competitive_updates_raw import CompetitiveUpdatesRawV1 +from valo_api.responses.content import ContentV1 +from valo_api.responses.leaderboard import LeaderboardPlayerV1, LeaderboardV2 +from valo_api.responses.lifetime_match import LifetimeMatchV1 +from valo_api.responses.match_details_raw import MatchDetailsRawV1 +from valo_api.responses.match_history import MatchHistoryPointV3 +from valo_api.responses.match_history_raw import MatchHistoryRawV1 +from valo_api.responses.mmr_details import MMRDetailsV1, MMRDetailsV2, SeasonDataV2 +from valo_api.responses.mmr_history import MMRHistoryPointV1 +from valo_api.responses.mmr_raw import MMRRawV1 +from valo_api.responses.status import StatusV1 +from valo_api.responses.store_featured import BundleV2, StoreFeaturedV1 +from valo_api.responses.store_offers import StoreOffersV1, StoreOffersV2 +from valo_api.responses.version_info import VersionInfoV1 +from valo_api.responses.website import WebsiteBannerV1 - LIFETIME_MATCHES_BY_PUUID = ( - "/valorant/{version}/by-puuid/lifetime/matches/{region}/{puuid}" + +class EndpointsConfig(Enum): + RAW_MATCH_DETAILS = Endpoint( + path="/valorant/{version}/raw", + method="POST", + f_name="get_raw_match_details_data", + return_type=MatchDetailsRawV1, + data_response=False, + kwargs={ + "version": str, + "value": Optional[str], + "region": Optional[str], + "queries": Optional[dict], + }, + query_args={ + "type": "matchdetails", + "value": "{value}", + "region": "{region}", + "queries": "{queries}", + }, ) - LIFETIME_MATCHES_BY_NAME = ( - "/valorant/{version}/lifetime/matches/{region}/{name}/{tag}" + RAW_MATCH_HISTORY = Endpoint( + path="/valorant/{version}/raw", + method="POST", + f_name="get_raw_match_history_data", + return_type=MatchHistoryRawV1, + data_response=False, + kwargs={ + "version": str, + "value": Optional[str], + "region": Optional[str], + "queries": Optional[dict], + }, + query_args={ + "type": "matchhistory", + "value": "{value}", + "region": "{region}", + "queries": "{queries}", + }, + ) + RAW_MMR = Endpoint( + path="/valorant/{version}/raw", + method="POST", + f_name="get_raw_mmr_data", + return_type=MMRRawV1, + data_response=False, + kwargs={ + "version": str, + "value": Optional[str], + "region": Optional[str], + "queries": Optional[dict], + }, + query_args={ + "type": "mmr", + "value": "{value}", + "region": "{region}", + "queries": "{queries}", + }, + ) + RAW_COMPETITIVE_UPDATES = Endpoint( + path="/valorant/{version}/raw", + method="POST", + f_name="get_raw_competitive_updates_data", + return_type=CompetitiveUpdatesRawV1, + data_response=False, + kwargs={ + "version": str, + "value": Optional[str], + "region": Optional[str], + "queries": Optional[dict], + }, + query_args={ + "type": "competitiveupdates", + "value": "{value}", + "region": "{region}", + "queries": "{queries}", + }, + ) + CONTENT = Endpoint( + path="/valorant/{version}/content", + f_name="get_content", + return_type=ContentV1, + data_response=False, + kwargs={ + "version": str, + "locale": Optional[str], + }, + query_args={ + "locale": "{locale}", + }, + ) + STORE_FEATURED = Endpoint( + path="/valorant/{version}/store-featured", + f_name="get_store_featured", + versions=["v1", "v2"], + return_type=Union[StoreFeaturedV1, List[BundleV2]], + kwargs={"version": str}, + ) + STORE_OFFERS = Endpoint( + path="/valorant/{version}/store-offers", + f_name="get_store_offers", + versions=["v2"], + return_type=StoreOffersV2, + kwargs={"version": str}, + ) + STATUS = Endpoint( + path="/valorant/{version}/status/{region}", + f_name="get_status", + return_type=StatusV1, + kwargs={"version": str, "region": str}, + ) + VERSION_INFO = Endpoint( + path="/valorant/{version}/version/{region}", + f_name="get_version_info", + return_type=VersionInfoV1, + kwargs={"version": str, "region": str}, + ) + WEBSITE = Endpoint( + path="/valorant/{version}/website/{countrycode}", + f_name="get_website", + return_type=List[WebsiteBannerV1], + kwargs={"version": str, "countrycode": str}, + ) + LEADERBOARD = Endpoint( + path="/valorant/{version}/leaderboard/{region}", + f_name="get_leaderboard", + versions=["v1", "v2"], + return_type=Union[LeaderboardV2, List[LeaderboardPlayerV1]], + data_response=False, + kwargs={ + "version": str, + "region": str, + "puuid": Optional[str], + "name": Optional[str], + "tag": Optional[str], + "season_id": Optional[str], + "start": Optional[int], + }, + query_args={ + "puuid": "{puuid}", + "name": "{name}", + "tag": "{tag}", + "season_id": "{season_id}", + "start": "{start}", + }, + ) + ACCOUNT_BY_NAME = Endpoint( + path="/valorant/{version}/account/{name}/{tag}", + f_name="get_account_details_by_name", + return_type=AccountDetailsV1, + kwargs={"version": str, "name": str, "tag": str, "force_update": bool}, + query_args={"force": "{force_update}"}, + ) + ACCOUNT_BY_PUUID = Endpoint( + path="/valorant/{version}/by-puuid/account/{puuid}", + f_name="get_account_details_by_puuid", + return_type=AccountDetailsV1, + kwargs={"version": str, "puuid": str, "force_update": bool}, + query_args={"force": "{force_update}"}, + ) + MATCH_DETAILS = Endpoint( + path="/valorant/{version}/match/{match_id}", + f_name="get_match_details", + versions=["v2"], + return_type=MatchHistoryPointV3, + kwargs={"version": str, "match_id": str}, + ) + MMR_DETAILS_BY_PUUID = Endpoint( + path="/valorant/{version}/by-puuid/mmr/{region}/{puuid}", + f_name="get_mmr_details_by_puuid", + versions=["v1", "v2"], + return_type=MMRDetailsV2, + kwargs={"version": str, "region": str, "puuid": str, "filter": str}, + query_args={"filter": "{filter}"}, + ) + MMR_DETAILS_BY_NAME = Endpoint( + path="/valorant/{version}/mmr/{region}/{name}/{tag}", + f_name="get_mmr_details_by_name", + versions=["v2"], + return_type=MMRDetailsV2, + kwargs={"version": str, "region": str, "name": str, "tag": str, "filter": str}, + query_args={"filter": "{filter}"}, + ) + MMR_HISTORY_BY_PUUID = Endpoint( + path="/valorant/{version}/by-puuid/mmr-history/{region}/{puuid}", + f_name="get_mmr_history_by_puuid", + return_type=List[MMRHistoryPointV1], + kwargs={"version": str, "region": str, "puuid": str}, + ) + MMR_HISTORY_BY_NAME = Endpoint( + path="/valorant/{version}/mmr-history/{region}/{name}/{tag}", + f_name="get_mmr_history_by_name", + return_type=List[MMRHistoryPointV1], + kwargs={"version": str, "region": str, "name": str, "tag": str}, + ) + MATCH_HISTORY_BY_PUUID = Endpoint( + path="/valorant/{version}/by-puuid/matches/{region}/{puuid}", + f_name="get_match_history_by_puuid", + versions=["v3"], + return_type=List[MatchHistoryPointV3], + kwargs={ + "version": str, + "region": str, + "puuid": str, + "size": Optional[int], + "map": Optional[str], + "game_mode": Optional[str], + }, + query_args={ + "size": "{size}", + "map": "{map}", + "filter": "{game_mode}", + }, + ) + MATCH_HISTORY_BY_NAME = Endpoint( + path="/valorant/{version}/matches/{region}/{name}/{tag}", + f_name="get_match_history_by_name", + versions=["v3"], + return_type=List[MatchHistoryPointV3], + kwargs={ + "version": str, + "region": str, + "name": str, + "tag": str, + "size": Optional[int], + "map": Optional[str], + "game_mode": Optional[str], + }, + query_args={ + "size": "{size}", + "map": "{map}", + "filter": "{game_mode}", + }, + ) + LIFETIME_MATCHES_BY_PUUID = Endpoint( + path="/valorant/{version}/by-puuid/lifetime/matches/{region}/{puuid}", + f_name="get_lifetime_matches_by_puuid", + return_type=List[LifetimeMatchV1], + kwargs={ + "version": str, + "region": str, + "puuid": str, + "mode": Optional[str], + "map": Optional[str], + "page": Optional[int], + "size": Optional[int], + }, + query_args={ + "mode": "{mode}", + "map": "{map}", + "page": "{page}", + "size": "{size}", + }, + ) + LIFETIME_MATCHES_BY_NAME = Endpoint( + path="/valorant/{version}/lifetime/matches/{region}/{name}/{tag}", + f_name="get_lifetime_matches_by_name", + return_type=List[LifetimeMatchV1], + kwargs={ + "version": str, + "region": str, + "name": str, + "tag": str, + "mode": Optional[str], + "map": Optional[str], + "page": Optional[int], + "size": Optional[int], + }, + query_args={ + "mode": "{mode}", + "map": "{map}", + "page": "{page}", + "size": "{size}", + }, + ) + CROSSHAIR = Endpoint( + path="/valorant/{version}/crosshair/generate", + f_name="get_crosshair", + return_type=Image.Image, + kwargs={ + "version": str, + "crosshair_id": str, + }, + query_args={ + "id": "{crosshair_id}", + }, ) - - CROSSHAIR = "/valorant/{version}/crosshair/generate"