diarama-api 0.1.19__py3-none-any.whl → 0.1.26__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 CHANGED
@@ -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)
diarama_api/client.py CHANGED
@@ -13,7 +13,16 @@ class DiaramaAPIClient:
13
13
  def _get(self, endpoint, params=None):
14
14
  r = requests.get(f"{self.base_url}{endpoint}", headers=self.headers, params=params)
15
15
  r.raise_for_status()
16
- return r.json()
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
+
17
26
 
18
27
  def _post(self, endpoint, data=None, files=None):
19
28
  url = f"{self.base_url}{endpoint}"
@@ -36,6 +45,14 @@ class DiaramaAPIClient:
36
45
  return r.json()
37
46
 
38
47
  def _delete(self, endpoint):
39
- r = requests.delete(f"{self.base_url}{endpoint}", headers=self.headers)
40
- r.raise_for_status()
41
- return r.json()
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 CHANGED
@@ -6,12 +6,16 @@ class Files:
6
6
  return self.client._get("/files")
7
7
 
8
8
  def download(self, filename):
9
- return self.client._get(f"/files/{filename}")
9
+ return self.client._get(f"/files/get/{filename}")
10
10
 
11
11
  def upload(self, file_obj, filename):
12
12
  files = {'file': (filename, file_obj)}
13
- return self.client._post("/files", files=files)
13
+ return self.client._post("/files/upload", files=files)
14
14
 
15
15
  def edit(self, filename, content):
16
16
  data = {"content": content}
17
- return self.client._put(f"/files/{filename}", json=data)
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/media.py CHANGED
@@ -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)
diarama_api/players.py CHANGED
@@ -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
 
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diarama-api
3
- Version: 0.1.19
3
+ Version: 0.1.26
4
4
  Summary: Python SDK для работы с API Diarama Studio
5
5
  Author-email: Haru <hello@chinoharu.ru>
6
6
  License: MIT
@@ -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=cX1kxP_G4shpEjosTNkbrSNJjLMGFxO_DWi_gtE_Kg0,998
10
+ diarama_api/shop.py,sha256=IKwbPO0qy-e_lns0Bp3xIVvqplYkS6gWNBe_WGXuRaU,2870
11
+ diarama_api-0.1.26.dist-info/METADATA,sha256=lVmSXrdNci7N001xxkD9LlM5feqbbzeXmZ0s9o8T1tk,324
12
+ diarama_api-0.1.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ diarama_api-0.1.26.dist-info/top_level.txt,sha256=OcL6tQomtjFhzrraJ9GouJCWoc668jQEsqbUGxM8E7E,12
14
+ diarama_api-0.1.26.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- diarama_api/__init__.py,sha256=5vRMtDZp2LSs0IH1SoMZwS7bWtBUWeYufZAUyeGFZAQ,643
2
- diarama_api/auth.py,sha256=y5PkFDqMyD2FXQ0fepEzlS_XDAguLcS1fqq7lKkwV_Y,358
3
- diarama_api/client.py,sha256=7VseMp0Zssd4DWmWJxWbzO0fFrCdorQF5WsAth9DfXc,1489
4
- diarama_api/files.py,sha256=MYkViq0tT3B-mM2khoZPwTOfVA_rfD56cSOFLXDCsnk,530
5
- diarama_api/games.py,sha256=4Bls55VmOIXEbLw0HVIffa-dAZBVyze4Ii4UD3pSITE,950
6
- diarama_api/media.py,sha256=jregTsjacX0C2Mj4OEkETz1G3nCZR3ix_8s93mkNz0c,709
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-0.1.19.dist-info/METADATA,sha256=Zx4uZitwWyMQzMnznolYffhmEMPn1svy6SpQODZ2uRQ,324
11
- diarama_api-0.1.19.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- diarama_api-0.1.19.dist-info/top_level.txt,sha256=OcL6tQomtjFhzrraJ9GouJCWoc668jQEsqbUGxM8E7E,12
13
- diarama_api-0.1.19.dist-info/RECORD,,