diarama-api 0.1.0__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.

Potentially problematic release.


This version of diarama-api might be problematic. Click here for more details.

diarama_api/_init_.py ADDED
@@ -0,0 +1,15 @@
1
+ from .client import DiaramaAPIClient
2
+ from .auth import Auth
3
+ from .players import Players
4
+ from .games import Games
5
+ from .payments import Payments
6
+ from .media import Media
7
+
8
+ class DiaramaAPI:
9
+ def __init__(self, api_key):
10
+ self.client = DiaramaAPIClient(api_key)
11
+ self.auth = Auth(self.client)
12
+ self.players = Players(self.client)
13
+ self.games = Games(self.client)
14
+ self.payments = Payments(self.client)
15
+ self.media = Media(self.client)
diarama_api/auth.py ADDED
@@ -0,0 +1,12 @@
1
+ class Auth:
2
+ def __init__(self, client):
3
+ self.client = client
4
+
5
+ def create_key(self, name: str):
6
+ return self.client._post("/auth/create-key", {"name": name})
7
+
8
+ def list(self):
9
+ return self.client._get("/auth/keys")
10
+
11
+ def deactivate(self, key_id: int):
12
+ return self.client._delete(f"/auth/keys/{key_id}")
diarama_api/client.py ADDED
@@ -0,0 +1,30 @@
1
+ import requests
2
+
3
+ class DiaramaAPIClient:
4
+ def __init__(self, api_key: str, base_url: str = "https://api.diaramastudio.ru"):
5
+ self.api_key = api_key
6
+ self.base_url = base_url
7
+ self.headers = {
8
+ "Authorization": f"Bearer {self.api_key}",
9
+ "Content-Type": "application/json"
10
+ }
11
+
12
+ def _get(self, endpoint, params=None):
13
+ r = requests.get(f"{self.base_url}{endpoint}", headers=self.headers, params=params)
14
+ r.raise_for_status()
15
+ return r.json()
16
+
17
+ def _post(self, endpoint, data=None):
18
+ r = requests.post(f"{self.base_url}{endpoint}", headers=self.headers, json=data)
19
+ r.raise_for_status()
20
+ return r.json()
21
+
22
+ def _put(self, endpoint, data=None):
23
+ r = requests.put(f"{self.base_url}{endpoint}", headers=self.headers, json=data)
24
+ r.raise_for_status()
25
+ return r.json()
26
+
27
+ def _delete(self, endpoint):
28
+ r = requests.delete(f"{self.base_url}{endpoint}", headers=self.headers)
29
+ r.raise_for_status()
30
+ return r.json()
diarama_api/games.py ADDED
@@ -0,0 +1,28 @@
1
+ class Games:
2
+ def __init__(self, client):
3
+ self.client = client
4
+
5
+ def list(self):
6
+ return self.client._get("/games/")
7
+
8
+ def get(self, game_id):
9
+ return self.client._get(f"/games/{game_id}")
10
+
11
+ def create(self, name, version, author, description, platform_id, media_id):
12
+ data = {
13
+ "name": name,
14
+ "version": version,
15
+ "author": author,
16
+ "description": description,
17
+ "platform_id": platform_id,
18
+ "media_id": media_id
19
+ }
20
+ return self.client._post("/games/", data)
21
+
22
+ def update(self, game_id, **kwargs):
23
+ allowed = ["name", "version", "author"]
24
+ data = {k: v for k, v in kwargs.items() if k in allowed}
25
+ return self.client._put(f"/games/{game_id}", data)
26
+
27
+ def delete(self, game_id):
28
+ return self.client._delete(f"/games/{game_id}")
diarama_api/media.py ADDED
@@ -0,0 +1,14 @@
1
+ class Media:
2
+ def __init__(self, client):
3
+ self.client = client
4
+
5
+ def create_image(self, url, alt_text=None):
6
+ data = {"url": url}
7
+ if alt_text: data["alt_text"] = alt_text
8
+ return self.client._post("/media/images", data)
9
+
10
+ def create_avatar(self, image_id):
11
+ return self.client._post("/media/avatars", {"image_id": image_id})
12
+
13
+ def create_banner(self, image_id):
14
+ return self.client._post("/media/banners", {"image_id": image_id})
@@ -0,0 +1,16 @@
1
+ class Payments:
2
+ def __init__(self, client):
3
+ self.client = client
4
+
5
+ def list(self, player_id=None):
6
+ params = {"player_id": player_id} if player_id else None
7
+ return self.client._get("/payments/", params=params)
8
+
9
+ def create(self, player_id, game_id, price, platform_id=None, paystatus_id=None):
10
+ data = {"player_id": player_id, "game_id": game_id, "price": price}
11
+ if platform_id: data["platform_id"] = platform_id
12
+ if paystatus_id: data["paystatus_id"] = paystatus_id
13
+ return self.client._post("/payments/", data)
14
+
15
+ def update_status(self, payment_id, paystatus_id):
16
+ return self.client._put(f"/payments/{payment_id}", {"paystatus_id": paystatus_id})
diarama_api/players.py ADDED
@@ -0,0 +1,23 @@
1
+ class Players:
2
+ def __init__(self, client):
3
+ self.client = client
4
+
5
+ def list(self):
6
+ return self.client._get("/players/")
7
+
8
+ def get(self, player_id: int):
9
+ return self.client._get(f"/players/{player_id}")
10
+
11
+ def create(self, username, password, email, role_id=None, avatar_id=None):
12
+ data = {"username": username, "password": password, "email": email}
13
+ if role_id: data["role_id"] = role_id
14
+ if avatar_id: data["avatar_id"] = avatar_id
15
+ return self.client._post("/players/", data)
16
+
17
+ def update(self, player_id, **kwargs):
18
+ allowed = ["email", "banned", "role_id", "avatar_id"]
19
+ data = {k: v for k, v in kwargs.items() if k in allowed}
20
+ return self.client._put(f"/players/{player_id}", data)
21
+
22
+ def delete(self, player_id):
23
+ return self.client._delete(f"/players/{player_id}")
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: diarama-api
3
+ Version: 0.1.0
4
+ Summary: Python SDK для работы с API Diarama Studio
5
+ Author-email: Haru <hello@chinoharu.ru>
6
+ License: MIT
7
+ Project-URL: Homepage, https://diaramastudio.ru
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: requests>=2.25.0
@@ -0,0 +1,11 @@
1
+ diarama_api/_init_.py,sha256=cJmhN50DnymYRMg3aLptA7UsbEoXswRQoV8S8AlpphY,493
2
+ diarama_api/auth.py,sha256=y5PkFDqMyD2FXQ0fepEzlS_XDAguLcS1fqq7lKkwV_Y,358
3
+ diarama_api/client.py,sha256=SrorvoDIV9Gq1iNe7NJDKIK14dzmAxjDoB0NP9oIMiA,1082
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.0.dist-info/METADATA,sha256=cMLXQr1_4AZMRxURs9sURp5KjcJ-AXfYDXih2nVindM,323
9
+ diarama_api-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ diarama_api-0.1.0.dist-info/top_level.txt,sha256=OcL6tQomtjFhzrraJ9GouJCWoc668jQEsqbUGxM8E7E,12
11
+ diarama_api-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ diarama_api