dataify-sdk 1.4.0__tar.gz → 1.4.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 (101) hide show
  1. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/PKG-INFO +2 -2
  2. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/README.md +1 -1
  3. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/docs/AI_WEB.md +2 -2
  4. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/docs/WEB_MONITOR.md +1 -1
  5. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/pyproject.toml +1 -1
  6. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/__init__.py +1 -1
  7. dataify_sdk-1.4.2/src/dataify_sdk/errors.py +114 -0
  8. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/web_monitor.py +26 -7
  9. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_client/test_web_monitor.py +47 -0
  10. dataify_sdk-1.4.2/tests/test_errors.py +68 -0
  11. dataify_sdk-1.4.0/src/dataify_sdk/errors.py +0 -67
  12. dataify_sdk-1.4.0/tests/test_errors.py +0 -43
  13. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/.gitignore +0 -0
  14. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/LICENSE +0 -0
  15. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/examples/ai_web.py +0 -0
  16. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/examples/web_monitor.py +0 -0
  17. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/scripts/codegen.py +0 -0
  18. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/_codegen/__init__.py +0 -0
  19. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/_codegen/generate.py +0 -0
  20. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/ai_web.py +0 -0
  21. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/client.py +0 -0
  22. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/__init__.py +0 -0
  23. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/airbnbproduct.py +0 -0
  24. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazoncomment.py +0 -0
  25. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonglobalproduct.py +0 -0
  26. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonproduct.py +0 -0
  27. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonproductlist.py +0 -0
  28. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/amazonseller.py +0 -0
  29. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingimages.py +0 -0
  30. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingmaps.py +0 -0
  31. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingnews.py +0 -0
  32. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingsearch.py +0 -0
  33. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingshopping.py +0 -0
  34. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bingvideos.py +0 -0
  35. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/bookinghotellist.py +0 -0
  36. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/chatgptanswer.py +0 -0
  37. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/crunchbasecompany.py +0 -0
  38. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/duckduckgosearch.py +0 -0
  39. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/ebayinfo.py +0 -0
  40. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookcomment.py +0 -0
  41. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookevent.py +0 -0
  42. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookpost.py +0 -0
  43. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/facebookprofile.py +0 -0
  44. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/githubrepository.py +0 -0
  45. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/glassdoorcompany.py +0 -0
  46. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/glassdoorjoblistings.py +0 -0
  47. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleaimode.py +0 -0
  48. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlefinance.py +0 -0
  49. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleflights.py +0 -0
  50. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlehotels.py +0 -0
  51. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleimages.py +0 -0
  52. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlejobs.py +0 -0
  53. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlelens.py +0 -0
  54. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlelocal.py +0 -0
  55. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemapcomment.py +0 -0
  56. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemapdetails.py +0 -0
  57. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlemaps.py +0 -0
  58. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlenews.py +0 -0
  59. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlepatents.py +0 -0
  60. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplay.py +0 -0
  61. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplaystoreinformation.py +0 -0
  62. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleplaystorereviews.py +0 -0
  63. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlescholar.py +0 -0
  64. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlesearch.py +0 -0
  65. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleshopping.py +0 -0
  66. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googleshoppinginfo.py +0 -0
  67. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googletrends.py +0 -0
  68. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/googlevideos.py +0 -0
  69. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/indeedcompaniesinfo.py +0 -0
  70. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/indeedjoblistings.py +0 -0
  71. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramcomment.py +0 -0
  72. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramprofiles.py +0 -0
  73. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/instagramreel.py +0 -0
  74. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/linkedincompanyinformation.py +0 -0
  75. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/linkedinjoblistingsinformation.py +0 -0
  76. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/redditcomment.py +0 -0
  77. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/redditposts.py +0 -0
  78. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokcomment.py +0 -0
  79. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokposts.py +0 -0
  80. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokprofiles.py +0 -0
  81. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/tiktokshop.py +0 -0
  82. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/twitterpost.py +0 -0
  83. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/twitterprofile.py +0 -0
  84. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/walmartproduct.py +0 -0
  85. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/yandexsearch.py +0 -0
  86. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeaudio.py +0 -0
  87. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubecomment.py +0 -0
  88. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeproduct.py +0 -0
  89. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubeprofiles.py +0 -0
  90. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubetranscript.py +0 -0
  91. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubevideo.py +0 -0
  92. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/youtubevideopost.py +0 -0
  93. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/src/dataify_sdk/tools/zillowproduct.py +0 -0
  94. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/__init__.py +0 -0
  95. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/conftest.py +0 -0
  96. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_client/__init__.py +0 -0
  97. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_client/test_ai_web.py +0 -0
  98. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_client/test_http_client.py +0 -0
  99. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_tools/__init__.py +0 -0
  100. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_tools/test_codegen.py +0 -0
  101. {dataify_sdk-1.4.0 → dataify_sdk-1.4.2}/tests/test_tools/test_tool_modules.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dataify-sdk
