sendclap 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sendclap
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Official Sendclap client: license key checks for your app and the creator REST API
5
5
  Project-URL: Homepage, https://sendclap.com
6
6
  Project-URL: Documentation, https://sendclap.com/docs
@@ -32,7 +32,7 @@ def licensed(key: str, cache: dict) -> bool:
32
32
  return time.time() - cache.get("validated_at", 0) < 7 * 86400
33
33
  if r.valid:
34
34
  cache["validated_at"] = time.time() # persist cache to disk yourself
35
- return r.valid # status "invalid", "disabled" or "not_activated": lock the app
35
+ return r.valid # status "not_found", "disabled" or "not_activated": lock the app
36
36
  ```
37
37
 
38
38
  On first run, activate the device and remember the instance id:
@@ -46,7 +46,7 @@ except DisabledLicenseError: ... # the payment was refunded or disputed
46
46
  except ActivationLimitError as e: print(f"Used on {e.license.activations}/{e.license.max_activations} devices")
47
47
  ```
48
48
 
49
- `deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"invalid"` (unknown key) or `"disabled"` (refunded or disputed), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "invalid" and show "this license was refunded" for `"disabled"`.
49
+ `deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
50
50
 
51
51
  **Instance name:** `instance_name()` is the machine's hostname. It is sent to Sendclap and shown to the creator, and two machines with the same hostname share one activation. If that matters, pass your own stable id instead (for example a `uuid4()` saved on first run). The instance id Sendclap returns is the name you send.
52
52
 
@@ -68,7 +68,7 @@ for p in api.all_payments(status="paid"): # a generator that follows `next` acr
68
68
  print(p["amount"], p["email"])
69
69
  ```
70
70
 
71
- Lists (`list_payments`, `list_members`, `list_licenses`, `list_disputes`) return a `Page` with `data`, `has_more` and `next`, newest first; `limit` is at most 500 and `after` is the previous page's `next`. `all_payments`, `all_members`, `all_licenses` and `all_disputes` take the same filters and yield every item.
71
+ Lists (`list_payments`, `list_members`, `list_licenses`, `list_disputes`) return a `Page` with `data`, `has_more` and `next`, newest first; `limit` defaults to 50 and is at most 500 and `after` is the previous page's `next`. `all_payments`, `all_members`, `all_licenses` and `all_disputes` take the same filters and yield every item.
72
72
 
73
73
  Methods: `create_checkout` and `get_checkout` (both return the checkout `url`), `me`, `get_payment`, `list_products`, `list_memberships`, the list and `all_*` methods above, and `get_creator` (public, works with `ApiClient()` and no key). Items are plain dicts with the API's JSON fields, typed with `TypedDict`.
74
74
 
@@ -19,7 +19,7 @@ def licensed(key: str, cache: dict) -> bool:
19
19
  return time.time() - cache.get("validated_at", 0) < 7 * 86400
20
20
  if r.valid:
21
21
  cache["validated_at"] = time.time() # persist cache to disk yourself
22
- return r.valid # status "invalid", "disabled" or "not_activated": lock the app
22
+ return r.valid # status "not_found", "disabled" or "not_activated": lock the app
23
23
  ```
24
24
 
25
25
  On first run, activate the device and remember the instance id:
@@ -33,7 +33,7 @@ except DisabledLicenseError: ... # the payment was refunded or disputed
33
33
  except ActivationLimitError as e: print(f"Used on {e.license.activations}/{e.license.max_activations} devices")
34
34
  ```
35
35
 
36
- `deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"invalid"` (unknown key) or `"disabled"` (refunded or disputed), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "invalid" and show "this license was refunded" for `"disabled"`.
36
+ `deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
37
37
 
38
38
  **Instance name:** `instance_name()` is the machine's hostname. It is sent to Sendclap and shown to the creator, and two machines with the same hostname share one activation. If that matters, pass your own stable id instead (for example a `uuid4()` saved on first run). The instance id Sendclap returns is the name you send.
39
39
 
@@ -55,7 +55,7 @@ for p in api.all_payments(status="paid"): # a generator that follows `next` acr
55
55
  print(p["amount"], p["email"])
56
56
  ```
57
57
 
58
- Lists (`list_payments`, `list_members`, `list_licenses`, `list_disputes`) return a `Page` with `data`, `has_more` and `next`, newest first; `limit` is at most 500 and `after` is the previous page's `next`. `all_payments`, `all_members`, `all_licenses` and `all_disputes` take the same filters and yield every item.
58
+ Lists (`list_payments`, `list_members`, `list_licenses`, `list_disputes`) return a `Page` with `data`, `has_more` and `next`, newest first; `limit` defaults to 50 and is at most 500 and `after` is the previous page's `next`. `all_payments`, `all_members`, `all_licenses` and `all_disputes` take the same filters and yield every item.
59
59
 
60
60
  Methods: `create_checkout` and `get_checkout` (both return the checkout `url`), `me`, `get_payment`, `list_products`, `list_memberships`, the list and `all_*` methods above, and `get_creator` (public, works with `ApiClient()` and no key). Items are plain dicts with the API's JSON fields, typed with `TypedDict`.
