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