bafredo-devsms 0.1.0__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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.env
|
|
2
|
+
.env.local
|
|
3
|
+
.DS_Store
|
|
4
|
+
backend/.env
|
|
5
|
+
backend/bin/
|
|
6
|
+
backend/.cache/
|
|
7
|
+
backend/coverage.out
|
|
8
|
+
backend/devsms
|
|
9
|
+
backend/tmp/
|
|
10
|
+
firmware/.pio/
|
|
11
|
+
firmware/.vscode/
|
|
12
|
+
frontend/node_modules/
|
|
13
|
+
frontend/dist/
|
|
14
|
+
frontend/*.tsbuildinfo
|
|
15
|
+
frontend/vite.config.js
|
|
16
|
+
frontend/vite.config.d.ts
|
|
17
|
+
mosquitto/data/
|
|
18
|
+
mosquitto/log/
|
|
19
|
+
postgres-data/
|
|
20
|
+
sdks/java/target/
|
|
21
|
+
sdks/nodejs/*.tgz
|
|
22
|
+
sdks/python/**/__pycache__/
|
|
23
|
+
sdks/python/build/
|
|
24
|
+
sdks/python/dist/
|
|
25
|
+
testtext_muyoma_me/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bafredo-devsms
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official DevSMS SDK for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/Bafredo/devsms-python
|
|
6
|
+
Project-URL: Repository, https://github.com/Bafredo/devsms-python
|
|
7
|
+
Author: Bafredo
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: api,devsms,sdk,sms
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# DevSMS Python SDK
|
|
18
|
+
|
|
19
|
+
Package: `bafredo-devsms`
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install bafredo-devsms
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from devsms import DevSMSClient
|
|
31
|
+
|
|
32
|
+
client = DevSMSClient(api_key="YOUR_API_KEY")
|
|
33
|
+
|
|
34
|
+
response = client.send(
|
|
35
|
+
to="+254712345678",
|
|
36
|
+
message="Hello from Python",
|
|
37
|
+
correlation_id="order-1001",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
print(response.message_id, response.status)
|
|
41
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# DevSMS Python SDK
|
|
2
|
+
|
|
3
|
+
Package: `bafredo-devsms`
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install bafredo-devsms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from devsms import DevSMSClient
|
|
15
|
+
|
|
16
|
+
client = DevSMSClient(api_key="YOUR_API_KEY")
|
|
17
|
+
|
|
18
|
+
response = client.send(
|
|
19
|
+
to="+254712345678",
|
|
20
|
+
message="Hello from Python",
|
|
21
|
+
correlation_id="order-1001",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
print(response.message_id, response.status)
|
|
25
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
from urllib import error, request
|
|
7
|
+
|
|
8
|
+
DEFAULT_BASE_URL = "https://devtext.site"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DevSMSError(Exception):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
message: str,
|
|
15
|
+
status_code: int = 0,
|
|
16
|
+
details: Optional[dict[str, Any]] = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
super().__init__(message)
|
|
19
|
+
self.status_code = status_code
|
|
20
|
+
self.details = details or {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class SendSMSResponse:
|
|
25
|
+
message_id: str
|
|
26
|
+
status: str
|
|
27
|
+
to: str
|
|
28
|
+
message: str
|
|
29
|
+
correlation_id: Optional[str]
|
|
30
|
+
provider_reference: Optional[str]
|
|
31
|
+
created_at: Optional[str]
|
|
32
|
+
updated_at: Optional[str]
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def from_api_payload(cls, payload: dict[str, Any]) -> "SendSMSResponse":
|
|
36
|
+
return cls(
|
|
37
|
+
message_id=str(payload.get("id", "")),
|
|
38
|
+
status=str(payload.get("status", "")),
|
|
39
|
+
to=str(payload.get("to_number", "")),
|
|
40
|
+
message=str(payload.get("message", "")),
|
|
41
|
+
correlation_id=payload.get("correlation_id"),
|
|
42
|
+
provider_reference=payload.get("provider_reference"),
|
|
43
|
+
created_at=payload.get("created_at"),
|
|
44
|
+
updated_at=payload.get("updated_at"),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class DevSMSClient:
|
|
49
|
+
def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout: int = 30) -> None:
|
|
50
|
+
if not str(api_key or "").strip():
|
|
51
|
+
raise DevSMSError("api_key is required")
|
|
52
|
+
|
|
53
|
+
self.api_key = str(api_key).strip()
|
|
54
|
+
self.base_url = str(base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
55
|
+
self.timeout = timeout
|
|
56
|
+
|
|
57
|
+
def send(
|
|
58
|
+
self,
|
|
59
|
+
*,
|
|
60
|
+
to: str,
|
|
61
|
+
message: str,
|
|
62
|
+
correlation_id: Optional[str] = None,
|
|
63
|
+
) -> SendSMSResponse:
|
|
64
|
+
if not str(to or "").strip():
|
|
65
|
+
raise DevSMSError("to is required")
|
|
66
|
+
if not str(message or "").strip():
|
|
67
|
+
raise DevSMSError("message is required")
|
|
68
|
+
|
|
69
|
+
payload: dict[str, Any] = {
|
|
70
|
+
"to": str(to).strip(),
|
|
71
|
+
"message": str(message).strip(),
|
|
72
|
+
}
|
|
73
|
+
if str(correlation_id or "").strip():
|
|
74
|
+
payload["correlation_id"] = str(correlation_id).strip()
|
|
75
|
+
|
|
76
|
+
body = json.dumps(payload).encode("utf-8")
|
|
77
|
+
req = request.Request(
|
|
78
|
+
url=f"{self.base_url}/v1/sms/send",
|
|
79
|
+
data=body,
|
|
80
|
+
method="POST",
|
|
81
|
+
headers={
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
"X-API-Key": self.api_key,
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
with request.urlopen(req, timeout=self.timeout) as response:
|
|
89
|
+
raw = response.read().decode("utf-8")
|
|
90
|
+
parsed = json.loads(raw) if raw else {}
|
|
91
|
+
return SendSMSResponse.from_api_payload(parsed)
|
|
92
|
+
except error.HTTPError as exc:
|
|
93
|
+
raw = exc.read().decode("utf-8")
|
|
94
|
+
details = json.loads(raw) if raw else {}
|
|
95
|
+
raise DevSMSError(
|
|
96
|
+
details.get("error", f"DevSMS request failed with status {exc.code}"),
|
|
97
|
+
status_code=exc.code,
|
|
98
|
+
details=details,
|
|
99
|
+
) from exc
|
|
100
|
+
except error.URLError as exc:
|
|
101
|
+
raise DevSMSError(str(exc.reason), status_code=0) from exc
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bafredo-devsms"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official DevSMS SDK for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Bafredo" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["devsms", "sms", "sdk", "api"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/Bafredo/devsms-python"
|
|
25
|
+
Repository = "https://github.com/Bafredo/devsms-python"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["devsms"]
|