zoytar 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.
- zoytar-1.0.0/PKG-INFO +54 -0
- zoytar-1.0.0/README.md +46 -0
- zoytar-1.0.0/pyproject.toml +12 -0
- zoytar-1.0.0/setup.cfg +4 -0
- zoytar-1.0.0/zoytar/__init__.py +187 -0
- zoytar-1.0.0/zoytar.egg-info/PKG-INFO +54 -0
- zoytar-1.0.0/zoytar.egg-info/SOURCES.txt +7 -0
- zoytar-1.0.0/zoytar.egg-info/dependency_links.txt +1 -0
- zoytar-1.0.0/zoytar.egg-info/top_level.txt +1 -0
zoytar-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zoytar
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: zoytar API client
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# zoytar SDKs
|
|
10
|
+
|
|
11
|
+
Generated by tools/sdk-gen.php from the zoytar API description. Do not edit by hand.
|
|
12
|
+
|
|
13
|
+
The description is `openapi.json`; the reference is /developers/api on your academy.
|
|
14
|
+
|
|
15
|
+
## Resources
|
|
16
|
+
|
|
17
|
+
- `learners` / `learners` — Your people, by your own id — `list`, `all`, `write`
|
|
18
|
+
- `groups` / `groups` — Groups of learners — `list`, `all`, `write`
|
|
19
|
+
- `organisations` / `organisations` — Your customers' organisations, each in one academy — `list`, `all`, `write`
|
|
20
|
+
- `enrolments` / `enrolments` — What a learner or a group is given — `list`, `all`, `write`
|
|
21
|
+
- `playerSessions` / `player_sessions` — A launch address for the embedded player: once, for five minutes, `write`
|
|
22
|
+
- `courses` / `courses` — Your courses; with id, the outline — `list`, `all`
|
|
23
|
+
- `classes` / `classes` — Your live classes — `list`, `all`
|
|
24
|
+
- `paths` / `paths` — Your learning paths, with their steps — `list`, `all`
|
|
25
|
+
- `tests` / `tests` — Your tests, with their rules — `list`, `all`
|
|
26
|
+
- `progress` / `progress` — How far each learner is, and the certificate — `list`, `all`
|
|
27
|
+
- `results` / `results` — Test results — `list`, `all`
|
|
28
|
+
|
|
29
|
+
Every write sends an Idempotency-Key (made for you, or pass your own); a 429 is waited out and tried again with the same key. A refusal raises `ZoytarError` with `status`, `error` and `message`.
|
|
30
|
+
|
|
31
|
+
## JavaScript and Node.js
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { zoytar } from '@zoytar/sdk';
|
|
35
|
+
const z = new zoytar({ token: process.env.ZOYTAR_TOKEN, baseUrl: 'https://your-academy.zoytar.com/api/v1' });
|
|
36
|
+
await z.learners.write({ external_id: 'u-42', email: 'asha@example.com', name: 'Asha' });
|
|
37
|
+
for await (const l of z.learners.all()) console.log(l.external_id);
|
|
38
|
+
const { url } = await z.playerSessions.write({ learner: 'u-42', kind: 'course', item: 7 });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
import { ZoytarPlayer } from '@zoytar/sdk/react';
|
|
43
|
+
<ZoytarPlayer src={url} />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Python
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from zoytar import zoytar
|
|
50
|
+
z = zoytar(token, 'https://your-academy.zoytar.com/api/v1')
|
|
51
|
+
z.learners.write({'external_id': 'u-42', 'email': 'asha@example.com'})
|
|
52
|
+
for l in z.learners.all():
|
|
53
|
+
print(l['external_id'])
|
|
54
|
+
```
|
zoytar-1.0.0/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# zoytar SDKs
|
|
2
|
+
|
|
3
|
+
Generated by tools/sdk-gen.php from the zoytar API description. Do not edit by hand.
|
|
4
|
+
|
|
5
|
+
The description is `openapi.json`; the reference is /developers/api on your academy.
|
|
6
|
+
|
|
7
|
+
## Resources
|
|
8
|
+
|
|
9
|
+
- `learners` / `learners` — Your people, by your own id — `list`, `all`, `write`
|
|
10
|
+
- `groups` / `groups` — Groups of learners — `list`, `all`, `write`
|
|
11
|
+
- `organisations` / `organisations` — Your customers' organisations, each in one academy — `list`, `all`, `write`
|
|
12
|
+
- `enrolments` / `enrolments` — What a learner or a group is given — `list`, `all`, `write`
|
|
13
|
+
- `playerSessions` / `player_sessions` — A launch address for the embedded player: once, for five minutes, `write`
|
|
14
|
+
- `courses` / `courses` — Your courses; with id, the outline — `list`, `all`
|
|
15
|
+
- `classes` / `classes` — Your live classes — `list`, `all`
|
|
16
|
+
- `paths` / `paths` — Your learning paths, with their steps — `list`, `all`
|
|
17
|
+
- `tests` / `tests` — Your tests, with their rules — `list`, `all`
|
|
18
|
+
- `progress` / `progress` — How far each learner is, and the certificate — `list`, `all`
|
|
19
|
+
- `results` / `results` — Test results — `list`, `all`
|
|
20
|
+
|
|
21
|
+
Every write sends an Idempotency-Key (made for you, or pass your own); a 429 is waited out and tried again with the same key. A refusal raises `ZoytarError` with `status`, `error` and `message`.
|
|
22
|
+
|
|
23
|
+
## JavaScript and Node.js
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { zoytar } from '@zoytar/sdk';
|
|
27
|
+
const z = new zoytar({ token: process.env.ZOYTAR_TOKEN, baseUrl: 'https://your-academy.zoytar.com/api/v1' });
|
|
28
|
+
await z.learners.write({ external_id: 'u-42', email: 'asha@example.com', name: 'Asha' });
|
|
29
|
+
for await (const l of z.learners.all()) console.log(l.external_id);
|
|
30
|
+
const { url } = await z.playerSessions.write({ learner: 'u-42', kind: 'course', item: 7 });
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```jsx
|
|
34
|
+
import { ZoytarPlayer } from '@zoytar/sdk/react';
|
|
35
|
+
<ZoytarPlayer src={url} />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Python
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from zoytar import zoytar
|
|
42
|
+
z = zoytar(token, 'https://your-academy.zoytar.com/api/v1')
|
|
43
|
+
z.learners.write({'external_id': 'u-42', 'email': 'asha@example.com'})
|
|
44
|
+
for l in z.learners.all():
|
|
45
|
+
print(l['external_id'])
|
|
46
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Generated by tools/sdk-gen.php from the zoytar API description. Do not edit by hand.
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=61"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "zoytar"
|
|
8
|
+
version = "1.0.0"
|
|
9
|
+
description = "zoytar API client"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
license = { text = "MIT" }
|
zoytar-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Generated by tools/sdk-gen.php from the zoytar API description. Do not edit by hand.
|
|
2
|
+
"""zoytar API client. Standard library only; Python 3.8 and later."""
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import json
|
|
7
|
+
import time
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.parse
|
|
10
|
+
import urllib.request
|
|
11
|
+
import uuid
|
|
12
|
+
from typing import Any, Dict, Iterator, List, Optional, Union
|
|
13
|
+
|
|
14
|
+
API_VERSION = "1"
|
|
15
|
+
__version__ = "1.0.0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ZoytarError(Exception):
|
|
19
|
+
def __init__(self, status: int, error: str, message: str, retry_after: Optional[int] = None):
|
|
20
|
+
super().__init__(message)
|
|
21
|
+
self.status = status
|
|
22
|
+
self.error = error
|
|
23
|
+
self.message = message
|
|
24
|
+
self.retry_after = retry_after
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _Resource:
|
|
28
|
+
def __init__(self, client: "zoytar", name: str):
|
|
29
|
+
self._c = client
|
|
30
|
+
self._name = name
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class _Reads:
|
|
34
|
+
def list(self, **params: Any) -> Dict[str, Any]:
|
|
35
|
+
return self._c.request("GET", "/" + self._name, query=params)
|
|
36
|
+
|
|
37
|
+
def all(self, **params: Any) -> Iterator[Dict[str, Any]]:
|
|
38
|
+
page = 1
|
|
39
|
+
while True:
|
|
40
|
+
r = self.list(page=page, **params)
|
|
41
|
+
yield from r.get("data", [])
|
|
42
|
+
if not r.get("has_more"):
|
|
43
|
+
return
|
|
44
|
+
page += 1
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _Writes:
|
|
48
|
+
def write(self, item: Union[Dict[str, Any], List[Dict[str, Any]]], idempotency_key: Optional[str] = None) -> Dict[str, Any]:
|
|
49
|
+
body = {self._name: item} if isinstance(item, list) else item
|
|
50
|
+
return self._c.request("POST", "/" + self._name, body=body, idempotency_key=idempotency_key)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Learners(_Reads, _Writes, _Resource):
|
|
54
|
+
"""Your people, by your own id.
|
|
55
|
+
Filters: external_id (str), email (str), page (int).
|
|
56
|
+
Fields: external_id (str, required), email (str), name (str), department (str), active (bool), invite (bool).
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Groups(_Reads, _Writes, _Resource):
|
|
61
|
+
"""Groups of learners.
|
|
62
|
+
Filters: external_id (str), page (int).
|
|
63
|
+
Fields: external_id (str, required), name (str), members (List[str]), add (List[str]), remove (List[str]).
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Organisations(_Reads, _Writes, _Resource):
|
|
68
|
+
"""Your customers' organisations, each in one academy.
|
|
69
|
+
Filters: external_id (str), page (int).
|
|
70
|
+
Fields: external_id (str, required), academy (str), name (str), seat_cap (int), add (List[str]), admins (List[str]), remove (List[str]).
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class Enrolments(_Reads, _Writes, _Resource):
|
|
75
|
+
"""What a learner or a group is given.
|
|
76
|
+
Filters: learner (str), kind (str), item (int), page (int).
|
|
77
|
+
Fields: learner (str), group (str), kind (str, required), item (int, required), due_on (str), revoke (bool).
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class PlayerSessions(_Writes, _Resource):
|
|
82
|
+
"""A launch address for the embedded player: once, for five minutes.
|
|
83
|
+
Fields: learner (str, required), kind (str, required), item (int, required), lesson (str).
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Courses(_Reads, _Resource):
|
|
88
|
+
"""Your courses; with id, the outline.
|
|
89
|
+
Filters: id (int), page (int).
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Classes(_Reads, _Resource):
|
|
94
|
+
"""Your live classes.
|
|
95
|
+
Filters: id (int), page (int).
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Paths(_Reads, _Resource):
|
|
100
|
+
"""Your learning paths, with their steps.
|
|
101
|
+
Filters: id (int), page (int).
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Tests(_Reads, _Resource):
|
|
106
|
+
"""Your tests, with their rules.
|
|
107
|
+
Filters: id (int), page (int).
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class Progress(_Reads, _Resource):
|
|
112
|
+
"""How far each learner is, and the certificate.
|
|
113
|
+
Filters: learner (str), item (int), page (int).
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class Results(_Reads, _Resource):
|
|
118
|
+
"""Test results.
|
|
119
|
+
Filters: learner (str), item (int), page (int).
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class zoytar:
|
|
124
|
+
def __init__(self, token: str, base_url: str, max_retries: int = 2, timeout: float = 60):
|
|
125
|
+
if not token:
|
|
126
|
+
raise ValueError("token is required")
|
|
127
|
+
if not base_url:
|
|
128
|
+
raise ValueError("base_url is required, like https://your-academy.zoytar.com/api/v1")
|
|
129
|
+
self.token = token
|
|
130
|
+
self.base_url = base_url.rstrip("/")
|
|
131
|
+
self.max_retries = max_retries
|
|
132
|
+
self.timeout = timeout
|
|
133
|
+
self.learners = Learners(self, "learners")
|
|
134
|
+
self.groups = Groups(self, "groups")
|
|
135
|
+
self.organisations = Organisations(self, "organisations")
|
|
136
|
+
self.enrolments = Enrolments(self, "enrolments")
|
|
137
|
+
self.player_sessions = PlayerSessions(self, "player-sessions")
|
|
138
|
+
self.courses = Courses(self, "courses")
|
|
139
|
+
self.classes = Classes(self, "classes")
|
|
140
|
+
self.paths = Paths(self, "paths")
|
|
141
|
+
self.tests = Tests(self, "tests")
|
|
142
|
+
self.progress = Progress(self, "progress")
|
|
143
|
+
self.results = Results(self, "results")
|
|
144
|
+
|
|
145
|
+
def request(self, method: str, path: str, query: Optional[Dict[str, Any]] = None, body: Any = None, idempotency_key: Optional[str] = None) -> Dict[str, Any]:
|
|
146
|
+
url = self.base_url + path
|
|
147
|
+
q = {k: v for k, v in (query or {}).items() if v is not None}
|
|
148
|
+
if q:
|
|
149
|
+
url += "?" + urllib.parse.urlencode(q)
|
|
150
|
+
headers = {"Authorization": "Bearer " + self.token, "Accept": "application/json"}
|
|
151
|
+
data = None
|
|
152
|
+
if body is not None:
|
|
153
|
+
data = json.dumps(body).encode("utf-8")
|
|
154
|
+
headers["Content-Type"] = "application/json"
|
|
155
|
+
headers["Idempotency-Key"] = idempotency_key or str(uuid.uuid4())
|
|
156
|
+
attempt = 0
|
|
157
|
+
while True:
|
|
158
|
+
req = urllib.request.Request(url, data=data, headers=headers, method=method)
|
|
159
|
+
try:
|
|
160
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as res:
|
|
161
|
+
return json.loads(res.read() or b"{}")
|
|
162
|
+
except urllib.error.HTTPError as e:
|
|
163
|
+
try:
|
|
164
|
+
payload = json.loads(e.read() or b"{}")
|
|
165
|
+
except ValueError:
|
|
166
|
+
payload = {}
|
|
167
|
+
wait = int(e.headers.get("Retry-After") or payload.get("retry_after") or 0)
|
|
168
|
+
# the same Idempotency-Key goes again, so a retried write is never done twice
|
|
169
|
+
if e.code == 429 and attempt < self.max_retries:
|
|
170
|
+
attempt += 1
|
|
171
|
+
time.sleep(max(1, wait))
|
|
172
|
+
continue
|
|
173
|
+
raise ZoytarError(e.code, payload.get("error", "http_%d" % e.code), payload.get("message", str(e)), wait or None)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def verify_webhook(secret: str, signature_header: str, raw_body: Union[str, bytes], tolerance_seconds: int = 300) -> bool:
|
|
177
|
+
"""Check X-Zoytar-Signature ("t=<seconds>,v1=<hex HMAC-SHA256 of t.body>") against the raw body."""
|
|
178
|
+
parts = dict(p.split("=", 1) for p in (signature_header or "").split(",") if "=" in p)
|
|
179
|
+
try:
|
|
180
|
+
t = int(parts.get("t", "0"))
|
|
181
|
+
except ValueError:
|
|
182
|
+
return False
|
|
183
|
+
if not t or "v1" not in parts or abs(time.time() - t) > tolerance_seconds:
|
|
184
|
+
return False
|
|
185
|
+
body = raw_body.encode("utf-8") if isinstance(raw_body, str) else raw_body
|
|
186
|
+
want = hmac.new(secret.encode("utf-8"), str(t).encode("ascii") + b"." + body, hashlib.sha256).hexdigest()
|
|
187
|
+
return hmac.compare_digest(want, parts["v1"])
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zoytar
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: zoytar API client
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# zoytar SDKs
|
|
10
|
+
|
|
11
|
+
Generated by tools/sdk-gen.php from the zoytar API description. Do not edit by hand.
|
|
12
|
+
|
|
13
|
+
The description is `openapi.json`; the reference is /developers/api on your academy.
|
|
14
|
+
|
|
15
|
+
## Resources
|
|
16
|
+
|
|
17
|
+
- `learners` / `learners` — Your people, by your own id — `list`, `all`, `write`
|
|
18
|
+
- `groups` / `groups` — Groups of learners — `list`, `all`, `write`
|
|
19
|
+
- `organisations` / `organisations` — Your customers' organisations, each in one academy — `list`, `all`, `write`
|
|
20
|
+
- `enrolments` / `enrolments` — What a learner or a group is given — `list`, `all`, `write`
|
|
21
|
+
- `playerSessions` / `player_sessions` — A launch address for the embedded player: once, for five minutes, `write`
|
|
22
|
+
- `courses` / `courses` — Your courses; with id, the outline — `list`, `all`
|
|
23
|
+
- `classes` / `classes` — Your live classes — `list`, `all`
|
|
24
|
+
- `paths` / `paths` — Your learning paths, with their steps — `list`, `all`
|
|
25
|
+
- `tests` / `tests` — Your tests, with their rules — `list`, `all`
|
|
26
|
+
- `progress` / `progress` — How far each learner is, and the certificate — `list`, `all`
|
|
27
|
+
- `results` / `results` — Test results — `list`, `all`
|
|
28
|
+
|
|
29
|
+
Every write sends an Idempotency-Key (made for you, or pass your own); a 429 is waited out and tried again with the same key. A refusal raises `ZoytarError` with `status`, `error` and `message`.
|
|
30
|
+
|
|
31
|
+
## JavaScript and Node.js
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { zoytar } from '@zoytar/sdk';
|
|
35
|
+
const z = new zoytar({ token: process.env.ZOYTAR_TOKEN, baseUrl: 'https://your-academy.zoytar.com/api/v1' });
|
|
36
|
+
await z.learners.write({ external_id: 'u-42', email: 'asha@example.com', name: 'Asha' });
|
|
37
|
+
for await (const l of z.learners.all()) console.log(l.external_id);
|
|
38
|
+
const { url } = await z.playerSessions.write({ learner: 'u-42', kind: 'course', item: 7 });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
import { ZoytarPlayer } from '@zoytar/sdk/react';
|
|
43
|
+
<ZoytarPlayer src={url} />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Python
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from zoytar import zoytar
|
|
50
|
+
z = zoytar(token, 'https://your-academy.zoytar.com/api/v1')
|
|
51
|
+
z.learners.write({'external_id': 'u-42', 'email': 'asha@example.com'})
|
|
52
|
+
for l in z.learners.all():
|
|
53
|
+
print(l['external_id'])
|
|
54
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
zoytar
|