-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbase.py
More file actions
43 lines (35 loc) · 1.09 KB
/
base.py
File metadata and controls
43 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from retroachievements import __version__
_BASE_URL = "https://retroachievements.org/API/"
class BaseRAClient:
"""
Main class for accessing the RetroAchievements Web API
"""
headers = {"User-Agent": "RetroAchievements-api-python/" + __version__}
def __init__(self, api_key: str):
self.api_key = api_key
def url_params(self, params: dict[str, str | int | None] | None = None):
"""
Inserts the auth and query params into the request
"""
if params is None:
params = {}
params.update({"y": self.api_key})
return params
# URL construction
def call_api(
self,
endpoint: str | None = None,
params: dict[str, str | int | None] | None = None,
timeout: int = 30,
headers: dict[str, str] | None = None,
):
if endpoint is None:
endpoint = ""
req = requests.get(
f"{_BASE_URL}{endpoint}",
params=self.url_params(params),
timeout=timeout,
headers=headers,
)
return req