Skip to content

Commit 8fac07d

Browse files
committed
✨: create , utilize new subpackage
1 parent 315f52b commit 8fac07d

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

valorant/aio.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import typing as t
2+
import urllib.parse
3+
4+
from .lexicon import Lex
5+
6+
from .callers import AsyncCaller
7+
8+
from .objects import (
9+
DTO,
10+
ActDTO,
11+
AccountDTO,
12+
ContentDTO,
13+
ContentItemDTO,
14+
LeaderboardDTO,
15+
LeaderboardIterator,
16+
PlatformDataDTO,
17+
MatchDTO,
18+
)
19+
20+
21+
class AsyncClient(object):
22+
def __init__(
23+
self,
24+
key: t.Text,
25+
locale: t.Optional[t.Text] = Lex.LOCALE,
26+
region: t.Text = "na",
27+
route: t.Text = "americas",
28+
):
29+
self.key = key
30+
self.route = route
31+
self.locale = locale
32+
self.region = region
33+
self.handle = AsyncCaller(key, locale=locale, region=region, route=route)
34+
35+
async def _content_from_cache(self, from_cache=True):
36+
if from_cache and getattr(self, "content", False):
37+
return self.content
38+
else:
39+
self.content = ContentDTO(await self.handle.call("GET", "content"))
40+
41+
return self.content
42+
43+
async def get_content(self, cache: bool=False) -> ContentDTO:
44+
return await self._content_from_cache(from_cache=cache)

valorant/client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import requests
21
import typing as t
32
import urllib.parse
43

54
from .lexicon import Lex
65

7-
from .caller import WebCaller
6+
from .callers import WebCaller
87

98
from .objects import (
109
DTO,
@@ -66,22 +65,22 @@ def __init__(
6665
self.route = route
6766
self.locale = locale
6867
self.region = region
69-
self.handle = WebCaller(key, locale, region, route)
68+
self.handle = WebCaller(key, locale=locale, region=region, route=route)
7069

7170
if load_content:
7271
self.get_content(cache=True)
7372
else:
7473
self.content = None
7574

75+
def __getattribute__(self, name):
76+
return super(Client, self).__getattribute__(name)
77+
7678
def _content_if_cache(self) -> ContentDTO:
7779
if content := getattr(self, "content", None):
7880
return content
7981
else:
8082
return ContentDTO(self.handle.call("GET", "content"))
8183

82-
def __getattribute__(self, name):
83-
return super(Client, self).__getattribute__(name)
84-
8584
def asset(
8685
self, **attributes: t.Mapping[t.Text, t.Any]
8786
) -> t.Optional[t.Union[ActDTO, ContentItemDTO]]:
@@ -161,7 +160,7 @@ def get_chromas(self, strip: bool = False) -> t.List[ContentItemDTO]:
161160

162161
return chromas
163162

164-
def get_content(self, cache: bool = True) -> ContentDTO:
163+
def get_content(self, cache: bool = False) -> ContentDTO:
165164
"""Get complete content data from VALORANT.
166165
167166
:param cache: If set to ``True``, the Client will cache the response data,
@@ -377,8 +376,7 @@ def get_user_by_name(
377376
:type route: str
378377
:rtype: Optional[AccountDTO]
379378
"""
380-
vals = name.split("#")
381-
vals = [urllib.parse.quote(v, safe=Lex.SAFES) for v in vals]
379+
vals = [urllib.parse.quote(v, safe=Lex.SAFES) for v in name.split("#")]
382380

383381
r = self.handle.call(
384382
"GET",

0 commit comments

Comments
 (0)