pixelarraythirdparty 1.0.0__tar.gz → 1.0.2__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.
Files changed (23) hide show
  1. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/PKG-INFO +1 -1
  2. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/__init__.py +1 -1
  3. pixelarraythirdparty-1.0.2/pixelarraythirdparty/celery/celery.py +37 -0
  4. pixelarraythirdparty-1.0.2/pixelarraythirdparty/client.py +22 -0
  5. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/order/order.py +26 -24
  6. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/order/pay.py +14 -21
  7. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/product/product.py +26 -24
  8. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/user/user.py +28 -24
  9. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty.egg-info/PKG-INFO +1 -1
  10. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty.egg-info/SOURCES.txt +1 -1
  11. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pyproject.toml +1 -1
  12. pixelarraythirdparty-1.0.0/pixelarraythirdparty/auth.py +0 -0
  13. pixelarraythirdparty-1.0.0/pixelarraythirdparty/celery/celery.py +0 -38
  14. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/LICENSE +0 -0
  15. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/MANIFEST.in +0 -0
  16. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/celery/__init__.py +0 -0
  17. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/order/__init__.py +0 -0
  18. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/product/__init__.py +0 -0
  19. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty/user/__init__.py +0 -0
  20. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty.egg-info/dependency_links.txt +0 -0
  21. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty.egg-info/requires.txt +0 -0
  22. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/pixelarraythirdparty.egg-info/top_level.txt +0 -0
  23. {pixelarraythirdparty-1.0.0 → pixelarraythirdparty-1.0.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraythirdparty
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: PixelArray 第三方微服务客户端
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -10,7 +10,7 @@ PixelArray 第三方微服务客户端
10
10
  - user: 用户管理模块
11
11
  """
12
12
 
13
- __version__ = "1.0.0"
13
+ __version__ = "1.0.2"
14
14
  __author__ = "Lu qi"
15
15
  __email__ = "qi.lu@pixelarrayai.com"
16
16
 
@@ -0,0 +1,37 @@
1
+ from pixelarraythirdparty.client import Client
2
+
3
+
4
+ class CeleryManager(Client):
5
+ def get_celery_status(self):
6
+ data, success = self._request("GET", "/api/celery/status")
7
+ if not success:
8
+ return {}, False
9
+ return data, True
10
+
11
+ def get_celery_tasks(self):
12
+ data, success = self._request("GET", "/api/celery/tasks")
13
+ if not success:
14
+ return {}, False
15
+ return data, True
16
+
17
+ def get_celery_tasks_scheduled(self):
18
+ data, success = self._request("GET", "/api/celery/tasks/scheduled")
19
+ if not success:
20
+ return {}, False
21
+ return data, True
22
+
23
+ def get_celery_tasks_detail(self, task_name: str):
24
+ data, success = self._request("GET", f"/api/celery/tasks/{task_name}")
25
+ if not success:
26
+ return {}, False
27
+ return data, True
28
+
29
+ def trigger_celery_task(self, task_name: str, args: list, kwargs: dict):
30
+ data, success = self._request(
31
+ "POST",
32
+ f"/api/celery/tasks/{task_name}/trigger",
33
+ json={"args": args, "kwargs": kwargs},
34
+ )
35
+ if not success:
36
+ return {}, False
37
+ return data, True
@@ -0,0 +1,22 @@
1
+ import requests
2
+ from typing import Dict, Any, Optional, Tuple
3
+
4
+
5
+ class Client:
6
+ """基础认证类,提供公共的 API key 认证和请求方法"""
7
+ def __init__(self, api_key: str):
8
+ self.base_url = "https://thirdparty.pixelarrayai.com"
9
+ self.api_key = api_key
10
+ self.headers = {
11
+ "Content-Type": "application/json",
12
+ "X-API-Key": self.api_key,
13
+ }
14
+
15
+ def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
16
+ """统一的请求方法"""
17
+ resp = requests.request(
18
+ method, f"{self.base_url}{url}", headers=self.headers, **kwargs
19
+ )
20
+ if resp.status_code == 200 and resp.json().get("success") is True:
21
+ return resp.json().get("data", {}), True
22
+ return {}, False
@@ -1,23 +1,7 @@
1
- import requests
1
+ from pixelarraythirdparty.client import Client
2
2
 
3
3
 
4
- class OrderManager:
5
- def __init__(self, api_key: str):
6
- self.base_url = "https://thirdparty.pixelarrayai.com"
7
- self.api_key = api_key
8
- self.headers = {
9
- "Content-Type": "application/json",
10
- "X-API-Key": self.api_key,
11
- }
12
-
13
- def _request(self, method, url, **kwargs):
14
- resp = requests.request(
15
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
16
- )
17
- if resp.status_code == 200:
18
- return resp.json().get("data", {})
19
- return {}
20
-
4
+ class OrderManager(Client):
21
5
  def create_order(
22
6
  self,
23
7
  product_name: str,
@@ -35,7 +19,10 @@ class OrderManager:
35
19
  "remark": remark,
36
20
  "payment_channel": payment_channel,
37
21
  }
38
- return self._request("POST", "/api/orders/create", json=data)
22
+ data, success = self._request("POST", "/api/orders/create", json=data)
23
+ if not success:
24
+ return {}, False
25
+ return data, True
39
26
 
40
27
  def list_order(
41
28
  self,
@@ -50,10 +37,16 @@ class OrderManager:
50
37
  "payment_status": payment_status,
51
38
  "order_no": order_no,
52
39
  }
53
- return self._request("GET", "/api/orders/list", params=params)
40
+ data, success = self._request("GET", "/api/orders/list", params=params)
41
+ if not success:
42
+ return {}, False
43
+ return data, True
54
44
 
55
45
  def get_order_detail(self, order_no: str):
56
- return self._request("GET", f"/api/orders/{order_no}")
46
+ data, success = self._request("GET", f"/api/orders/{order_no}")
47
+ if not success:
48
+ return {}, False
49
+ return data, True
57
50
 
58
51
  def update_order(
59
52
  self,
@@ -81,10 +74,19 @@ class OrderManager:
81
74
  "time_end": time_end,
82
75
  "remark": remark,
83
76
  }
84
- return self._request("PUT", f"/api/orders/{order_no}", json=data)
77
+ data, success = self._request("PUT", f"/api/orders/{order_no}", json=data)
78
+ if not success:
79
+ return {}, False
80
+ return data, True
85
81
 
86
82
  def delete_order(self, order_no: str):
87
- return self._request("DELETE", f"/api/orders/{order_no}")
83
+ data, success = self._request("DELETE", f"/api/orders/{order_no}")
84
+ if not success:
85
+ return {}, False
86
+ return data, True
88
87
 
89
88
  def get_order_stats(self):
90
- return self._request("GET", "/api/orders/stats/summary")
89
+ data, success = self._request("GET", "/api/orders/stats/summary")
90
+ if not success:
91
+ return {}, False
92
+ return data, True
@@ -1,23 +1,7 @@
1
- import requests
1
+ from pixelarraythirdparty.client import Client
2
2
 
3
3
 
4
- class WeChatPayManager:
5
- def __init__(self, api_key: str):
6
- self.base_url = "https://thirdparty.pixelarrayai.com"
7
- self.api_key = api_key
8
- self.headers = {
9
- "Content-Type": "application/json",
10
- "X-API-Key": self.api_key,
11
- }
12
-
13
- def _request(self, method, url, **kwargs):
14
- resp = requests.request(
15
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
16
- )
17
- if resp.status_code == 200:
18
- return resp.json().get("data", {})
19
- return {}
20
-
4
+ class WeChatPayManager(Client):
21
5
  def generate_qr_code(
22
6
  self,
23
7
  out_trade_no: str,
@@ -26,7 +10,7 @@ class WeChatPayManager:
26
10
  product_name: str,
27
11
  product_id: str,
28
12
  ):
29
- return self._request(
13
+ data, success = self._request(
30
14
  "POST",
31
15
  "/api/wx_pay/generate_qr_code",
32
16
  json={
@@ -37,15 +21,24 @@ class WeChatPayManager:
37
21
  "product_id": product_id,
38
22
  },
39
23
  )
24
+ if not success:
25
+ return {}, False
26
+ return data, True
40
27
 
41
28
  def query_order(self, out_trade_no: str):
42
- return self._request(
29
+ data, success = self._request(
43
30
  "POST", "/api/wx_pay/query_order", json={"out_trade_no": out_trade_no}
44
31
  )
32
+ if not success:
33
+ return {}, False
34
+ return data, True
45
35
 
46
36
  def refund(self, out_trade_no: str, total_fee: int):
47
- return self._request(
37
+ data, success = self._request(
48
38
  "POST",
49
39
  "/api/wx_pay/refund",
50
40
  json={"out_trade_no": out_trade_no, "total_fee": total_fee},
51
41
  )
42
+ if not success:
43
+ return {}, False
44
+ return data, True
@@ -1,23 +1,7 @@
1
- import requests
1
+ from pixelarraythirdparty.client import Client
2
2
 
3
3
 
4
- class ProductManager:
5
- def __init__(self, api_key: str):
6
- self.base_url = "https://thirdparty.pixelarrayai.com"
7
- self.api_key = api_key
8
- self.headers = {
9
- "Content-Type": "application/json",
10
- "X-API-Key": self.api_key,
11
- }
12
-
13
- def _request(self, method, url, **kwargs):
14
- resp = requests.request(
15
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
16
- )
17
- if resp.status_code == 200:
18
- return resp.json().get("data", {})
19
- return {}
20
-
4
+ class ProductManager(Client):
21
5
  def create_product(
22
6
  self,
23
7
  name: str,
@@ -41,7 +25,10 @@ class ProductManager:
41
25
  "features": features,
42
26
  "sort_order": sort_order,
43
27
  }
44
- return self._request("POST", "/api/products/create", json=data)
28
+ data, success = self._request("POST", "/api/products/create", json=data)
29
+ if not success:
30
+ return {}, False
31
+ return data, True
45
32
 
46
33
  def list_product(
47
34
  self,
@@ -64,10 +51,16 @@ class ProductManager:
64
51
  params["category"] = category
65
52
  if name is not None:
66
53
  params["name"] = name
67
- return self._request("GET", "/api/products/list", params=params)
54
+ data, success = self._request("GET", "/api/products/list", params=params)
55
+ if not success:
56
+ return {}, False
57
+ return data, True
68
58
 
69
59
  def get_product_detail(self, product_id: str):
70
- return self._request("GET", f"/api/products/{product_id}")
60
+ data, success = self._request("GET", f"/api/products/{product_id}")
61
+ if not success:
62
+ return {}, False
63
+ return data, True
71
64
 
72
65
  def update_product(
73
66
  self,
@@ -93,10 +86,19 @@ class ProductManager:
93
86
  "features": features,
94
87
  "sort_order": sort_order,
95
88
  }
96
- return self._request("PUT", f"/api/products/{product_id}", json=data)
89
+ data, success = self._request("PUT", f"/api/products/{product_id}", json=data)
90
+ if not success:
91
+ return {}, False
92
+ return data, True
97
93
 
98
94
  def delete_product(self, product_id: str):
99
- return self._request("DELETE", f"/api/products/{product_id}")
95
+ data, success = self._request("DELETE", f"/api/products/{product_id}")
96
+ if not success:
97
+ return {}, False
98
+ return data, True
100
99
 
101
100
  def get_product_categories(self):
102
- return self._request("GET", "/api/products/categories/list")
101
+ data, success = self._request("GET", "/api/products/categories/list")
102
+ if not success:
103
+ return {}, False
104
+ return data, True
@@ -1,25 +1,9 @@
1
- import requests
2
1
  import aiohttp
3
2
  from typing import Optional
3
+ from pixelarraythirdparty.client import Client
4
4
 
5
5
 
6
- class UserManager:
7
- def __init__(self, api_key: str):
8
- self.base_url = "https://thirdparty.pixelarrayai.com"
9
- self.api_key = api_key
10
- self.headers = {
11
- "Content-Type": "application/json",
12
- "X-API-Key": self.api_key,
13
- }
14
-
15
- def _request(self, method, url, **kwargs):
16
- resp = requests.request(
17
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
18
- )
19
- if resp.status_code == 200:
20
- return resp.json().get("data", {})
21
- return {}
22
-
6
+ class UserManager(Client):
23
7
  def list_user(
24
8
  self,
25
9
  page: int = 1,
@@ -32,7 +16,10 @@ class UserManager:
32
16
  params["role"] = role
33
17
  if is_active is not None:
34
18
  params["is_active"] = is_active
35
- return self._request("GET", "/api/users/list", params=params)
19
+ data, success = self._request("GET", "/api/users/list", params=params)
20
+ if not success:
21
+ return {}, False
22
+ return data, True
36
23
 
37
24
  def create_user(self, username: str, password: str, email: str, role: str):
38
25
  data = {
@@ -41,7 +28,10 @@ class UserManager:
41
28
  "email": email,
42
29
  "role": role,
43
30
  }
44
- return self._request("POST", "/api/users/create", json=data)
31
+ data, success = self._request("POST", "/api/users/create", json=data)
32
+ if not success:
33
+ return {}, False
34
+ return data, True
45
35
 
46
36
  def update_user(
47
37
  self, user_id: int, username: str, email: str, role: str, is_active: bool
@@ -52,14 +42,28 @@ class UserManager:
52
42
  "role": role,
53
43
  "is_active": is_active,
54
44
  }
55
- return self._request("PUT", f"/api/users/{user_id}", json=data)
45
+ data, success = self._request("PUT", f"/api/users/{user_id}", json=data)
46
+ if not success:
47
+ return {}, False
48
+ return data, True
56
49
 
57
50
  def delete_user(self, user_id: int):
58
- return self._request("DELETE", f"/api/users/{user_id}")
51
+ data, success = self._request("DELETE", f"/api/users/{user_id}")
52
+ if not success:
53
+ return {}, False
54
+ return data, True
59
55
 
60
56
  def get_user_detail(self, user_id: int):
61
- return self._request("GET", f"/api/users/{user_id}")
57
+ data, success = self._request("GET", f"/api/users/{user_id}")
58
+ if not success:
59
+ return {}, False
60
+ return data, True
62
61
 
63
62
  def reset_user_password(self, user_id: int, new_password: str):
64
63
  data = {"new_password": new_password}
65
- return self._request("POST", f"/api/users/{user_id}/reset-password", json=data)
64
+ data, success = self._request(
65
+ "POST", f"/api/users/{user_id}/reset-password", json=data
66
+ )
67
+ if not success:
68
+ return {}, False
69
+ return data, True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraythirdparty
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: PixelArray 第三方微服务客户端
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -2,7 +2,7 @@ LICENSE
2
2
  MANIFEST.in
3
3
  pyproject.toml
4
4
  pixelarraythirdparty/__init__.py
5
- pixelarraythirdparty/auth.py
5
+ pixelarraythirdparty/client.py
6
6
  pixelarraythirdparty.egg-info/PKG-INFO
7
7
  pixelarraythirdparty.egg-info/SOURCES.txt
8
8
  pixelarraythirdparty.egg-info/dependency_links.txt
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pixelarraythirdparty"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  authors = [
9
9
  {name = "Lu qi", email = "qi.lu@pixelarrayai.com"},
10
10
  ]
File without changes
@@ -1,38 +0,0 @@
1
- import requests
2
-
3
-
4
- class CeleryManager:
5
- def __init__(self, api_key: str):
6
- self.base_url = "https://thirdparty.pixelarrayai.com"
7
- self.api_key = api_key
8
- self.headers = {
9
- "Content-Type": "application/json",
10
- "X-API-Key": self.api_key,
11
- }
12
-
13
- def _request(self, method, url, **kwargs):
14
- resp = requests.request(
15
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
16
- )
17
- if resp.status_code == 200:
18
- return resp.json().get("data", {})
19
- return {}
20
-
21
- def get_celery_status(self):
22
- return self._request("GET", "/api/celery/status")
23
-
24
- def get_celery_tasks(self):
25
- return self._request("GET", "/api/celery/tasks")
26
-
27
- def get_celery_tasks_scheduled(self):
28
- return self._request("GET", "/api/celery/tasks/scheduled")
29
-
30
- def get_celery_tasks_detail(self, task_name: str):
31
- return self._request("GET", f"/api/celery/tasks/{task_name}")
32
-
33
- def trigger_celery_task(self, task_name: str, args: list, kwargs: dict):
34
- return self._request(
35
- "POST",
36
- f"/api/celery/tasks/{task_name}/trigger",
37
- json={"args": args, "kwargs": kwargs},
38
- )