diarama-api 0.1.18__tar.gz → 0.1.27__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diarama-api
3
- Version: 0.1.18
3
+ Version: 0.1.27
4
4
  Summary: Python SDK для работы с API Diarama Studio
5
5
  Author-email: Haru <hello@chinoharu.ru>
6
6
  License: MIT
@@ -1,3 +1,4 @@
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
@@ -17,3 +18,4 @@ class DiaramaAPI:
17
18
  self.media = Media(self.client)
18
19
  self.platforms = Platforms(self.client)
19
20
  self.files = Files(self.client)
21
+ self.shop = Shop(self.client)
@@ -0,0 +1,58 @@
1
+ import json
2
+ import requests
3
+
4
+ class DiaramaAPIClient:
5
+ def __init__(self, api_key: str, base_url: str = "https://api.diaramastudio.ru"):
6
+ self.api_key = api_key
7
+ self.base_url = base_url
8
+ self.headers = {
9
+ "X-API-Key": api_key,
10
+ "Content-Type": "application/json; charset=utf-8"
11
+ }
12
+
13
+ def _get(self, endpoint, params=None):
14
+ r = requests.get(f"{self.base_url}{endpoint}", headers=self.headers, params=params)
15
+ r.raise_for_status()
16
+
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
+
38
+ r.raise_for_status()
39
+ return r.json()
40
+
41
+ def _put(self, endpoint, data=None):
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)
44
+ r.raise_for_status()
45
+ return r.json()
46
+
47
+ def _delete(self, endpoint):
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()
@@ -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}")
@@ -16,5 +16,11 @@ class Media:
16
16
 
17
17
  def upload(self, file_obj):
18
18
  """Загрузить файл как медиа"""
19
- files = {'file': file_obj}
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}
20
26
  return self.client._post("/media/upload", files=files)
@@ -5,6 +5,9 @@ class Players:
5
5
  def list(self):
6
6
  return self.client._get("/players/")
7
7
 
8
+ def get_by_username(self, username: str):
9
+ return self.client._get(f"/players/{username}")
10
+
8
11
  def get(self, player_id: int):
9
12
  return self.client._get(f"/players/{player_id}")
10
13
 
@@ -14,6 +17,10 @@ class Players:
14
17
  if avatar_id: data["avatar_id"] = avatar_id
15
18
  return self.client._post("/players/", data)
16
19
 
20
+ def login(self, username, password):
21
+ data = {"username": username, "password": password}
22
+ return self.client._post("/players/login", data)
23
+
17
24
  def update(self, player_id, **kwargs):
18
25
  allowed = ["email", "banned", "role_id", "avatar_id"]
19
26
  data = {k: v for k, v in kwargs.items() if k in allowed}
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diarama-api
3
- Version: 0.1.18
3
+ Version: 0.1.27
4
4
  Summary: Python SDK для работы с API Diarama Studio
5
5
  Author-email: Haru <hello@chinoharu.ru>
6
6
  License: MIT
@@ -8,6 +8,7 @@ diarama_api/media.py
8
8
  diarama_api/payments.py
9
9
  diarama_api/platforms.py
10
10
  diarama_api/players.py
11
+ diarama_api/shop.py
11
12
  diarama_api.egg-info/PKG-INFO
12
13
  diarama_api.egg-info/SOURCES.txt
13
14
  diarama_api.egg-info/dependency_links.txt
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "diarama-api"
3
- version = "0.1.18"
3
+ version = "0.1.27"
4
4
  description = "Python SDK для работы с API Diarama Studio"
5
5
  authors = [{ name = "Haru", email = "hello@chinoharu.ru" }]
6
6
  readme = "README.md"
@@ -1,33 +0,0 @@
1
- import json
2
- import requests
3
-
4
- class DiaramaAPIClient:
5
- def __init__(self, api_key: str, base_url: str = "https://api.diaramastudio.ru"):
6
- self.api_key = api_key
7
- self.base_url = base_url
8
- self.headers = {
9
- "X-API-Key": api_key,
10
- "Content-Type": "application/json; charset=utf-8"
11
- }
12
-
13
- def _get(self, endpoint, params=None):
14
- r = requests.get(f"{self.base_url}{endpoint}", headers=self.headers, params=params)
15
- r.raise_for_status()
16
- return r.json()
17
-
18
- def _post(self, endpoint, data=None):
19
- json_data = json.dumps(data, ensure_ascii=False).encode('utf-8')
20
- r = requests.post(f"{self.base_url}{endpoint}", headers=self.headers, data=json_data)
21
- r.raise_for_status()
22
- return r.json()
23
-
24
- def _put(self, endpoint, data=None):
25
- json_data = json.dumps(data, ensure_ascii=False).encode('utf-8')
26
- r = requests.put(f"{self.base_url}{endpoint}", headers=self.headers, data=json_data)
27
- r.raise_for_status()
28
- return r.json()
29
-
30
- def _delete(self, endpoint):
31
- r = requests.delete(f"{self.base_url}{endpoint}", headers=self.headers)
32
- r.raise_for_status()
33
- return r.json()
@@ -1,17 +0,0 @@
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/{filename}")
10
-
11
- def upload(self, file_obj, filename):
12
- files = {'file': (filename, file_obj)}
13
- return self.client._post("/files", files=files)
14
-
15
- def edit(self, filename, content):
16
- data = {"content": content}
17
- return self.client._put(f"/files/{filename}", json=data)
File without changes