-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathuser.py
More file actions
40 lines (34 loc) · 1.29 KB
/
user.py
File metadata and controls
40 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations
from ..models.user import User, UserUpdateCurrentOptions
from ..utils import valid_string_id
from ._base import _Service
class Users(_Service):
def read(self, user_id: str) -> User:
if not valid_string_id(user_id):
raise ValueError("invalid user id")
r = self.t.request("GET", f"/api/v2/users/{user_id}")
d = r.json()["data"]
attr = d.get("attributes", {}) or {}
user_data = dict(attr)
user_data["id"] = d.get("id")
return User(**user_data)
def read_current(self) -> User:
r = self.t.request("GET", "/api/v2/account/details")
d = r.json()["data"]
attr = d.get("attributes", {}) or {}
user_data = dict(attr)
user_data["id"] = d.get("id")
return User(**user_data)
def update_current(self, options: UserUpdateCurrentOptions) -> User:
body = {
"data": {
"type": "users",
"attributes": options.model_dump(exclude_none=True),
}
}
r = self.t.request("PATCH", "/api/v2/account/update", json_body=body)
d = r.json()["data"]
attr = d.get("attributes", {}) or {}
user_data = dict(attr)
user_data["id"] = d.get("id")
return User(**user_data)