Skip to content

Commit

Permalink
refactor: use custom proxy type
Browse files Browse the repository at this point in the history
  • Loading branch information
pradishb committed Oct 2, 2024
1 parent 5d9168b commit 1280068
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 52 deletions.
16 changes: 8 additions & 8 deletions league_client/rso/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from urllib.parse import urlparse

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.constants import RIOT_CLIENT_AUTH_PARAMS
Expand All @@ -15,6 +14,7 @@
from league_client.exceptions import InvalidSessionError
from league_client.exceptions import RateLimitedError
from league_client.rso.utils import decode_token
from league_client.types import ProxyT


def process_redirect_url(redirect_url: str):
Expand Down Expand Up @@ -49,7 +49,7 @@ def process_access_token(access_token: str) -> tuple[str, str, int]:
return data["sub"], data["dat"]["r"], data["dat"]["u"]


def get_pas_token(access_token: str, proxy: Optional[ProxyTypes] = None):
def get_pas_token(access_token: str, proxy: Optional[ProxyT] = None):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {access_token}"
res = httpx.get(
Expand All @@ -62,7 +62,7 @@ def get_pas_token(access_token: str, proxy: Optional[ProxyTypes] = None):


def get_entitlements_token(
access_token: str, proxy: Optional[ProxyTypes] = None
access_token: str, proxy: Optional[ProxyT] = None
) -> str:
h = HEADERS.copy()
h["Authorization"] = f"Bearer {access_token}"
Expand All @@ -82,7 +82,7 @@ def get_login_queue_token(
entitlements_token: str,
region: str,
player_platform_url: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {access_token}"
Expand All @@ -106,7 +106,7 @@ def get_ledge_token(
puuid: str,
region: str,
player_platform_url: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {login_queue_token}"
Expand All @@ -130,7 +130,7 @@ def get_summoner_token(
puuid: str,
region: str,
ledge_url: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand All @@ -148,7 +148,7 @@ def login_using_ssid(
ssid: str,
clid: str,
auth_params: dict[str, str] = RIOT_CLIENT_AUTH_PARAMS,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
) -> tuple[str, str, str, str, str, str, str, str, str]:
with httpx.Client(verify=SSL_CONTEXT, proxy=proxy) as client:
if ssid:
Expand Down Expand Up @@ -275,7 +275,7 @@ def login_using_credentials(
password: str,
captcha_solver: Callable[[str, str], str],
params: dict[str, str] = RIOT_CLIENT_AUTH_PARAMS,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
) -> tuple[str, str, str, str, str, str, str, str, str]:
with httpx.Client(verify=SSL_CONTEXT, proxy=proxy) as client:
authorize(
Expand Down
22 changes: 11 additions & 11 deletions league_client/rso/craft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.rso.constants import LootNameTypes
Expand All @@ -16,6 +15,7 @@
from league_client.rso.loot import get_loot_data
from league_client.rso.loot import get_masterwork_chest_count
from league_client.rso.loot import get_mythic_essence_count
from league_client.types import ProxyT


def craft(
Expand All @@ -25,7 +25,7 @@ def craft(
recipe_name: str,
loot_names: list[LootNameTypes],
repeat: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
"""Craft or open a chest item"""
h = HEADERS.copy()
Expand Down Expand Up @@ -55,7 +55,7 @@ def craft_key_from_key_fragments(
ledge_url: str,
puuid: str,
repeat: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
return craft(
ledge_token,
Expand All @@ -73,7 +73,7 @@ def craft_generic_chests(
ledge_url: str,
puuid: str,
repeat: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
return craft(
ledge_token,
Expand All @@ -91,7 +91,7 @@ def craft_champion_mastery_chest(
ledge_url: str,
puuid: str,
repeat: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
return craft(
ledge_token,
Expand All @@ -109,7 +109,7 @@ def craft_keys_and_generic_chests(
ledge_url: str,
puuid: str,
retry_limit: int = 10,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
for _ in range(retry_limit):

Expand Down Expand Up @@ -141,7 +141,7 @@ def craft_keys_and_masterwork_chests(
ledge_url: str,
puuid: str,
retry_limit: int = 10,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
for _ in range(retry_limit):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
Expand Down Expand Up @@ -174,7 +174,7 @@ def craft_chest_by_loot_name(
loot_name: LootNameTypes,
requires_key: bool = False,
repeat: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
"""Craft or open an chest item by loot id"""
loot_names = [loot_name]
Expand All @@ -198,7 +198,7 @@ def craft_chest_loots(
loot_data: dict[str, Any],
requires_key: bool = True,
delay: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
key_count = 0
if requires_key:
Expand Down Expand Up @@ -228,7 +228,7 @@ def craft_champion_capsules(
ledge_url: str,
puuid: str,
delay: int = 1,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
champion_capsules = [
Expand All @@ -253,7 +253,7 @@ def craft_mythic_essence_into_skin_shard(
ledge_token: str,
ledge_url: str,
puuid: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
count: int = get_mythic_essence_count(loot_data)
Expand Down
9 changes: 4 additions & 5 deletions league_client/rso/disenchant.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from typing import Optional

from httpx._types import ProxyTypes

from league_client.rso.craft import craft
from league_client.rso.loot import get_loot_data
from league_client.types import ProxyT


def disenchant_champion_shards(
ledge_token: str,
ledge_url: str,
puuid: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
champion_shards = [
Expand All @@ -35,7 +34,7 @@ def disenchant_eternals(
ledge_token: str,
ledge_url: str,
puuid: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
eternals = [
Expand All @@ -59,7 +58,7 @@ def disenchant_ward_skins(
ledge_token: str,
ledge_url: str,
puuid: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
loot_data = get_loot_data(ledge_token, ledge_url, puuid, proxy)
ward_skins = [
Expand Down
4 changes: 2 additions & 2 deletions league_client/rso/honor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.types import ProxyT


def get_honor_data(
ledge_token: str,
ledge_url: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand Down
8 changes: 4 additions & 4 deletions league_client/rso/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.rso.constants import InventoryTypes
from league_client.types import ProxyT


def _inventory_data_from_url(
Expand All @@ -16,7 +16,7 @@ def _inventory_data_from_url(
account_id: int,
service_location: str,
inventory_types: List[InventoryTypes],
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand All @@ -43,7 +43,7 @@ def get_inventory_data(
service_location: str,
ledge_url: str,
inventory_types: List[InventoryTypes],
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
return _inventory_data_from_url(
f"{ledge_url}/lolinventoryservice-ledge/v1/inventories/simple",
Expand All @@ -67,7 +67,7 @@ def get_inventory_data_v2(
service_location: str,
ledge_url: str,
inventory_types: List[InventoryTypes],
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
return _inventory_data_from_url(
f"{ledge_url}/lolinventoryservice-ledge/v2/inventoriesWithLoyalty",
Expand Down
4 changes: 2 additions & 2 deletions league_client/rso/loot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.rso.constants import LootNameTypes
from league_client.types import ProxyT


def get_loot_data(
ledge_token: str,
ledge_url: str,
puuid: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand Down
4 changes: 2 additions & 2 deletions league_client/rso/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.types import ProxyT


def get_match_data(
access_token: str,
puuid: str,
player_platform_edge_url: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
count: int = 30,
):
h = HEADERS.copy()
Expand Down
4 changes: 2 additions & 2 deletions league_client/rso/missions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.types import ProxyT


def get_missions(
ledge_token: str,
ledge_url: str,
inventory_tokens: list[str], # list of `EVENT_PASS, CHAMPION_SKIN` tokens
userinfo_token: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand Down
6 changes: 3 additions & 3 deletions league_client/rso/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import HEADERS
from league_client.types import ProxyT


def get_party_data(
Expand All @@ -20,7 +20,7 @@ def get_party_data(
ranked_overview_token: str,
inventory_token: str, # champion, champion_skin, skin_border, skin_augment
inventory_token_v2: str, # queue_entry
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand Down Expand Up @@ -75,7 +75,7 @@ def get_party_restrictions(
ledge_token: str,
ledge_url: str,
party_id: str,
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
):
h = HEADERS.copy()
h["Authorization"] = f"Bearer {ledge_token}"
Expand Down
4 changes: 2 additions & 2 deletions league_client/rso/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from typing import Optional

import httpx
from httpx._types import ProxyTypes

from league_client.constants import ACCOUNTODACTYL_PARAMS
from league_client.constants import HEADERS
from league_client.constants import PROD_XSS0_RIOTGAMES
from league_client.constants import SSL_CONTEXT
from league_client.rso.auth import authorize
from league_client.types import ProxyT


def parse_csrf_token(text: str):
Expand All @@ -25,7 +25,7 @@ def change_password_using_credentials(
password: str,
new_password: str,
captcha_solver: Callable[[str, str], str],
proxy: Optional[ProxyTypes] = None,
proxy: Optional[ProxyT] = None,
) -> bool:
with httpx.Client(verify=SSL_CONTEXT, proxy=proxy) as client:
authorize(
Expand Down
Loading

0 comments on commit 1280068

Please sign in to comment.