waapi 0.1.0__tar.gz → 0.1.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.
- {waapi-0.1.0 → waapi-0.1.2}/PKG-INFO +14 -27
- {waapi-0.1.0 → waapi-0.1.2}/README.md +12 -4
- {waapi-0.1.0 → waapi-0.1.2}/pyproject.toml +6 -4
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/__init__.py +1 -1
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/_http.py +22 -9
- {waapi-0.1.0 → waapi-0.1.2}/tests/test_client.py +23 -0
- {waapi-0.1.0 → waapi-0.1.2}/.github/workflows/publish.yml +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/.github/workflows/tests.yml +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/.gitignore +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/CONTRIBUTING.md +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/LICENSE +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/scripts/sync_actions.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/_actions.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/_generated.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/client.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/exceptions.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/src/waapi/py.typed +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/tests/conftest.py +0 -0
- {waapi-0.1.0 → waapi-0.1.2}/tests/test_generated_actions.py +0 -0
|
@@ -1,38 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: waapi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Official Python SDK for the WaAPI REST API
|
|
5
5
|
Project-URL: Homepage, https://waapi.app
|
|
6
6
|
Project-URL: Documentation, https://waapi.app/docs
|
|
7
7
|
Project-URL: Source, https://github.com/WaAPIapp/waapi-python-sdk
|
|
8
8
|
Project-URL: Issues, https://github.com/WaAPIapp/waapi-python-sdk/issues
|
|
9
9
|
Author-email: WaAPI <info@waapi.app>
|
|
10
|
-
License:
|
|
11
|
-
|
|
12
|
-
Copyright (c) WaAPI <info@waapi.app>
|
|
13
|
-
|
|
14
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
-
in the Software without restriction, including without limitation the rights
|
|
17
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
-
furnished to do so, subject to the following conditions:
|
|
20
|
-
|
|
21
|
-
The above copyright notice and this permission notice shall be included in all
|
|
22
|
-
copies or substantial portions of the Software.
|
|
23
|
-
|
|
24
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
-
SOFTWARE.
|
|
10
|
+
License-Expression: MIT
|
|
31
11
|
License-File: LICENSE
|
|
32
12
|
Keywords: api,automation,chatbot,messaging,sdk,waapi
|
|
33
13
|
Classifier: Development Status :: 4 - Beta
|
|
34
14
|
Classifier: Intended Audience :: Developers
|
|
35
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
36
15
|
Classifier: Programming Language :: Python :: 3
|
|
37
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
38
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -105,10 +84,18 @@ async with AsyncWaAPI(token="YOUR_API_TOKEN", instance_id=123) as client:
|
|
|
105
84
|
|
|
106
85
|
## Errors
|
|
107
86
|
|
|
108
|
-
A successful HTTP exchange is not proof the message was sent. The API
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
A successful HTTP exchange is not proof the message was sent. The API carries
|
|
88
|
+
two envelopes:
|
|
89
|
+
|
|
90
|
+
| Field | Answers |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `status` | did the request reach the instance |
|
|
93
|
+
| `data.status` | did the instance carry the action out |
|
|
94
|
+
|
|
95
|
+
**The inner one is authoritative.** A malformed chat ID comes back as
|
|
96
|
+
`{"status": "success", "data": {"status": "error", …}}` — nothing was sent. The
|
|
97
|
+
SDK raises `FailedActionError` on either envelope, so neither case reaches you
|
|
98
|
+
looking like success.
|
|
112
99
|
|
|
113
100
|
```python
|
|
114
101
|
from waapi import WaAPI, FailedActionError, AuthenticationError, RateLimitError
|
|
@@ -51,10 +51,18 @@ async with AsyncWaAPI(token="YOUR_API_TOKEN", instance_id=123) as client:
|
|
|
51
51
|
|
|
52
52
|
## Errors
|
|
53
53
|
|
|
54
|
-
A successful HTTP exchange is not proof the message was sent. The API
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
A successful HTTP exchange is not proof the message was sent. The API carries
|
|
55
|
+
two envelopes:
|
|
56
|
+
|
|
57
|
+
| Field | Answers |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `status` | did the request reach the instance |
|
|
60
|
+
| `data.status` | did the instance carry the action out |
|
|
61
|
+
|
|
62
|
+
**The inner one is authoritative.** A malformed chat ID comes back as
|
|
63
|
+
`{"status": "success", "data": {"status": "error", …}}` — nothing was sent. The
|
|
64
|
+
SDK raises `FailedActionError` on either envelope, so neither case reaches you
|
|
65
|
+
looking like success.
|
|
58
66
|
|
|
59
67
|
```python
|
|
60
68
|
from waapi import WaAPI, FailedActionError, AuthenticationError, RateLimitError
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "waapi"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Official Python SDK for the WaAPI REST API"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
|
|
10
|
+
# PEP 639: an SPDX expression, not the file. The table form made PyPI
|
|
11
|
+
# render the whole licence text where the licence name belongs.
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
11
14
|
requires-python = ">=3.9"
|
|
12
15
|
authors = [{ name = "WaAPI", email = "info@waapi.app" }]
|
|
13
16
|
keywords = ["waapi", "messaging", "api", "sdk", "automation", "chatbot"]
|
|
14
17
|
classifiers = [
|
|
15
18
|
"Development Status :: 4 - Beta",
|
|
16
19
|
"Intended Audience :: Developers",
|
|
17
|
-
"License :: OSI Approved :: MIT License",
|
|
18
20
|
"Programming Language :: Python :: 3",
|
|
19
21
|
"Programming Language :: Python :: 3.9",
|
|
20
22
|
"Programming Language :: Python :: 3.10",
|
|
@@ -73,20 +73,33 @@ def interpret(response: httpx.Response, *, check_body_status: bool = True) -> An
|
|
|
73
73
|
if not 200 <= status < 300:
|
|
74
74
|
raise WaAPIError(f"WaAPI returned HTTP {status}: {_brief(body)}")
|
|
75
75
|
|
|
76
|
-
#
|
|
77
|
-
#
|
|
76
|
+
# Two envelopes, and the inner one is the authoritative answer:
|
|
77
|
+
#
|
|
78
|
+
# body.status did the request reach the instance
|
|
79
|
+
# body.data.status did the instance carry the action out
|
|
80
|
+
#
|
|
81
|
+
# A malformed chatId comes back as {"status": "success", "data":
|
|
82
|
+
# {"status": "error", "message": "incorrect chatId format."}} -- nothing
|
|
83
|
+
# was sent. Checking only the outer envelope reports that as delivered,
|
|
84
|
+
# which is the exact failure this class exists to prevent, one level down.
|
|
78
85
|
if check_body_status and isinstance(body, Mapping):
|
|
79
|
-
envelope
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
for envelope in (_inner_status(body), body.get("status")):
|
|
87
|
+
if envelope is not None and envelope != "success":
|
|
88
|
+
raise FailedActionError(
|
|
89
|
+
"WaAPI accepted the request but did not carry the action out: "
|
|
90
|
+
+ _brief(body),
|
|
91
|
+
body,
|
|
92
|
+
)
|
|
86
93
|
|
|
87
94
|
return body
|
|
88
95
|
|
|
89
96
|
|
|
97
|
+
def _inner_status(body: Mapping[str, Any]) -> Any:
|
|
98
|
+
"""``body.data.status`` when the response wraps a client action."""
|
|
99
|
+
data = body.get("data")
|
|
100
|
+
return data.get("status") if isinstance(data, Mapping) else None
|
|
101
|
+
|
|
102
|
+
|
|
90
103
|
def _brief(body: Any, limit: int = 400) -> str:
|
|
91
104
|
text = body if isinstance(body, str) else _json.dumps(body, ensure_ascii=False)
|
|
92
105
|
return text if len(text) <= limit else text[:limit] + "..."
|
|
@@ -212,3 +212,26 @@ def test_the_generated_surface_is_not_empty():
|
|
|
212
212
|
|
|
213
213
|
methods = {n for n in vars(GeneratedActions) if not n.startswith("_")}
|
|
214
214
|
assert len(methods) > 100, f"only {len(methods)} generated methods"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_the_inner_status_is_the_authoritative_one():
|
|
218
|
+
"""A request can reach the instance and still not be carried out.
|
|
219
|
+
|
|
220
|
+
The outer envelope reports delivery to the instance; the inner one reports
|
|
221
|
+
whether the instance did the thing. A malformed chatId produces
|
|
222
|
+
success-outside, error-inside — and was reported as sent until the check
|
|
223
|
+
looked one level down.
|
|
224
|
+
"""
|
|
225
|
+
client = client_returning(200, {
|
|
226
|
+
"status": "success",
|
|
227
|
+
"data": {"status": "error", "message": "incorrect chatId format."},
|
|
228
|
+
})
|
|
229
|
+
with pytest.raises(FailedActionError) as excinfo:
|
|
230
|
+
client.send_message(chat_id="bogus", message="must not count as sent")
|
|
231
|
+
assert "did not carry the action out" in str(excinfo.value)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_a_data_array_does_not_trip_the_inner_check():
|
|
235
|
+
"""Plenty of actions return a list in `data`, which has no status at all."""
|
|
236
|
+
client = client_returning(200, {"status": "success", "data": [{"id": 1}, {"id": 2}]})
|
|
237
|
+
assert client.get_chats()["data"] == [{"id": 1}, {"id": 2}]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|