3
- Version: 1.4.0
3
+ Version: 1.4.2
4
4
  Summary: Python SDK that calls the Dataify upstream REST API directly (no MCP layer) for web scrapers and search engines.
5
5
  Project-URL: Homepage, https://dashboard.dataify.com
6
6
  Project-URL: Repository, https://github.com/dataify-server/dataify-sdk-python
@@ -151,7 +151,7 @@ client = DataifyClient(token="YOUR_TOKEN")
151
151
  try:
152
152
  result = google_search(q="pizza", client=client)
153
153
  except DataifyAPIError as e:
154
- print(f"上游返回错误 HTTP {e.status_code}: {e.body}")
154
+ print(f"上游返回错误 HTTP {e.status_code}: {e.code} {e.message}")
155
155
  except DataifyConnectionError:
156
156
  print("无法连接 Dataify 上游")
157
157
  ```
@@ -126,7 +126,7 @@ client = DataifyClient(token="YOUR_TOKEN")
126
126
  try:
127
127
  result = google_search(q="pizza", client=client)
128
128
  except DataifyAPIError as e:
129
- print(f"上游返回错误 HTTP {e.status_code}: {e.body}")
129
+ print(f"上游返回错误 HTTP {e.status_code}: {e.code} {e.message}")
130
130
  except DataifyConnectionError:
131
131
  print("无法连接 Dataify 上游")
132
132
  ```
@@ -171,7 +171,7 @@ if result.request_id:
171
171
  ## 错误处理
172
172
 
173
173
  - 未配置网关:抛出 `DataifyMissingAIWebBaseUrlError`,请求不会发出。
174
- - 上游返回非 2xx:抛出 `DataifyAPIError`,包含 `status_code` 和 `body`。
174
+ - 上游返回非 2xx:抛出 `DataifyAPIError`,包含 `status_code`、解析后的 `code` / `message`,以及原始 `body`。
175
175
  - 缺少 `unique_id`、`query` 或 `url`:抛出 `ValueError`。
176
176
  - `formats` 非法或重复:抛出 `ValueError`。
177
177
 
@@ -185,5 +185,5 @@ try:
185
185
  except DataifyMissingAIWebBaseUrlError:
186
186
  print("AI Web 网关不可用")
187
187
  except DataifyAPIError as exc:
