netsware-sdk 1.0.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.
- netsware_sdk-1.0.0/PKG-INFO +85 -0
- netsware_sdk-1.0.0/README.md +73 -0
- netsware_sdk-1.0.0/netsware/__init__.py +297 -0
- netsware_sdk-1.0.0/netsware_sdk.egg-info/PKG-INFO +85 -0
- netsware_sdk-1.0.0/netsware_sdk.egg-info/SOURCES.txt +7 -0
- netsware_sdk-1.0.0/netsware_sdk.egg-info/dependency_links.txt +1 -0
- netsware_sdk-1.0.0/netsware_sdk.egg-info/top_level.txt +1 -0
- netsware_sdk-1.0.0/pyproject.toml +21 -0
- netsware_sdk-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netsware-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Netsware SDK — Business Hours + Scheduled Jobs APIs
|
|
5
|
+
Author: Netsware Systems LLP
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://netsware.com
|
|
8
|
+
Project-URL: Documentation, https://netsware.com/dashboard/docs
|
|
9
|
+
Keywords: netsware,business-hours,scheduled-jobs,webhooks,cron
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# netsware-sdk
|
|
14
|
+
|
|
15
|
+
Official Python SDK for the [Netsware](https://netsware.com) API — Business Hours,
|
|
16
|
+
Scheduled Jobs, and Webhooks. Pure standard library, no dependencies.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install netsware-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quickstart
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from netsware import Netsware, verify_webhook
|
|
28
|
+
|
|
29
|
+
client = Netsware("nw_live_xxx")
|
|
30
|
+
|
|
31
|
+
# Is a business open right now?
|
|
32
|
+
status = client.hours.check(timezone="Asia/Kolkata", country="IN")
|
|
33
|
+
print(status["open"])
|
|
34
|
+
|
|
35
|
+
# Create a business-hours schedule
|
|
36
|
+
sched = client.hours.create_schedule(
|
|
37
|
+
name="Mumbai office",
|
|
38
|
+
days=["MON", "TUE", "WED", "THU", "FRI"],
|
|
39
|
+
open_time="09:00",
|
|
40
|
+
close_time="18:00",
|
|
41
|
+
timezone="Asia/Kolkata",
|
|
42
|
+
country="IN",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Schedule a one-time job
|
|
46
|
+
job = client.jobs.schedule(
|
|
47
|
+
name="Send reminder",
|
|
48
|
+
url="https://example.com/webhook",
|
|
49
|
+
run_at="2026-07-01T09:00:00",
|
|
50
|
+
timezone="Asia/Kolkata",
|
|
51
|
+
payload={"user_id": "123"},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Register a webhook (one event per registration)
|
|
55
|
+
hook = client.webhooks.register(
|
|
56
|
+
product="scheduled_jobs",
|
|
57
|
+
event="job.completed",
|
|
58
|
+
url="https://example.com/events",
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Verifying webhook signatures
|
|
63
|
+
|
|
64
|
+
Pass the **raw** request body string for a byte-exact check:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
ok = verify_webhook(
|
|
68
|
+
payload=raw_body, # raw request body (string)
|
|
69
|
+
signature=headers["X-Netsware-Signature"],
|
|
70
|
+
timestamp=headers["X-Netsware-Timestamp"],
|
|
71
|
+
secret="whsec_...",
|
|
72
|
+
)
|
|
73
|
+
if not ok:
|
|
74
|
+
... # reject
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
client = Netsware("nw_live_xxx", base_url="https://app.netsware.com", timeout=30.0)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Full API reference: <https://netsware.com/dashboard/docs>.
|
|
84
|
+
|
|
85
|
+
MIT © Netsware Systems LLP
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# netsware-sdk
|
|
2
|
+
|
|
3
|
+
Official Python SDK for the [Netsware](https://netsware.com) API — Business Hours,
|
|
4
|
+
Scheduled Jobs, and Webhooks. Pure standard library, no dependencies.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install netsware-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quickstart
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from netsware import Netsware, verify_webhook
|
|
16
|
+
|
|
17
|
+
client = Netsware("nw_live_xxx")
|
|
18
|
+
|
|
19
|
+
# Is a business open right now?
|
|
20
|
+
status = client.hours.check(timezone="Asia/Kolkata", country="IN")
|
|
21
|
+
print(status["open"])
|
|
22
|
+
|
|
23
|
+
# Create a business-hours schedule
|
|
24
|
+
sched = client.hours.create_schedule(
|
|
25
|
+
name="Mumbai office",
|
|
26
|
+
days=["MON", "TUE", "WED", "THU", "FRI"],
|
|
27
|
+
open_time="09:00",
|
|
28
|
+
close_time="18:00",
|
|
29
|
+
timezone="Asia/Kolkata",
|
|
30
|
+
country="IN",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Schedule a one-time job
|
|
34
|
+
job = client.jobs.schedule(
|
|
35
|
+
name="Send reminder",
|
|
36
|
+
url="https://example.com/webhook",
|
|
37
|
+
run_at="2026-07-01T09:00:00",
|
|
38
|
+
timezone="Asia/Kolkata",
|
|
39
|
+
payload={"user_id": "123"},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Register a webhook (one event per registration)
|
|
43
|
+
hook = client.webhooks.register(
|
|
44
|
+
product="scheduled_jobs",
|
|
45
|
+
event="job.completed",
|
|
46
|
+
url="https://example.com/events",
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Verifying webhook signatures
|
|
51
|
+
|
|
52
|
+
Pass the **raw** request body string for a byte-exact check:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
ok = verify_webhook(
|
|
56
|
+
payload=raw_body, # raw request body (string)
|
|
57
|
+
signature=headers["X-Netsware-Signature"],
|
|
58
|
+
timestamp=headers["X-Netsware-Timestamp"],
|
|
59
|
+
secret="whsec_...",
|
|
60
|
+
)
|
|
61
|
+
if not ok:
|
|
62
|
+
... # reject
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
client = Netsware("nw_live_xxx", base_url="https://app.netsware.com", timeout=30.0)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Full API reference: <https://netsware.com/dashboard/docs>.
|
|
72
|
+
|
|
73
|
+
MIT © Netsware Systems LLP
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"""Netsware Python SDK — Business Hours + Scheduled Jobs APIs.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
from netsware import Netsware, verify_webhook
|
|
5
|
+
|
|
6
|
+
client = Netsware("nw_live_xxx")
|
|
7
|
+
status = client.hours.check(timezone="Asia/Kolkata", country="IN")
|
|
8
|
+
print(status["open"])
|
|
9
|
+
|
|
10
|
+
sched = client.hours.create_schedule(
|
|
11
|
+
name="Mumbai office",
|
|
12
|
+
days=["MON", "TUE", "WED", "THU", "FRI"],
|
|
13
|
+
open_time="09:00",
|
|
14
|
+
close_time="18:00",
|
|
15
|
+
timezone="Asia/Kolkata",
|
|
16
|
+
country="IN",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
job = client.jobs.schedule(
|
|
20
|
+
name="Send reminder",
|
|
21
|
+
url="https://example.com/webhook",
|
|
22
|
+
run_at="2026-07-01T09:00:00",
|
|
23
|
+
timezone="Asia/Kolkata",
|
|
24
|
+
payload={"user_id": "123"},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
Only the Python standard library is used (urllib) — no third-party dependencies.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import hashlib
|
|
33
|
+
import hmac
|
|
34
|
+
import json
|
|
35
|
+
import time
|
|
36
|
+
import urllib.parse
|
|
37
|
+
import urllib.request
|
|
38
|
+
from typing import Any, List, Optional
|
|
39
|
+
|
|
40
|
+
__all__ = ["Netsware", "NetswareError", "verify_webhook"]
|
|
41
|
+
|
|
42
|
+
DEFAULT_BASE_URL = "https://app.netsware.com"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class NetswareError(Exception):
|
|
46
|
+
def __init__(self, status: int, code: str, message: str):
|
|
47
|
+
super().__init__(f"[{status}] {code}: {message}")
|
|
48
|
+
self.status = status
|
|
49
|
+
self.code = code
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class _Http:
|
|
53
|
+
def __init__(self, api_key: str, base_url: str, timeout: float):
|
|
54
|
+
self._api_key = api_key
|
|
55
|
+
self._base_url = base_url.rstrip("/")
|
|
56
|
+
self._timeout = timeout
|
|
57
|
+
|
|
58
|
+
def request(self, method: str, path: str, query: Optional[dict] = None,
|
|
59
|
+
body: Optional[dict] = None) -> Any:
|
|
60
|
+
url = self._base_url + path
|
|
61
|
+
if query:
|
|
62
|
+
clean = {k: v for k, v in query.items() if v is not None}
|
|
63
|
+
if clean:
|
|
64
|
+
url += "?" + urllib.parse.urlencode(clean)
|
|
65
|
+
if body is not None:
|
|
66
|
+
# Omit None fields entirely — the API treats explicit null and
|
|
67
|
+
# "absent" differently (optional fields reject null).
|
|
68
|
+
body = {k: v for k, v in body.items() if v is not None}
|
|
69
|
+
data = json.dumps(body).encode() if body is not None else None
|
|
70
|
+
req = urllib.request.Request(url, data=data, method=method)
|
|
71
|
+
req.add_header("X-API-Key", self._api_key)
|
|
72
|
+
req.add_header("Content-Type", "application/json")
|
|
73
|
+
req.add_header("User-Agent", "netsware-sdk-python/1.0")
|
|
74
|
+
try:
|
|
75
|
+
with urllib.request.urlopen(req, timeout=self._timeout) as resp:
|
|
76
|
+
raw = resp.read().decode()
|
|
77
|
+
return json.loads(raw) if raw else {}
|
|
78
|
+
except urllib.error.HTTPError as e:
|
|
79
|
+
raw = e.read().decode()
|
|
80
|
+
try:
|
|
81
|
+
payload = json.loads(raw)
|
|
82
|
+
except Exception:
|
|
83
|
+
payload = {}
|
|
84
|
+
raise NetswareError(
|
|
85
|
+
e.code,
|
|
86
|
+
payload.get("error", "request_failed"),
|
|
87
|
+
payload.get("message", f"Request failed with status {e.code}"),
|
|
88
|
+
) from None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _csv(days) -> Optional[str]:
|
|
92
|
+
"""Join a list of weekday codes to the comma string the check query expects."""
|
|
93
|
+
if days is None:
|
|
94
|
+
return None
|
|
95
|
+
if isinstance(days, str):
|
|
96
|
+
return days
|
|
97
|
+
return ",".join(days)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class _Hours:
|
|
101
|
+
def __init__(self, http: _Http):
|
|
102
|
+
self._http = http
|
|
103
|
+
|
|
104
|
+
def check(self, timezone: str, country: str, timestamp: Optional[str] = None,
|
|
105
|
+
open_time: Optional[str] = None, close_time: Optional[str] = None,
|
|
106
|
+
days: Optional[List[str]] = None, region: Optional[str] = None) -> dict:
|
|
107
|
+
"""Check whether a business is open now. ``country`` is required."""
|
|
108
|
+
return self._http.request("GET", "/v1/hours/check", query={
|
|
109
|
+
"timezone": timezone, "country": country, "timestamp": timestamp,
|
|
110
|
+
"open_time": open_time, "close_time": close_time,
|
|
111
|
+
"days": _csv(days), "region": region,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
def create_schedule(self, name: str, days: List[str], open_time: str, close_time: str,
|
|
115
|
+
timezone: Optional[str] = None, country: Optional[str] = None,
|
|
116
|
+
respect_holidays: bool = True, timezones: Optional[list] = None,
|
|
117
|
+
region: Optional[str] = None) -> dict:
|
|
118
|
+
"""Create a schedule. A single ``open_time``/``close_time`` applies to all
|
|
119
|
+
``days`` (list of MON..SUN). Pass ``timezones`` (list) for one per zone."""
|
|
120
|
+
return self._http.request("POST", "/v1/hours/schedules", body={
|
|
121
|
+
"name": name, "timezone": timezone, "timezones": timezones,
|
|
122
|
+
"country_code": country, "region": region,
|
|
123
|
+
"respect_holidays": respect_holidays,
|
|
124
|
+
"days": days, "open_time": open_time, "close_time": close_time,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
def list_schedules(self) -> dict:
|
|
128
|
+
"""List the API key's schedules."""
|
|
129
|
+
return self._http.request("GET", "/v1/hours/schedules")
|
|
130
|
+
|
|
131
|
+
def get_schedule(self, schedule_id: str) -> dict:
|
|
132
|
+
"""Fetch a schedule's full detail."""
|
|
133
|
+
return self._http.request("GET", f"/v1/hours/schedules/{schedule_id}")
|
|
134
|
+
|
|
135
|
+
def check_schedule(self, schedule_id: str) -> dict:
|
|
136
|
+
"""Check a saved schedule's current open/closed status."""
|
|
137
|
+
return self._http.request("GET", f"/v1/hours/schedules/{schedule_id}/check")
|
|
138
|
+
|
|
139
|
+
def update_schedule(self, schedule_id: str, name: str, days: List[str], open_time: str,
|
|
140
|
+
close_time: str, timezone: Optional[str] = None, country: Optional[str] = None,
|
|
141
|
+
respect_holidays: bool = True, region: Optional[str] = None) -> dict:
|
|
142
|
+
"""Update a schedule in place (keeps its id)."""
|
|
143
|
+
return self._http.request("PUT", f"/v1/hours/schedules/{schedule_id}", body={
|
|
144
|
+
"name": name, "timezone": timezone, "country_code": country, "region": region,
|
|
145
|
+
"respect_holidays": respect_holidays,
|
|
146
|
+
"days": days, "open_time": open_time, "close_time": close_time,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
def delete_schedule(self, schedule_id: str, permanent: bool = False) -> dict:
|
|
150
|
+
"""Delete a schedule (soft by default; ``permanent=True`` hard-deletes)."""
|
|
151
|
+
return self._http.request("DELETE", f"/v1/hours/schedules/{schedule_id}",
|
|
152
|
+
query={"permanent": "true" if permanent else None})
|
|
153
|
+
|
|
154
|
+
def holidays(self, country: str, year: int, region: Optional[str] = None,
|
|
155
|
+
type: Optional[str] = None) -> Any:
|
|
156
|
+
"""List public holidays. ``region`` for state-level calendars; ``type`` to filter."""
|
|
157
|
+
return self._http.request("GET", "/v1/hours/holidays",
|
|
158
|
+
query={"country": country, "year": year, "region": region, "type": type})
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class _Jobs:
|
|
162
|
+
def __init__(self, http: _Http):
|
|
163
|
+
self._http = http
|
|
164
|
+
|
|
165
|
+
def schedule(self, url: str, run_at: str, timezone: Optional[str] = None, name: Optional[str] = None,
|
|
166
|
+
payload: Optional[dict] = None, headers: Optional[dict] = None,
|
|
167
|
+
retry: Optional[dict] = None, timeout_seconds: Optional[int] = None,
|
|
168
|
+
success_codes: Optional[list] = None, business_hours_schedule_id: Optional[str] = None,
|
|
169
|
+
timezones: Optional[list] = None) -> dict:
|
|
170
|
+
"""Schedule a one-time job. Pass ``timezones`` (list) for one per zone."""
|
|
171
|
+
return self._http.request("POST", "/v1/jobs", body={
|
|
172
|
+
"type": "once", "name": name, "url": url, "run_at": run_at,
|
|
173
|
+
"timezone": timezone, "timezones": timezones, "payload": payload or {},
|
|
174
|
+
"headers": headers, "retry": retry, "timeout_seconds": timeout_seconds,
|
|
175
|
+
"success_codes": success_codes, "business_hours_schedule_id": business_hours_schedule_id,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
def recurring(self, url: str, cron: str, timezone: Optional[str] = None, name: Optional[str] = None,
|
|
179
|
+
payload: Optional[dict] = None, headers: Optional[dict] = None,
|
|
180
|
+
retry: Optional[dict] = None, business_hours_schedule_id: Optional[str] = None,
|
|
181
|
+
timezones: Optional[list] = None) -> dict:
|
|
182
|
+
"""Schedule a recurring (cron) job. Pass ``timezones`` (list) for one per zone."""
|
|
183
|
+
return self._http.request("POST", "/v1/jobs", body={
|
|
184
|
+
"type": "recurring", "name": name, "url": url, "cron": cron,
|
|
185
|
+
"timezone": timezone, "timezones": timezones, "payload": payload or {},
|
|
186
|
+
"headers": headers, "retry": retry,
|
|
187
|
+
"business_hours_schedule_id": business_hours_schedule_id,
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
def sequence(self, timezone: str, steps: list, name: Optional[str] = None) -> dict:
|
|
191
|
+
"""Create a multi-step sequence job. ``steps`` = list of
|
|
192
|
+
``{"delay", "delay_unit", "url", "payload"}``."""
|
|
193
|
+
return self._http.request("POST", "/v1/jobs", body={
|
|
194
|
+
"type": "sequence", "name": name, "timezone": timezone, "steps": steps,
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
def list(self, status: Optional[str] = None, type: Optional[str] = None,
|
|
198
|
+
search: Optional[str] = None) -> dict:
|
|
199
|
+
return self._http.request("GET", "/v1/jobs",
|
|
200
|
+
query={"status": status, "type": type, "search": search})
|
|
201
|
+
|
|
202
|
+
def get(self, job_id: str) -> dict:
|
|
203
|
+
return self._http.request("GET", f"/v1/jobs/{job_id}")
|
|
204
|
+
|
|
205
|
+
def update(self, job_id: str, **fields) -> dict:
|
|
206
|
+
"""Update a job in place (its ``type`` is immutable). Pass any of: ``name``,
|
|
207
|
+
``url``, ``method``, ``timezone``, ``run_at``, ``cron``, ``payload``,
|
|
208
|
+
``headers``, ``retry``, ``timeout_seconds``, ``success_codes``,
|
|
209
|
+
``business_hours_schedule_id``/``_ids``, ``business_hours_match``."""
|
|
210
|
+
return self._http.request("PUT", f"/v1/jobs/{job_id}", body=fields)
|
|
211
|
+
|
|
212
|
+
def stats(self) -> dict:
|
|
213
|
+
return self._http.request("GET", "/v1/jobs/stats")
|
|
214
|
+
|
|
215
|
+
def logs(self, job_id: str) -> dict:
|
|
216
|
+
return self._http.request("GET", f"/v1/jobs/{job_id}/logs")
|
|
217
|
+
|
|
218
|
+
def cancel(self, job_id: str) -> dict:
|
|
219
|
+
return self._http.request("DELETE", f"/v1/jobs/{job_id}")
|
|
220
|
+
|
|
221
|
+
def pause(self, job_id: str) -> dict:
|
|
222
|
+
return self._http.request("PUT", f"/v1/jobs/{job_id}/pause")
|
|
223
|
+
|
|
224
|
+
def resume(self, job_id: str) -> dict:
|
|
225
|
+
return self._http.request("PUT", f"/v1/jobs/{job_id}/resume")
|
|
226
|
+
|
|
227
|
+
def retry(self, job_id: str) -> dict:
|
|
228
|
+
return self._http.request("POST", f"/v1/jobs/{job_id}/retry")
|
|
229
|
+
|
|
230
|
+
def trigger(self, job_id: str) -> dict:
|
|
231
|
+
return self._http.request("POST", f"/v1/jobs/{job_id}/trigger")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class _Webhooks:
|
|
235
|
+
def __init__(self, http: _Http):
|
|
236
|
+
self._http = http
|
|
237
|
+
|
|
238
|
+
def register(self, product: str, event: str, url: str) -> dict:
|
|
239
|
+
"""Register a webhook. ``product`` = ``scheduled_jobs``|``business_hours``;
|
|
240
|
+
``event`` is a single event name (register again for more). The response
|
|
241
|
+
includes a signing ``secret``, shown once."""
|
|
242
|
+
return self._http.request("POST", "/v1/webhooks",
|
|
243
|
+
body={"product": product, "event": event, "url": url})
|
|
244
|
+
|
|
245
|
+
def list(self) -> dict:
|
|
246
|
+
return self._http.request("GET", "/v1/webhooks")
|
|
247
|
+
|
|
248
|
+
def delete(self, webhook_id: str) -> dict:
|
|
249
|
+
return self._http.request("DELETE", f"/v1/webhooks/{webhook_id}")
|
|
250
|
+
|
|
251
|
+
def test(self, webhook_id: str) -> dict:
|
|
252
|
+
return self._http.request("POST", f"/v1/webhooks/{webhook_id}/test")
|
|
253
|
+
|
|
254
|
+
def deliveries(self, webhook_id: str) -> dict:
|
|
255
|
+
return self._http.request("GET", f"/v1/webhooks/{webhook_id}/deliveries")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class _Usage:
|
|
259
|
+
def __init__(self, http: _Http):
|
|
260
|
+
self._http = http
|
|
261
|
+
|
|
262
|
+
def get(self) -> dict:
|
|
263
|
+
"""Current month's metered usage + plan limits for the account."""
|
|
264
|
+
return self._http.request("GET", "/v1/usage")
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class Netsware:
|
|
268
|
+
def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout: float = 30.0):
|
|
269
|
+
if not api_key:
|
|
270
|
+
raise ValueError("Netsware: an API key is required")
|
|
271
|
+
http = _Http(api_key, base_url, timeout)
|
|
272
|
+
self.hours = _Hours(http)
|
|
273
|
+
self.jobs = _Jobs(http)
|
|
274
|
+
self.webhooks = _Webhooks(http)
|
|
275
|
+
self.usage = _Usage(http)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def verify_webhook(payload, signature: Optional[str], timestamp,
|
|
279
|
+
secret: str, tolerance_seconds: int = 300) -> bool:
|
|
280
|
+
"""Verify a Netsware webhook signature (constant-time + replay window).
|
|
281
|
+
|
|
282
|
+
Prefer passing the RAW request body string as ``payload``; a parsed dict is
|
|
283
|
+
re-serialized and may not reproduce the exact signed bytes (false negative).
|
|
284
|
+
"""
|
|
285
|
+
if not signature or timestamp is None or not secret:
|
|
286
|
+
return False
|
|
287
|
+
try:
|
|
288
|
+
ts = int(timestamp)
|
|
289
|
+
except (TypeError, ValueError):
|
|
290
|
+
return False
|
|
291
|
+
if abs(time.time() - ts) > tolerance_seconds:
|
|
292
|
+
return False
|
|
293
|
+
ts_raw = str(timestamp)
|
|
294
|
+
body = payload if isinstance(payload, str) else json.dumps(payload, separators=(",", ":"))
|
|
295
|
+
expected = hmac.new(secret.encode(), f"{ts_raw}.{body}".encode(), hashlib.sha256).hexdigest()
|
|
296
|
+
provided = signature[7:] if signature.startswith("sha256=") else signature
|
|
297
|
+
return hmac.compare_digest(expected, provided)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netsware-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Netsware SDK — Business Hours + Scheduled Jobs APIs
|
|
5
|
+
Author: Netsware Systems LLP
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://netsware.com
|
|
8
|
+
Project-URL: Documentation, https://netsware.com/dashboard/docs
|
|
9
|
+
Keywords: netsware,business-hours,scheduled-jobs,webhooks,cron
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# netsware-sdk
|
|
14
|
+
|
|
15
|
+
Official Python SDK for the [Netsware](https://netsware.com) API — Business Hours,
|
|
16
|
+
Scheduled Jobs, and Webhooks. Pure standard library, no dependencies.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install netsware-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quickstart
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from netsware import Netsware, verify_webhook
|
|
28
|
+
|
|
29
|
+
client = Netsware("nw_live_xxx")
|
|
30
|
+
|
|
31
|
+
# Is a business open right now?
|
|
32
|
+
status = client.hours.check(timezone="Asia/Kolkata", country="IN")
|
|
33
|
+
print(status["open"])
|
|
34
|
+
|
|
35
|
+
# Create a business-hours schedule
|
|
36
|
+
sched = client.hours.create_schedule(
|
|
37
|
+
name="Mumbai office",
|
|
38
|
+
days=["MON", "TUE", "WED", "THU", "FRI"],
|
|
39
|
+
open_time="09:00",
|
|
40
|
+
close_time="18:00",
|
|
41
|
+
timezone="Asia/Kolkata",
|
|
42
|
+
country="IN",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Schedule a one-time job
|
|
46
|
+
job = client.jobs.schedule(
|
|
47
|
+
name="Send reminder",
|
|
48
|
+
url="https://example.com/webhook",
|
|
49
|
+
run_at="2026-07-01T09:00:00",
|
|
50
|
+
timezone="Asia/Kolkata",
|
|
51
|
+
payload={"user_id": "123"},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# Register a webhook (one event per registration)
|
|
55
|
+
hook = client.webhooks.register(
|
|
56
|
+
product="scheduled_jobs",
|
|
57
|
+
event="job.completed",
|
|
58
|
+
url="https://example.com/events",
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Verifying webhook signatures
|
|
63
|
+
|
|
64
|
+
Pass the **raw** request body string for a byte-exact check:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
ok = verify_webhook(
|
|
68
|
+
payload=raw_body, # raw request body (string)
|
|
69
|
+
signature=headers["X-Netsware-Signature"],
|
|
70
|
+
timestamp=headers["X-Netsware-Timestamp"],
|
|
71
|
+
secret="whsec_...",
|
|
72
|
+
)
|
|
73
|
+
if not ok:
|
|
74
|
+
... # reject
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
client = Netsware("nw_live_xxx", base_url="https://app.netsware.com", timeout=30.0)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Full API reference: <https://netsware.com/dashboard/docs>.
|
|
84
|
+
|
|
85
|
+
MIT © Netsware Systems LLP
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
netsware
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "netsware-sdk"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Official Netsware SDK — Business Hours + Scheduled Jobs APIs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Netsware Systems LLP" }]
|
|
13
|
+
keywords = ["netsware", "business-hours", "scheduled-jobs", "webhooks", "cron"]
|
|
14
|
+
dependencies = []
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://netsware.com"
|
|
18
|
+
Documentation = "https://netsware.com/dashboard/docs"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
include = ["netsware*"]
|