61
61
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sendclap"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Official Sendclap client: license key checks for your app and the creator REST API"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -9,7 +9,7 @@ import urllib.request
9
9
  from dataclasses import dataclass
10
10
  from typing import Any, Callable, Dict, Generic, Iterator, List, Optional, TypedDict, TypeVar
11
11
 
12
- __version__ = "0.2.0"
12
+ __version__ = "0.3.0"
13
13
  DEFAULT_BASE_URL = "https://sendclap.com"
14
14
  USER_AGENT = f"sendclap-python/{__version__}"
15
15
 
@@ -93,7 +93,7 @@ class ActivateResult:
93
93
  @dataclass(frozen=True)
94
94
  class ValidateResult:
95
95
  valid: bool
96
- status: str # "active", "not_activated", "invalid" (unknown key) or "disabled" (refunded or disputed)
96
+ status: str # "active", "not_activated", "disabled" (refunded or disputed) or "not_found" (unknown key)
97
97
  license: Optional[LicenseInfo] = None
98
98
  product: Optional[ProductRef] = None
99
99
 
@@ -115,6 +115,7 @@ class Checkout(TypedDict):
115
115
  method: str
116
116
  email: Optional[str]
117
117
  url: str # where to send the customer to pay
118
+ paid_at: Optional[str] # ISO 8601 time it was paid, None while unpaid
118
119
 
119
120
 
120
121
  T = TypeVar("T")
@@ -325,16 +326,11 @@ class LicenseClient:
325
326
  return ActivateResult(instance_id=d["instance_id"], license=_license(d), product=_product(d))
326
327
 
327
328
  def validate(self, license_key: str, instance_id: Optional[str] = None) -> ValidateResult:
328
- """Never raises for a bad key: returns status "invalid" or "disabled". Raises NetworkError when offline."""
329
- try:
330
- d = self._post("validate", license_key, instance_id)
331
- except InvalidLicenseError:
332
- return ValidateResult(valid=False, status="invalid")
333
- except DisabledLicenseError:
334
- return ValidateResult(valid=False, status="disabled")
335
- valid = d.get("valid") is True
336
- return ValidateResult(valid=valid, status="active" if valid else "not_activated",
337
- license=_license(d), product=_product(d))
329
+ """Never raises for a bad key: returns status "not_found" or "disabled". Raises NetworkError when offline."""
330
+ d = self._post("validate", license_key, instance_id)
331
+ known = "license" in d
332
+ return ValidateResult(valid=d.get("valid") is True, status=d["status"],
333
+ license=_license(d) if known else None, product=_product(d) if known else None)
338
334
 
339
335
  def deactivate(self, license_key: str, instance_id: str) -> DeactivateResult:
340
336
  d = self._post("deactivate", license_key, instance_id)
@@ -378,7 +374,7 @@ class ApiClient:
378
374
  d = self._http.request("GET", path, query=query)
379
375
  return Page(data=d["data"], has_more=d["has_more"], next=d["next"])
380
376
 
381
- # Lists are pages: `limit` is at most 500, `after` is the previous page's `next`. The all_* generators follow `next`.
377
+ # Lists are pages: `limit` defaults to 50 and is at most 500, `after` is the previous page's `next`. The all_* generators follow `next`.
382
378
  def list_payments(self, status: Optional[str] = None, type: Optional[str] = None, email: Optional[str] = None,
383
379
  limit: Optional[int] = None, after: Optional[int] = None) -> Page[Payment]:
384
380
  return self._page("/payments", {"status": status, "type": type, "email": email, "limit": limit, "after": after})
@@ -17,7 +17,7 @@ from sendclap import ( # noqa: E402
17
17
  LICENSE = {"key": "GOOD", "activations": 1, "max_activations": 3}
18
18
  PRODUCT = {"id": 1, "name": "Pro"}
19
19
  CHECKOUT = {"id": "0xabc", "status": "pending", "type": "product", "amount": 29, "currency": "usd",
20
- "method": "card", "email": "buyer@example.com", "url": "http://x/checkout/0xabc"}
20
+ "method": "card", "email": "buyer@example.com", "url": "http://x/checkout/0xabc", "paid_at": None}
21
21
  PAYMENTS = [{"id": 3, "status": "paid"}, {"id": 2, "status": "paid"}, {"id": 1, "status": "paid"}]
22
22
  SEEN = [] # (method, path, headers, body) of every request
23
23
 
@@ -42,22 +42,27 @@ class Mock(BaseHTTPRequestHandler):
42
42
  p = url.path
43
43
  if p.startswith("/api/v1/licenses/"):
44
44
  action, key, inst = p.rsplit("/", 1)[1], body.get("license_key"), body.get("instance_id")
