Skip to content

Commit 2fdfa04

Browse files
committed
Create LoadingApiWrapper class with authentication method
1 parent fe8f097 commit 2fdfa04

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

loading_api_wrapper/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from loading_api_wrapper.api import LoadingApiWrapper

loading_api_wrapper/api.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import requests
2+
3+
API_URL = "https://api.loading.se"
4+
API_VERSION = "v1"
5+
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
6+
7+
8+
class LoadingApiWrapper:
9+
def __init__(self, email=None, password=None):
10+
self.cookies = None
11+
12+
if email and password:
13+
response = self._authenticate(email, password)
14+
15+
if response.get("code") == 200:
16+
self.cookies = response.get("cookies")
17+
18+
def _authenticate(self, email, password):
19+
url = f"{API_URL}/{API_VERSION}/auth/login"
20+
headers = {
21+
"User-Agent": USER_AGENT,
22+
"content-type": "application/x-www-form-urlencoded",
23+
}
24+
data = {
25+
"email": email,
26+
"password": password,
27+
}
28+
response = requests.post(url, headers=headers, data=data)
29+
30+
if response.status_code == 200:
31+
return {"code": 200, "cookies": response.cookies}
32+
33+
return response.json()

0 commit comments

Comments
 (0)