diarama-api 0.1.12__py3-none-any.whl → 0.1.25__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diarama_api/__init__.py +6 -0
- diarama_api/client.py +35 -7
- diarama_api/files.py +21 -0
- diarama_api/games.py +1 -1
- diarama_api/media.py +13 -1
- diarama_api/platforms.py +26 -0
- diarama_api/shop.py +72 -0
- {diarama_api-0.1.12.dist-info → diarama_api-0.1.25.dist-info}/METADATA +1 -1
- diarama_api-0.1.25.dist-info/RECORD +14 -0
- diarama_api-0.1.12.dist-info/RECORD +0 -11
- {diarama_api-0.1.12.dist-info → diarama_api-0.1.25.dist-info}/WHEEL +0 -0
- {diarama_api-0.1.12.dist-info → diarama_api-0.1.25.dist-info}/top_level.txt +0 -0
diarama_api/__init__.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
from diarama_api.shop import Shop
|
|
1
2
|
from .client import DiaramaAPIClient
|
|
2
3
|
from .auth import Auth
|
|
3
4
|
from .players import Players
|
|
4
5
|
from .games import Games
|
|
5
6
|
from .payments import Payments
|
|
6
7
|
from .media import Media
|
|
8
|
+
from .platforms import Platforms
|
|
9
|
+
from .files import Files
|
|
7
10
|
|
|
8
11
|
class DiaramaAPI:
|
|
9
12
|
def __init__(self, api_key):
|
|
@@ -13,3 +16,6 @@ class DiaramaAPI:
|
|
|
13
16
|
self.games = Games(self.client)
|
|
14
17
|
self.payments = Payments(self.client)
|
|
15
18
|
self.media = Media(self.client)
|
|
19
|
+
self.platforms = Platforms(self.client)
|
|
20
|
+
self.files = Files(self.client)
|
|
21
|
+
self.shop = Shop(self.client)
|
diarama_api/client.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import requests
|
|
2
3
|
|
|
3
4
|
class DiaramaAPIClient:
|
|
@@ -12,19 +13,46 @@ class DiaramaAPIClient:
|
|
|
12
13
|
def _get(self, endpoint, params=None):
|
|
13
14
|
r = requests.get(f"{self.base_url}{endpoint}", headers=self.headers, params=params)
|
|
14
15
|
r.raise_for_status()
|
|
15
|
-
return r.json()
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try:
|
|
18
|
+
return r.json()
|
|
19
|
+
except ValueError:
|
|
20
|
+
content_type = r.headers.get("Content-Type", "")
|
|
21
|
+
if "text" in content_type or "json" in content_type or "utf" in content_type:
|
|
22
|
+
return {"content": r.text}
|
|
23
|
+
else:
|
|
24
|
+
return r.content
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _post(self, endpoint, data=None, files=None):
|
|
28
|
+
url = f"{self.base_url}{endpoint}"
|
|
29
|
+
headers = self.headers.copy()
|
|
30
|
+
|
|
31
|
+
if files:
|
|
32
|
+
headers.pop("Content-Type", None)
|
|
33
|
+
r = requests.post(url, headers=headers, files=files)
|
|
34
|
+
else:
|
|
35
|
+
json_data = json.dumps(data, ensure_ascii=False).encode('utf-8') if data else None
|
|
36
|
+
r = requests.post(url, headers=headers, data=json_data)
|
|
37
|
+
|
|
19
38
|
r.raise_for_status()
|
|
20
39
|
return r.json()
|
|
21
40
|
|
|
22
41
|
def _put(self, endpoint, data=None):
|
|
23
|
-
|
|
42
|
+
json_data = json.dumps(data, ensure_ascii=False).encode('utf-8')
|
|
43
|
+
r = requests.put(f"{self.base_url}{endpoint}", headers=self.headers, data=json_data)
|
|
24
44
|
r.raise_for_status()
|
|
25
45
|
return r.json()
|
|
26
46
|
|
|
27
47
|
def _delete(self, endpoint):
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
"""DELETE запрос"""
|
|
49
|
+
url = f"{self.base_url}{endpoint}"
|
|
50
|
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
|
51
|
+
response = requests.delete(url, headers=headers)
|
|
52
|
+
if response.status_code in [200, 204]:
|
|
53
|
+
try:
|
|
54
|
+
return response.json()
|
|
55
|
+
except:
|
|
56
|
+
return {"success": True}
|
|
57
|
+
else:
|
|
58
|
+
response.raise_for_status()
|
diarama_api/files.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Files:
|
|
2
|
+
def __init__(self, client):
|
|
3
|
+
self.client = client
|
|
4
|
+
|
|
5
|
+
def list(self):
|
|
6
|
+
return self.client._get("/files")
|
|
7
|
+
|
|
8
|
+
def download(self, filename):
|
|
9
|
+
return self.client._get(f"/files/get/{filename}")
|
|
10
|
+
|
|
11
|
+
def upload(self, file_obj, filename):
|
|
12
|
+
files = {'file': (filename, file_obj)}
|
|
13
|
+
return self.client._post("/files/upload", files=files)
|
|
14
|
+
|
|
15
|
+
def edit(self, filename, content):
|
|
16
|
+
data = {"content": content}
|
|
17
|
+
return self.client._put(f"/files/edit/{filename}", json=data)
|
|
18
|
+
|
|
19
|
+
def delete(self, filename):
|
|
20
|
+
"""Удаление файла"""
|
|
21
|
+
return self.client._delete(f"/files/delete/{filename}")
|
diarama_api/games.py
CHANGED
|
@@ -20,7 +20,7 @@ class Games:
|
|
|
20
20
|
return self.client._post("/games/", data)
|
|
21
21
|
|
|
22
22
|
def update(self, game_id, **kwargs):
|
|
23
|
-
allowed = ["name", "version", "author"]
|
|
23
|
+
allowed = ["name", "version", "author", "description", "platforms", "media_id"]
|
|
24
24
|
data = {k: v for k, v in kwargs.items() if k in allowed}
|
|
25
25
|
return self.client._put(f"/games/{game_id}", data)
|
|
26
26
|
|
diarama_api/media.py
CHANGED
|
@@ -4,7 +4,8 @@ class Media:
|
|
|
4
4
|
|
|
5
5
|
def create_image(self, url, alt_text=None):
|
|
6
6
|
data = {"url": url}
|
|
7
|
-
if alt_text:
|
|
7
|
+
if alt_text:
|
|
8
|
+
data["alt_text"] = alt_text
|
|
8
9
|
return self.client._post("/media/images", data)
|
|
9
10
|
|
|
10
11
|
def create_avatar(self, image_id):
|
|
@@ -12,3 +13,14 @@ class Media:
|
|
|
12
13
|
|
|
13
14
|
def create_banner(self, image_id):
|
|
14
15
|
return self.client._post("/media/banners", {"image_id": image_id})
|
|
16
|
+
|
|
17
|
+
def upload(self, file_obj):
|
|
18
|
+
"""Загрузить файл как медиа"""
|
|
19
|
+
# Если пришёл Flask FileStorage
|
|
20
|
+
if hasattr(file_obj, "stream") and hasattr(file_obj, "filename"):
|
|
21
|
+
file_tuple = (file_obj.filename, file_obj.stream, file_obj.mimetype)
|
|
22
|
+
files = {'file': file_tuple}
|
|
23
|
+
else:
|
|
24
|
+
# обычный open('file.png', 'rb')
|
|
25
|
+
files = {'file': file_obj}
|
|
26
|
+
return self.client._post("/media/upload", files=files)
|
diarama_api/platforms.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# api/platforms.py
|
|
2
|
+
class Platforms:
|
|
3
|
+
def __init__(self, client):
|
|
4
|
+
self.client = client
|
|
5
|
+
|
|
6
|
+
def list(self):
|
|
7
|
+
"""Получить список всех платформ"""
|
|
8
|
+
return self.client._get("/platforms/")
|
|
9
|
+
|
|
10
|
+
def get(self, platform_id):
|
|
11
|
+
"""Получить платформу по ID"""
|
|
12
|
+
return self.client._get(f"/platforms/{platform_id}")
|
|
13
|
+
|
|
14
|
+
def create(self, name):
|
|
15
|
+
"""Создать новую платформу"""
|
|
16
|
+
data = {"name": name}
|
|
17
|
+
return self.client._post("/platforms/", data)
|
|
18
|
+
|
|
19
|
+
def update(self, platform_id, name):
|
|
20
|
+
"""Обновить платформу"""
|
|
21
|
+
data = {"name": name}
|
|
22
|
+
return self.client._put(f"/platforms/{platform_id}", data)
|
|
23
|
+
|
|
24
|
+
def delete(self, platform_id):
|
|
25
|
+
"""Удалить платформу"""
|
|
26
|
+
return self.client._delete(f"/platforms/{platform_id}")
|
diarama_api/shop.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
class Shop:
|
|
2
|
+
def __init__(self, client):
|
|
3
|
+
self.client = client
|
|
4
|
+
|
|
5
|
+
# -------------------- CATEGORIES --------------------
|
|
6
|
+
def list_categories(self):
|
|
7
|
+
return self.client._get("/shop/categories")
|
|
8
|
+
|
|
9
|
+
def get_category(self, category_id: int):
|
|
10
|
+
return self.client._get(f"/shop/categories/{category_id}")
|
|
11
|
+
|
|
12
|
+
def create_category(self, name: str):
|
|
13
|
+
data = {"name": name}
|
|
14
|
+
return self.client._post("/shop/categories", data)
|
|
15
|
+
|
|
16
|
+
def update_category(self, category_id: int, name: str):
|
|
17
|
+
data = {"name": name}
|
|
18
|
+
return self.client._put(f"/shop/categories/{category_id}", data)
|
|
19
|
+
|
|
20
|
+
def delete_category(self, category_id: int):
|
|
21
|
+
return self.client._delete(f"/shop/categories/{category_id}")
|
|
22
|
+
|
|
23
|
+
# -------------------- PRODUCTS --------------------
|
|
24
|
+
def list_products(self):
|
|
25
|
+
return self.client._get("/shop/products")
|
|
26
|
+
|
|
27
|
+
def get_product(self, product_id: int):
|
|
28
|
+
return self.client._get(f"/shop/products/{product_id}")
|
|
29
|
+
|
|
30
|
+
def create_product(
|
|
31
|
+
self, title: str, short_description: str, price: float, product_type: str,
|
|
32
|
+
full_description: str = None, requirements: str = None,
|
|
33
|
+
seller_label: str = None, allow_multiple_purchase: bool = False,
|
|
34
|
+
media_id: int = None
|
|
35
|
+
):
|
|
36
|
+
data = {
|
|
37
|
+
"title": title,
|
|
38
|
+
"short_description": short_description,
|
|
39
|
+
"price": price,
|
|
40
|
+
"product_type": product_type,
|
|
41
|
+
"full_description": full_description,
|
|
42
|
+
"requirements": requirements,
|
|
43
|
+
"seller_label": seller_label,
|
|
44
|
+
"allow_multiple_purchase": allow_multiple_purchase,
|
|
45
|
+
"media_id": media_id
|
|
46
|
+
}
|
|
47
|
+
return self.client._post("/shop/products", data)
|
|
48
|
+
|
|
49
|
+
def update_product(self, product_id: int, **kwargs):
|
|
50
|
+
allowed = [
|
|
51
|
+
"title", "short_description", "full_description", "price",
|
|
52
|
+
"product_type", "requirements", "seller_label", "allow_multiple_purchase", "media_id"
|
|
53
|
+
]
|
|
54
|
+
data = {k: v for k, v in kwargs.items() if k in allowed}
|
|
55
|
+
return self.client._put(f"/shop/products/{product_id}", data)
|
|
56
|
+
|
|
57
|
+
def delete_product(self, product_id: int):
|
|
58
|
+
return self.client._delete(f"/shop/products/{product_id}")
|
|
59
|
+
|
|
60
|
+
# -------------------- USER PURCHASES --------------------
|
|
61
|
+
def list_user_purchases(self):
|
|
62
|
+
return self.client._get("/shop/user-purchases")
|
|
63
|
+
|
|
64
|
+
def create_user_purchase(self, player_id: int, product_id: int, purchase_price: float, license_key: str = None):
|
|
65
|
+
data = {
|
|
66
|
+
"player_id": player_id,
|
|
67
|
+
"product_id": product_id,
|
|
68
|
+
"purchase_price": purchase_price
|
|
69
|
+
}
|
|
70
|
+
if license_key:
|
|
71
|
+
data["license_key"] = license_key
|
|
72
|
+
return self.client._post("/shop/user-purchases", data)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
diarama_api/__init__.py,sha256=_rMIeavpVIY392LT1JFEXsfdSXzSzn1F6KtWvW7nBG4,717
|
|
2
|
+
diarama_api/auth.py,sha256=y5PkFDqMyD2FXQ0fepEzlS_XDAguLcS1fqq7lKkwV_Y,358
|
|
3
|
+
diarama_api/client.py,sha256=1CDEicXioaa3Qe1TbtGuqiRFCEhSv0yr_qB-tjCOtSg,2078
|
|
4
|
+
diarama_api/files.py,sha256=5--HKsT9G-H_gPi-jkW39zjstpLs8q_FoXO9Jd0a_nc,687
|
|
5
|
+
diarama_api/games.py,sha256=4Bls55VmOIXEbLw0HVIffa-dAZBVyze4Ii4UD3pSITE,950
|
|
6
|
+
diarama_api/media.py,sha256=Aq8rwadBr5u4gikZBHC_E1fHkbDvjGgwcOPXdMDDrlo,1031
|
|
7
|
+
diarama_api/payments.py,sha256=kA9jTsJsSf2e0D3T517Xchmy-WNGtQdAOcDpbbvXkAM,738
|
|
8
|
+
diarama_api/platforms.py,sha256=Rdb_kSROFDJ0qQTfc57DgoifC0nqRh6xfdn30zNEjw0,922
|
|
9
|
+
diarama_api/players.py,sha256=9ThcJKsQNhvBMvT6DI-rdxwfw4xa3C-9nTFEoNFFuLk,892
|
|
10
|
+
diarama_api/shop.py,sha256=IKwbPO0qy-e_lns0Bp3xIVvqplYkS6gWNBe_WGXuRaU,2870
|
|
11
|
+
diarama_api-0.1.25.dist-info/METADATA,sha256=-SbiffCHxw0UR26Q3bHpFpwF0qSf6bZbE8iUVrYx_EY,324
|
|
12
|
+
diarama_api-0.1.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
diarama_api-0.1.25.dist-info/top_level.txt,sha256=OcL6tQomtjFhzrraJ9GouJCWoc668jQEsqbUGxM8E7E,12
|
|
14
|
+
diarama_api-0.1.25.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
diarama_api/__init__.py,sha256=cJmhN50DnymYRMg3aLptA7UsbEoXswRQoV8S8AlpphY,493
|
|
2
|
-
diarama_api/auth.py,sha256=y5PkFDqMyD2FXQ0fepEzlS_XDAguLcS1fqq7lKkwV_Y,358
|
|
3
|
-
diarama_api/client.py,sha256=rH9Zm6rGqbgxRZ0pVZ0swlwgMQ3lNZYUT_vWS9U9PCg,1076
|
|
4
|
-
diarama_api/games.py,sha256=kYkkX0jHYftF6OZ2pSDns2eSenTyNu299CIgElNerAo,910
|
|
5
|
-
diarama_api/media.py,sha256=rwiOX2QSt5grZpj25639t4w8oyeV0Xtu72h_FF_d4WU,500
|
|
6
|
-
diarama_api/payments.py,sha256=kA9jTsJsSf2e0D3T517Xchmy-WNGtQdAOcDpbbvXkAM,738
|
|
7
|
-
diarama_api/players.py,sha256=9ThcJKsQNhvBMvT6DI-rdxwfw4xa3C-9nTFEoNFFuLk,892
|
|
8
|
-
diarama_api-0.1.12.dist-info/METADATA,sha256=iIvNWQoqqbWveH-_x0JQGlpxoVg3FKIBK921rRMvVq8,324
|
|
9
|
-
diarama_api-0.1.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
diarama_api-0.1.12.dist-info/top_level.txt,sha256=OcL6tQomtjFhzrraJ9GouJCWoc668jQEsqbUGxM8E7E,12
|
|
11
|
-
diarama_api-0.1.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|