188
- print(f"AI Web 返回错误 HTTP {exc.status_code}: {exc.body}")
188
+ print(f"AI Web 返回错误 HTTP {exc.status_code}: {exc.code} {exc.message}")
189
189
  ```
@@ -26,7 +26,7 @@ client = DataifyClient() # token 从 DATAIFY_API_TOKEN 读取
26
26
  | `client.web_monitor.list_checks(...)` | `POST /watch/checks/list` | 查询监控记录 |
27
27
  | `client.web_monitor.update_job(job_id, ...)` | `POST /watch/jobs/update` | 编辑监控任务 |
28
28
 
29
- `job_id` 支持 `mwj_` 平台任务 ID 或 `job_` 中台任务 ID。
29
+ `job_id` 支持 `mwj_` 平台任务 ID 或 `job_` 中台任务 ID;也兼容 `create_job` 响应中的整数 `id`,SDK 会自动转换为字符串后提交。
30
30
 
31
31
  ## 创建任务
32
32
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataify-sdk"
7
- version = "1.4.0"
7
+ version = "1.4.2"
8
8
  description = "Python SDK that calls the Dataify upstream REST API directly (no MCP layer) for web scrapers and search engines."
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -48,7 +48,7 @@ from dataify_sdk.errors import (
48
48
  DataifyValueError,
49
49
  )
50
50
 
51
- __version__ = "1.4.0"
51
+ __version__ = "1.4.2"
52
52
 
53
53
 
54
54
 
@@ -0,0 +1,114 @@
1
+ """Exceptions raised by the Dataify SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+
9
+ class DataifyError(Exception):
10
+ """Base class for all Dataify SDK errors."""
11
+
12
+
13
+ class DataifyValueError(DataifyError, ValueError):
14
+ """Raised when SDK input validation fails."""
15
+
16
+
17
+ class DataifyAPIError(DataifyError):
18
+ """Raised when the Dataify upstream API returns an error.
19
+
20
+ Attributes
21
+ ----------
22
+ message:
23
+ Parsed upstream message when available, otherwise the request-level
24
+ fallback message.
25
+ code:
26
+ Parsed upstream error code, for example ``INVALID_API_KEY``.
27
+ api_message:
28
+ Parsed upstream message; ``None`` when the body has no usable message.
29
+ context_message:
30
+ Request-level message supplied by the SDK before parsing the body.
31
+ status_code:
32
+ HTTP status code returned by the upstream (``None`` for network errors).
33
+ body:
34
+ Decoded response body (or error text) returned by the upstream.
35
+ """
36
+
37
+ def __init__(
38
+ self,
39
+ message: str,
40
+ status_code: int | None = None,
41
+ body: str | bytes | None = None,
42
+ ) -> None:
43
+ decoded_body = _decode_error_body(body)
44
+ code, api_message = _parse_error_body(decoded_body)
45
+ self.context_message = message
46
+ self.status_code = status_code
47
+ self.body = decoded_body
48
+ self.code = code
49
+ self.api_message = api_message
50
+ self.message = api_message or message
51
+ super().__init__(self.message)
52
+
53
+ def __str__(self) -> str:
54
+ if self.status_code is not None:
55
+ return f"{self.message} (HTTP {self.status_code})"
56
+ return self.message
57
+
58
+
59
+ def _decode_error_body(body: str | bytes | None) -> str | None:
60
+ if body is None:
61
+ return None
62
+ if isinstance(body, bytes):
63
+ return body.decode("utf-8", errors="replace")
64
+ return body
65
+
66
+
67
+ def _parse_error_body(body: str | None) -> tuple[str | None, str | None]:
68
+ if not body or not body.strip():
69
+ return None, None
70
+ try:
71
+ payload: Any = json.loads(body)
72
+ except (TypeError, ValueError):
73
+ return None, None
74
+ if not isinstance(payload, dict):
75
+ return None, None
76
+
77
+ raw_code = payload.get("code")
78
+ code = str(raw_code).strip() if raw_code is not None else ""
79
+ if not code:
80
+ code = None
81
+
82
+ raw_message = payload.get("message")
83
+ if raw_message is None:
84
+ data = payload.get("data")
85
+ if isinstance(data, str):
86
+ raw_message = data
87
+ elif isinstance(data, dict):
88
+ raw_message = data.get("message")
89
+ message = str(raw_message).strip() if raw_message is not None else ""
90
+ if not message:
91
+ message = None
92
+ return code, message
93
+
94
+
95
+ class DataifyConnectionError(DataifyError):
96
+ """Raised when the HTTP request to the Dataify upstream cannot be completed."""
97
+
98
+
99
+ class DataifyTimeoutError(DataifyError):
100
+ """Raised when the HTTP request to the Dataify upstream times out."""
101
+
102
+
103
+ class DataifyMissingAIWebBaseUrlError(DataifyError):
104
+ """Raised when an AI Web request has no usable gateway base URL.
105
+
106
+ The SDK defaults to ``https://aiwebapi.dataify.com``. This error only
107
+ occurs when the client's AI Web base URL is explicitly cleared.
108
+ """
109
+
110
+ def __init__(self) -> None:
111
+ super().__init__(
112
+ "AI Web base URL is empty: pass ai_web_base_url=... "
113
+ "or set AI_WEB_API_BASE_URL."
114
+ )
@@ -99,17 +99,17 @@ class WebMonitorService:
99
99
  )
100
100
  return self._post("/watch/jobs/create", payload)
101
101
 
102
- def delete_job(self, job_id: str) -> dict[str, Any]:
102
+ def delete_job(self, job_id: str | int) -> dict[str, Any]:
103
103
  """Delete a web monitoring job (``POST /watch/jobs/delete``)."""
104
104
 
105
105
  return self._post("/watch/jobs/delete", {"id": _require_job_id(job_id)})
106
106
 
107
- def resume_job(self, job_id: str) -> dict[str, Any]:
107
+ def resume_job(self, job_id: str | int) -> dict[str, Any]:
108
108
  """Resume a paused or abnormal job (``POST /watch/jobs/resume``)."""
109
109
 
110
110
  return self._post("/watch/jobs/resume", {"id": _require_job_id(job_id)})
111
111
 
112
- def pause_job(self, job_id: str) -> dict[str, Any]:
112
+ def pause_job(self, job_id: str | int) -> dict[str, Any]:
113
113
  """Pause a web monitoring job (``POST /watch/jobs/pause``)."""
114
114
 
115
115
  return self._post("/watch/jobs/pause", {"id": _require_job_id(job_id)})
@@ -166,7 +166,7 @@ class WebMonitorService:
166
166
  def list_checks(
167
167
  self,
168
168
  *,
169
- job_id: str | None = None,
169
+ job_id: str | int | None = None,
170
170
  check_status: int | None = None,
171
171
  start: int | None = None,
172
172
  end: int | None = None,
@@ -178,7 +178,7 @@ class WebMonitorService:
178
178
  _validate_time_range(start, end)
179
179
  payload = _compact(
180
180
  {
181
- "job_id": _validate_optional_text("job_id", job_id, 2048),
181
+ "job_id": _validate_optional_job_id(job_id),
182
182
  "check_status": (
183
183
  _validate_int_range("check_status", check_status, 1, 4)
184
184
  if check_status is not None
@@ -202,7 +202,7 @@ class WebMonitorService:
202
202
 
203
203
  def update_job(
204
204
  self,
205
- job_id: str,
205
+ job_id: str | int,
206
206
  *,
207
207
  url: str | None = None,
208
208
  webhook_url: str | None = None,
@@ -296,8 +296,27 @@ def _compact(payload: dict[str, Any]) -> dict[str, Any]:
296
296
  return {key: value for key, value in payload.items() if value is not None}
297
297
 
298
298
 
299
+ def _normalize_job_id(value: Any) -> str:
300
+ if isinstance(value, bool):
301
+ raise DataifyValueError("job_id must be a non-empty string or integer")
302
+ if isinstance(value, int):
303
+ value = str(value)
304
+ if not isinstance(value, str) or not value.strip():
305
+ raise DataifyValueError("job_id must be a non-empty string or integer")
306
+ value = value.strip()
307
+ if len(value) > 2048:
308
+ raise DataifyValueError("job_id must be at most 2048 characters")
309
+ return value
310
+
311
+
299
312
  def _require_job_id(value: Any) -> str:
300
- return _require_text("job_id", value, 2048)
313
+ return _normalize_job_id(value)
314
+
315
+
316
+ def _validate_optional_job_id(value: Any) -> str | None:
317
+ if value is None:
318
+ return None
319
+ return _normalize_job_id(value)
301
320
 
302
321
 
303
322
  def _require_text(name: str, value: Any, max_length: int | None = None) -> str:
@@ -131,6 +131,50 @@ def test_delete_resume_pause_jobs(web_monitor_server):
131
131
  ]
132
132
 
133
133
 
134
+ def test_job_id_accepts_integer_and_normalizes_to_string(web_monitor_server):
135
+ client = _client()
136
+ client.web_monitor.delete_job(123)
137
+ client.web_monitor.resume_job(124)
138
+ client.web_monitor.pause_job(125)
139
+ client.web_monitor.list_checks(job_id=126)
140
+ client.web_monitor.update_job(127, mask_enabled=0)
141
+
142
+ assert [_body(req) for req in web_monitor_server.calls] == [
143
+ {"id": "123"},
144
+ {"id": "124"},
145
+ {"id": "125"},
146
+ {"job_id": "126"},
147
+ {"id": "127", "mask_enabled": 0},
148
+ ]
149
+
150
+
151
+ def test_create_job_result_id_can_be_passed_directly_to_delete(web_monitor_server):
152
+ web_monitor_server.responses.append(
153
+ (
154
+ json.dumps(
155
+ {
156
+ "success": True,
157
+ "code": "OK",
158
+ "message": "",
159
+ "data": {"id": 1329},
160
+ }
161
+ ),
162
+ {},
163
+ )
164
+ )
165
+ client = _client()
166
+ created = client.web_monitor.create_job("https://example.com", 1, interval_seconds=60)
167
+
168
+ client.web_monitor.delete_job(created["data"]["id"])
169
+
170
+ assert _body(web_monitor_server.calls[1]) == {"id": "1329"}
171
+
172
+
173
+ def test_job_id_rejects_boolean():
174
+ with pytest.raises(DataifyValueError, match="non-empty string or integer"):
175
+ _client().web_monitor.delete_job(True)
176
+
177
+
134
178
  def test_list_jobs_payload(web_monitor_server):
135
179
  _client().web_monitor.list_jobs(
136
180
  task_id="mwj_1",
@@ -289,3 +333,6 @@ def test_http_error_propagates(monkeypatch):
289
333
  _client().web_monitor.list_jobs()
290
334
 
291
335
  assert exc.value.status_code == 401
336
+ assert exc.value.code == "INVALID_API_KEY"
337
+ assert exc.value.api_message is None
338
+ assert exc.value.message.startswith("Dataify API request failed:")
@@ -0,0 +1,68 @@
1
+ """Tests for SDK exception formatting."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+
7
+ from dataify_sdk import (
8
+ DataifyAPIError,
9
+ DataifyConnectionError,
10
+ DataifyError,
11
+ DataifyMissingAIWebBaseUrlError,
12
+ DataifyTimeoutError,
13
+ )
14
+
15
+
16
+ def test_dataify_api_error_parses_code_and_message():
17
+ error = DataifyAPIError(
18
+ "request failed",
19
+ 401,
20
+ '{"code": "INVALID_API_KEY", "message": "invalid token"}',
21
+ )
22
+
23
+ assert error.code == "INVALID_API_KEY"
24
+ assert error.api_message == "invalid token"
25
+ assert error.message == "invalid token"
26
+ assert error.context_message == "request failed"
27
+ assert error.body == '{"code": "INVALID_API_KEY", "message": "invalid token"}'
28
+ assert str(error) == "invalid token (HTTP 401)"
29
+
30
+
31
+ def test_dataify_api_error_parses_legacy_data_message():
32
+ error = DataifyAPIError("request failed", 400, '{"code": 400, "data": "验证失败"}')
33
+
34
+ assert error.code == "400"
35
+ assert error.api_message == "验证失败"
36
+ assert error.message == "验证失败"
37
+
38
+
39
+ def test_dataify_api_error_falls_back_for_non_json_body():
40
+ error = DataifyAPIError("request failed", 500, "upstream unavailable")
41
+
42
+ assert error.code is None
43
+ assert error.api_message is None
44
+ assert error.message == "request failed"
45
+ assert str(error) == "request failed (HTTP 500)"
46
+
47
+
48
+ def test_dataify_api_error_str_without_status():
49
+ error = DataifyAPIError("boom")
50
+
51
+ assert str(error) == "boom"
52
+
53
+
54
+ @pytest.mark.parametrize(
55
+ "error",
56
+ [
57
+ DataifyError("boom"),
58
+ DataifyAPIError("boom"),
59
+ DataifyConnectionError("boom"),
60
+ DataifyTimeoutError("boom"),
61
+ DataifyMissingAIWebBaseUrlError(),
62
+ ],
63
+ )
64
+ def test_every_dataify_error_can_be_printed(error):
65
+ rendered = str(error)
66
+
67
+ assert isinstance(rendered, str)
68
+ assert rendered
@@ -1,67 +0,0 @@
1
- """Exceptions raised by the Dataify SDK."""
2
-
3
- from __future__ import annotations
4
-
5
-
6
- class DataifyError(Exception):
7
- """Base class for all Dataify SDK errors."""
8
-
9
-
10
- class DataifyValueError(DataifyError, ValueError):
11
- """Raised when SDK input validation fails."""
12
-
13
-
14
- class DataifyAPIError(DataifyError):
15
- """Raised when the Dataify upstream API returns an error.
16
-
17
- Attributes
18
- ----------
19
- message:
20
- Human-readable error message.
21
- status_code:
22
- HTTP status code returned by the upstream (``None`` for network errors).
23
- body:
24
- Raw response body (or error text) returned by the upstream.
25
- """
26
-
27
-
28
-
29
- def __init__(
30
- self,
31
- message: str,
32
- status_code: int | None = None,
33
- body: str | None = None,
34
- ) -> None:
35
- self.message = message
36
- self.status_code = status_code
37
- self.body = body
38
- super().__init__(message)
39
-
40
-
41
-
42
- def __str__(self) -> str:
43
- if self.status_code is not None:
44
- return f"{self.message} (HTTP {self.status_code})"
45
- return self.message
46
-
47
-
48
- class DataifyConnectionError(DataifyError):
49
- """Raised when the HTTP request to the Dataify upstream cannot be completed."""
50
-
51
-
52
- class DataifyTimeoutError(DataifyError):
53
- """Raised when the HTTP request to the Dataify upstream times out."""
54
-
55
-
56
- class DataifyMissingAIWebBaseUrlError(DataifyError):
57
- """Raised when an AI Web request has no usable gateway base URL.
58
-
59
- The SDK defaults to ``https://aiwebapi.dataify.com``. This error only
60
- occurs when the client's AI Web base URL is explicitly cleared.
61
- """
62
-
63
- def __init__(self) -> None:
64
- super().__init__(
65
- "AI Web base URL is empty: pass ai_web_base_url=... "
66
- "or set AI_WEB_API_BASE_URL."
67
- )
@@ -1,43 +0,0 @@
1
- """Tests for SDK exception formatting."""
2
-
3
- from __future__ import annotations
4
-
5
- import pytest
6
-
7
- from dataify_sdk import (
8
- DataifyAPIError,
9
- DataifyConnectionError,
10
- DataifyError,
11
- DataifyMissingAIWebBaseUrlError,
12
- DataifyTimeoutError,
13
- )
14
-
15
-
16
- def test_dataify_api_error_str_includes_message_and_status():
17
- error = DataifyAPIError("boom", 401, '{"message": "invalid"}')
18
-
19
- assert error.message == "boom"
20
- assert str(error) == "boom (HTTP 401)"
21
-
22
-
23
- def test_dataify_api_error_str_without_status():
24
- error = DataifyAPIError("boom")
25
-
26
- assert str(error) == "boom"
27
-
28
-
29
- @pytest.mark.parametrize(
30
- "error",
31
- [
32
- DataifyError("boom"),
33
- DataifyAPIError("boom"),
34
- DataifyConnectionError("boom"),
35
- DataifyTimeoutError("boom"),
36
- DataifyMissingAIWebBaseUrlError(),
37
- ],
38
- )
39
- def test_every_dataify_error_can_be_printed(error):
40
- rendered = str(error)
41
-
42
- assert isinstance(rendered, str)
43
- assert rendered
File without changes
File without changes