45
- if key == "REFUNDED":
46
- return self.reply(403, {"valid": False, "error": "this license key is disabled", "code": "license_disabled"})
47
- if key != "GOOD" and key != "FULL":
48
- return self.reply(404, {"valid": False, "error": "license key not found", "code": "license_not_found"})
49
45
  if action == "validate":
50
- return self.reply(200, {"valid": inst in (None, "dev-1"), "license": LICENSE, "product": PRODUCT})
46
+ if key == "REFUNDED":
47
+ return self.reply(200, {"valid": False, "status": "disabled"})
48
+ if key not in ("GOOD", "FULL"):
49
+ return self.reply(200, {"valid": False, "status": "not_found"})
50
+ ok = inst in (None, "dev-1")
51
+ return self.reply(200, {"valid": ok, "status": "active" if ok else "not_activated",
52
+ "license": LICENSE, "product": PRODUCT})
53
+ if key == "REFUNDED":
54
+ return self.reply(403, {"error": "this license key is disabled", "code": "license_disabled"})
55
+ if key not in ("GOOD", "FULL"):
56
+ return self.reply(404, {"error": "license key not found", "code": "license_not_found"})
51
57
  if not inst:
52
58
  return self.reply(400, {"error": "instance_id is required", "code": "bad_request"})
53
59
  if action == "activate" and key == "FULL":
54
- return self.reply(409, {"activated": False, "error": "activation limit reached", "code": "activation_limit",
60
+ return self.reply(409, {"error": "activation limit reached", "code": "activation_limit",
55
61
  "license": {"key": "FULL", "activations": 3, "max_activations": 3}, "product": PRODUCT})
56
62
  if action == "activate":
57
63
  return self.reply(200, {"activated": True, "instance_id": inst, "license": LICENSE, "product": PRODUCT})
58
64
  if inst != "dev-1":
59
- return self.reply(404, {"deactivated": False, "error": "that instance is not activated",
60
- "code": "instance_not_found", "license": LICENSE, "product": PRODUCT})
65
+ return self.reply(404, {"error": "that instance is not activated", "code": "instance_not_found"})
61
66
  return self.reply(200, {"deactivated": True, "license": dict(LICENSE, activations=0), "product": PRODUCT})
62
67
  if p == "/api/v1/creators/demo":
63
68
  return self.reply(200, {"handle": "demo", "name": "Ada Builds"})
@@ -67,6 +72,8 @@ class Mock(BaseHTTPRequestHandler):
67
72
  return self.reply(201, CHECKOUT)
68
73
  if p == "/api/v1/checkouts/0xabc":
69
74
  return self.reply(200, CHECKOUT)
75
+ if p == "/api/v1/checkouts/0xpaid":
76
+ return self.reply(200, dict(CHECKOUT, status="paid", paid_at="2026-11-14T10:00:00.000Z"))
70
77
  if p == "/api/v1/payments": # two per page, newest first, cursor = the last id on the page
71
78
  after = int(parse_qs(url.query).get("after", ["1000"])[0])
72
79
  rows = [r for r in PAYMENTS if r["id"] < after]
@@ -111,7 +118,7 @@ class SendclapTest(unittest.TestCase):
111
118
  method, path, headers, body = SEEN[-1]
112
119
  self.assertEqual((method, path), ("POST", "/api/v1/licenses/activate"))
113
120
  self.assertEqual(body, {"license_key": "GOOD", "instance_id": "dev-1"})
114
- self.assertEqual(headers["User-Agent"], "sendclap-python/0.2.0")
121
+ self.assertEqual(headers["User-Agent"], "sendclap-python/0.3.0")
115
122
  self.assertEqual(headers["Content-Type"], "application/json")
116
123
  self.assertNotIn("Authorization", headers)
117
124
 
@@ -149,7 +156,7 @@ class SendclapTest(unittest.TestCase):
149
156
  r = self.lic.validate("GOOD", "other")
150
157
  self.assertEqual((r.valid, r.status, r.license.key), (False, "not_activated", "GOOD"))
151
158
  r = self.lic.validate("BAD", "dev-1")
152
- self.assertEqual((r.valid, r.status, r.license, r.product), (False, "invalid", None, None))
159
+ self.assertEqual((r.valid, r.status, r.license, r.product), (False, "not_found", None, None))
153
160
  r = self.lic.validate("REFUNDED", "dev-1")
154
161
  self.assertEqual((r.valid, r.status, r.license, r.product), (False, "disabled", None, None))
155
162
 
@@ -187,6 +194,8 @@ class SendclapTest(unittest.TestCase):
187
194
  self.assertEqual(headers["Authorization"], "Bearer sc_test")
188
195
  g = self.api.get_checkout("0xabc")
189
196
  self.assertEqual((g["status"], g["url"]), ("pending", "http://x/checkout/0xabc"))
197
+ self.assertIsNone(g["paid_at"])
198
+ self.assertEqual(self.api.get_checkout("0xpaid")["paid_at"], "2026-11-14T10:00:00.000Z")
190
199
 
191
200
  def test_payments_page(self):
192
201
  page = self.api.list_payments(status="paid", limit=2)
File without changes
File without changes