magic-campus-cli 0.1.0__py3-none-any.whl

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.
Files changed (53) hide show
  1. magic_campus_cli-0.1.0.dist-info/METADATA +51 -0
  2. magic_campus_cli-0.1.0.dist-info/RECORD +53 -0
  3. magic_campus_cli-0.1.0.dist-info/WHEEL +5 -0
  4. magic_campus_cli-0.1.0.dist-info/entry_points.txt +2 -0
  5. magic_campus_cli-0.1.0.dist-info/top_level.txt +2 -0
  6. magiccampus_cli/__init__.py +1 -0
  7. magiccampus_cli/__main__.py +9 -0
  8. magiccampus_cli/accounts.py +144 -0
  9. magiccampus_cli/cli.py +176 -0
  10. magiccampus_cli/client.py +54 -0
  11. magiccampus_cli/commands/auth.py +32 -0
  12. magiccampus_cli/commands/comment.py +38 -0
  13. magiccampus_cli/commands/config.py +95 -0
  14. magiccampus_cli/commands/feed.py +26 -0
  15. magiccampus_cli/commands/group.py +346 -0
  16. magiccampus_cli/commands/im.py +47 -0
  17. magiccampus_cli/commands/notify.py +81 -0
  18. magiccampus_cli/commands/playgroup.py +49 -0
  19. magiccampus_cli/commands/reaction.py +50 -0
  20. magiccampus_cli/commands/space.py +134 -0
  21. magiccampus_cli/commands/user.py +311 -0
  22. magiccampus_cli/config_store.py +61 -0
  23. magiccampus_cli/notify.py +493 -0
  24. magiccampus_cli/output.py +104 -0
  25. magiccampus_cli/prompts.py +58 -0
  26. magiccampus_cli/targets.py +26 -0
  27. magiccampus_cli/update.py +149 -0
  28. magiccampus_cli/utils.py +67 -0
  29. magiccampus_sdk/__init__.py +43 -0
  30. magiccampus_sdk/auth.py +111 -0
  31. magiccampus_sdk/comment_client.py +107 -0
  32. magiccampus_sdk/feed_api.py +61 -0
  33. magiccampus_sdk/feed_client.py +30 -0
  34. magiccampus_sdk/group_api.py +139 -0
  35. magiccampus_sdk/group_client.py +242 -0
  36. magiccampus_sdk/http/__init__.py +1 -0
  37. magiccampus_sdk/http/group_info_api.py +47 -0
  38. magiccampus_sdk/http/http_api.py +58 -0
  39. magiccampus_sdk/http/http_send.py +758 -0
  40. magiccampus_sdk/http/media.py +839 -0
  41. magiccampus_sdk/http/models.py +645 -0
  42. magiccampus_sdk/http/self_user_info_api.py +182 -0
  43. magiccampus_sdk/http/text.py +75 -0
  44. magiccampus_sdk/models.py +279 -0
  45. magiccampus_sdk/platform_client.py +137 -0
  46. magiccampus_sdk/platform_http.py +71 -0
  47. magiccampus_sdk/playgroup_api.py +104 -0
  48. magiccampus_sdk/playgroup_client.py +45 -0
  49. magiccampus_sdk/reaction_api.py +110 -0
  50. magiccampus_sdk/space_api.py +170 -0
  51. magiccampus_sdk/space_client.py +93 -0
  52. magiccampus_sdk/user_client.py +211 -0
  53. magiccampus_sdk/user_info_api.py +593 -0
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from uuid import uuid4
5
+
6
+ from .auth import fetch_magiccampus_credentials, normalize_platform
7
+
8
+
9
+ class MagicCampusAPIHTTPError(RuntimeError):
10
+ def __init__(self, status_code: int, body: str) -> None:
11
+ super().__init__(f"http status={status_code}, body={body}")
12
+ self.status_code = status_code
13
+ self.body = body
14
+
15
+
16
+ class MagicCampusAPIRemoteError(RuntimeError):
17
+ def __init__(self, code: int, message: str, detail: str = "") -> None:
18
+ super().__init__(f"[{code}] {message} {detail}".strip())
19
+ self.code = int(code)
20
+ self.message = message
21
+ self.detail = detail
22
+
23
+
24
+ class MagicCampusAPINotFoundError(RuntimeError):
25
+ def __init__(self, resource: str, identity: str) -> None:
26
+ super().__init__(f"{resource} not found: {identity}")
27
+ self.resource = resource
28
+ self.identity = identity
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class MagicCampusAPIContext:
33
+ apiurl: str
34
+ platform: str
35
+ user_id: str
36
+ token: str
37
+ api_addr: str
38
+ ws_addr: str
39
+ expire_time: int
40
+ timeout_seconds: float
41
+
42
+
43
+ def next_operation_id() -> str:
44
+ return uuid4().hex
45
+
46
+
47
+ def resolve_api_context(
48
+ *,
49
+ apiurl: str,
50
+ apikey: str,
51
+ platform: str = "IOS",
52
+ credential_timeout_seconds: float = 15.0,
53
+ request_timeout_seconds: float = 15.0,
54
+ ) -> MagicCampusAPIContext:
55
+ normalized_platform = normalize_platform(platform)
56
+ credentials = fetch_magiccampus_credentials(
57
+ apiurl=apiurl,
58
+ apikey=apikey,
59
+ platform=normalized_platform,
60
+ timeout_seconds=credential_timeout_seconds,
61
+ )
62
+ return MagicCampusAPIContext(
63
+ apiurl=credentials.apiurl,
64
+ platform=credentials.platform,
65
+ user_id=credentials.user_id,
66
+ token=credentials.token,
67
+ api_addr=credentials.api_addr,
68
+ ws_addr=credentials.ws_addr,
69
+ expire_time=credentials.expire_time,
70
+ timeout_seconds=request_timeout_seconds,
71
+ )
@@ -0,0 +1,104 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Sequence
4
+ from urllib.parse import quote
5
+
6
+ import httpx
7
+
8
+ from .auth import normalize_apiurl
9
+ from .platform_http import MagicCampusAPIHTTPError, MagicCampusAPINotFoundError, MagicCampusAPIRemoteError
10
+
11
+
12
+ def fetch_playgroups(
13
+ *, apiurl: str, apikey: str, space_id: str | None = None, timeout_seconds: float = 15.0,
14
+ ) -> dict[str, Any]:
15
+ """Return the App Playgroup data for the API Key's business user (assistant owner)."""
16
+ base = normalize_apiurl(apiurl)
17
+ token = str(apikey or "").strip()
18
+ if not token:
19
+ raise ValueError("magiccampus apikey is required")
20
+ path = "/api/v1/space/playgroups"
21
+ params: dict[str, str] = {}
22
+ if space_id is not None:
23
+ if not isinstance(space_id, str) or not space_id.strip() or len(space_id.strip()) > 64:
24
+ raise ValueError("space_id must be a nonempty string of at most 64 characters")
25
+ params["spaceId"] = space_id.strip()
26
+ path += "/detail"
27
+ response = httpx.get(
28
+ f"{base}{path}", params=params,
29
+ headers={"Authorization": f"Bearer {token}"}, timeout=timeout_seconds,
30
+ )
31
+ try:
32
+ response.raise_for_status()
33
+ except httpx.HTTPStatusError as exc:
34
+ raise MagicCampusAPIHTTPError(exc.response.status_code, exc.response.text) from exc
35
+ payload = response.json()
36
+ if not isinstance(payload, dict) or type(payload.get("code")) is not int:
37
+ raise ValueError("magiccampus playgroup response must have an integer code")
38
+ if payload["code"] == 404 and space_id is not None:
39
+ raise MagicCampusAPINotFoundError("playgroup", space_id.strip())
40
+ if payload["code"] != 200:
41
+ raise MagicCampusAPIRemoteError(
42
+ payload["code"], str(payload.get("msg") or ""), str(payload.get("detail") or ""),
43
+ )
44
+ data = payload.get("data")
45
+ if not isinstance(data, dict):
46
+ raise ValueError("magiccampus playgroup response data must be a JSON object")
47
+ return data
48
+
49
+
50
+ def join_playgroup(*, apiurl: str, apikey: str, space_id: str, timeout_seconds: float = 15.0) -> None:
51
+ """Submit an application for the authenticated user/owner; does not join the group."""
52
+ _post_playgroup(apiurl=apiurl, apikey=apikey, space_id=space_id, action="join",
53
+ timeout_seconds=timeout_seconds)
54
+
55
+
56
+ def invite_playgroup_members(
57
+ *, apiurl: str, apikey: str, space_id: str, user_ids: Sequence[str],
58
+ reason: str | None = None, timeout_seconds: float = 15.0,
59
+ ) -> None:
60
+ """Invite as a current Playgroup member; successful Void does not contain invite counts."""
61
+ if isinstance(user_ids, (str, bytes)) or not isinstance(user_ids, Sequence) or not user_ids:
62
+ raise ValueError("user_ids must be a non-empty sequence of user ID strings")
63
+ if any(not isinstance(value, str) or not value.strip() for value in user_ids):
64
+ raise ValueError("user_ids must contain non-empty strings")
65
+ if reason is not None and not isinstance(reason, str):
66
+ raise ValueError("reason must be a string or None")
67
+ body: dict[str, Any] = {"invitedUserIDs": list(dict.fromkeys(value.strip() for value in user_ids))}
68
+ if reason is not None:
69
+ body["reason"] = reason
70
+ _post_playgroup(apiurl=apiurl, apikey=apikey, space_id=space_id, action="inviteMembers",
71
+ body=body, timeout_seconds=timeout_seconds)
72
+
73
+
74
+ def _post_playgroup(
75
+ *, apiurl: str, apikey: str, space_id: str, action: str,
76
+ body: dict[str, Any] | None = None, timeout_seconds: float,
77
+ ) -> None:
78
+ if (not isinstance(space_id, str) or not space_id.strip() or len(space_id.strip()) > 64
79
+ or space_id.strip() in {".", ".."}):
80
+ raise ValueError("space_id must be a nonempty ID of at most 64 characters, not a dot segment")
81
+ normalized_id = space_id.strip()
82
+ base = normalize_apiurl(apiurl)
83
+ token = str(apikey or "").strip()
84
+ if not token:
85
+ raise ValueError("magiccampus apikey is required")
86
+ kwargs: dict[str, Any] = {"headers": {"Authorization": f"Bearer {token}"}, "timeout": timeout_seconds}
87
+ if body is not None:
88
+ kwargs["json"] = body
89
+ response = httpx.post(f"{base}/api/v1/space/playgroups/{quote(normalized_id, safe='')}/{action}", **kwargs)
90
+ try:
91
+ response.raise_for_status()
92
+ except httpx.HTTPStatusError as exc:
93
+ raise MagicCampusAPIHTTPError(exc.response.status_code, exc.response.text) from exc
94
+ payload = response.json()
95
+ if not isinstance(payload, dict) or type(payload.get("code")) is not int:
96
+ raise ValueError("magiccampus playgroup response must have an integer code")
97
+ if payload["code"] == 404:
98
+ raise MagicCampusAPINotFoundError("playgroup", normalized_id)
99
+ if payload["code"] != 200:
100
+ raise MagicCampusAPIRemoteError(
101
+ payload["code"], str(payload.get("msg") or ""), str(payload.get("detail") or ""),
102
+ )
103
+ if payload.get("data") is not None:
104
+ raise ValueError("magiccampus playgroup write response data must be null")
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, Sequence
5
+
6
+ from .playgroup_api import fetch_playgroups, join_playgroup, invite_playgroup_members
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class MagicCampusPlaygroupClientConfig:
11
+ apiurl: str
12
+ apikey: str
13
+ request_timeout_seconds: float = 15.0
14
+
15
+
16
+ class MagicCampusPlaygroupClient:
17
+ def __init__(self, config: MagicCampusPlaygroupClientConfig) -> None:
18
+ self._config = config
19
+
20
+ def list(self) -> dict[str, Any]:
21
+ """All public Playgroups and the joined subset; unjoinedPlaygroups includes joined items."""
22
+ return fetch_playgroups(
23
+ apiurl=self._config.apiurl, apikey=self._config.apikey,
24
+ timeout_seconds=self._config.request_timeout_seconds,
25
+ )
26
+
27
+ def get(self, space_id: str) -> dict[str, Any]:
28
+ """Fetch a public Playgroup by spaceId; its main group ID is innerData.groupId."""
29
+ if space_id is None:
30
+ raise ValueError("space_id must be a nonempty string of at most 64 characters")
31
+ return fetch_playgroups(
32
+ apiurl=self._config.apiurl, apikey=self._config.apikey, space_id=space_id,
33
+ timeout_seconds=self._config.request_timeout_seconds,
34
+ )
35
+
36
+ def join(self, space_id: str) -> None:
37
+ """Apply as the current user/owner. Success means submitted, not joined."""
38
+ join_playgroup(apiurl=self._config.apiurl, apikey=self._config.apikey, space_id=space_id,
39
+ timeout_seconds=self._config.request_timeout_seconds)
40
+
41
+ def invite_members(self, space_id: str, user_ids: Sequence[str], reason: str | None = None) -> None:
42
+ """Invite as a Playgroup member. Existing members are handled idempotently by the server."""
43
+ invite_playgroup_members(apiurl=self._config.apiurl, apikey=self._config.apikey, space_id=space_id,
44
+ user_ids=user_ids, reason=reason,
45
+ timeout_seconds=self._config.request_timeout_seconds)
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ import httpx
6
+
7
+ from .auth import normalize_apiurl
8
+ from .platform_http import MagicCampusAPIHTTPError, MagicCampusAPIRemoteError
9
+
10
+
11
+ def add_message_reaction(
12
+ *,
13
+ apiurl: str,
14
+ apikey: str,
15
+ conversation_id: str,
16
+ server_msg_id: str,
17
+ msg_sender_id: str,
18
+ reaction_code: str,
19
+ timeout_seconds: float = 15.0,
20
+ ) -> dict[str, Any] | None:
21
+ """Add or replace the authenticated user's reaction to a message."""
22
+ return _request_reaction(
23
+ method="POST",
24
+ apiurl=apiurl,
25
+ apikey=apikey,
26
+ fields={
27
+ "conversationID": ("conversation_id", conversation_id),
28
+ "serverMsgID": ("server_msg_id", server_msg_id),
29
+ "msgSenderID": ("msg_sender_id", msg_sender_id),
30
+ "reactionCode": ("reaction_code", reaction_code),
31
+ },
32
+ timeout_seconds=timeout_seconds,
33
+ )
34
+
35
+
36
+ def delete_message_reaction(
37
+ *,
38
+ apiurl: str,
39
+ apikey: str,
40
+ conversation_id: str,
41
+ server_msg_id: str,
42
+ msg_sender_id: str,
43
+ reaction_id: str,
44
+ timeout_seconds: float = 15.0,
45
+ ) -> dict[str, Any] | None:
46
+ """Delete the authenticated user's reaction by its returned record ID."""
47
+ return _request_reaction(
48
+ method="DELETE",
49
+ apiurl=apiurl,
50
+ apikey=apikey,
51
+ fields={
52
+ "conversationID": ("conversation_id", conversation_id),
53
+ "serverMsgID": ("server_msg_id", server_msg_id),
54
+ "msgSenderID": ("msg_sender_id", msg_sender_id),
55
+ "id": ("reaction_id", reaction_id),
56
+ },
57
+ timeout_seconds=timeout_seconds,
58
+ )
59
+
60
+
61
+ def _request_reaction(
62
+ *,
63
+ method: str,
64
+ apiurl: str,
65
+ apikey: str,
66
+ fields: dict[str, tuple[str, str]],
67
+ timeout_seconds: float,
68
+ ) -> dict[str, Any] | None:
69
+ base_url = normalize_apiurl(apiurl)
70
+ token = str(apikey or "").strip()
71
+ if not token:
72
+ raise ValueError("magiccampus apikey is required")
73
+
74
+ body = {}
75
+ for key, (name, value) in fields.items():
76
+ if not isinstance(value, str) or not value.strip():
77
+ raise ValueError(f"{name} must be a non-empty string")
78
+ body[key] = value.strip()
79
+
80
+ # httpx.delete does not accept a JSON body; use request for both verbs.
81
+ response = httpx.request(
82
+ method,
83
+ f"{base_url}/im/v1/message/reaction",
84
+ json=body,
85
+ headers={
86
+ "Authorization": f"Bearer {token}",
87
+ "Content-Type": "application/json",
88
+ },
89
+ timeout=timeout_seconds,
90
+ )
91
+ try:
92
+ response.raise_for_status()
93
+ except httpx.HTTPStatusError as exc:
94
+ raise MagicCampusAPIHTTPError(exc.response.status_code, exc.response.text) from exc
95
+
96
+ payload = response.json()
97
+ if not isinstance(payload, dict):
98
+ raise ValueError("magiccampus message reaction response must be a JSON object")
99
+ code = int(payload.get("code", 0) or 0)
100
+ if code != 200:
101
+ raise MagicCampusAPIRemoteError(
102
+ code,
103
+ str(payload.get("msg", "") or ""),
104
+ str(payload.get("detail", "") or ""),
105
+ )
106
+
107
+ data = payload.get("data")
108
+ if data is not None and not isinstance(data, dict):
109
+ raise ValueError("magiccampus message reaction data must be a JSON object or null")
110
+ return data
@@ -0,0 +1,170 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Callable
4
+
5
+ import httpx
6
+
7
+ from .auth import normalize_apiurl
8
+
9
+
10
+ def fetch_all_space_notices(
11
+ *,
12
+ apiurl: str,
13
+ apikey: str,
14
+ space_id: str,
15
+ timeout_seconds: float,
16
+ make_http_error: Callable[[int, str], Exception],
17
+ make_sdk_error: Callable[[int, str, str], Exception],
18
+ ) -> list[dict[str, Any]]:
19
+ normalized_apiurl = normalize_apiurl(apiurl)
20
+ normalized_apikey = str(apikey or "").strip()
21
+ normalized_space_id = str(space_id or "").strip()
22
+ if not normalized_apikey:
23
+ raise ValueError("magiccampus apikey is required")
24
+ if not normalized_space_id:
25
+ raise ValueError("space_id is required")
26
+
27
+ response = httpx.get(
28
+ f"{normalized_apiurl}/api/v1/space/notices",
29
+ params={"spaceId": normalized_space_id},
30
+ headers={"Authorization": f"Bearer {normalized_apikey}"},
31
+ timeout=timeout_seconds,
32
+ )
33
+
34
+ try:
35
+ response.raise_for_status()
36
+ except httpx.HTTPStatusError as exc:
37
+ raise make_http_error(exc.response.status_code, exc.response.text) from exc
38
+
39
+ payload = response.json()
40
+ if not isinstance(payload, dict):
41
+ raise ValueError("magiccampus getAllNotice response must be a JSON object")
42
+
43
+ code = int(payload.get("code", 0) or 0)
44
+ if code != 200:
45
+ raise make_sdk_error(code, str(payload.get("msg", "") or ""), "")
46
+
47
+ data = payload.get("data")
48
+ if data is None:
49
+ return []
50
+ if not isinstance(data, list):
51
+ raise ValueError("magiccampus getAllNotice response data must be a JSON array or null")
52
+ if any(not isinstance(notice, dict) for notice in data):
53
+ raise ValueError("magiccampus getAllNotice response data items must be JSON objects")
54
+
55
+ return data
56
+
57
+
58
+ def update_space_group_name(
59
+ *,
60
+ apiurl: str,
61
+ apikey: str,
62
+ group_id: str,
63
+ name: str,
64
+ timeout_seconds: float,
65
+ make_http_error: Callable[[int, str], Exception],
66
+ make_sdk_error: Callable[[int, str, str], Exception],
67
+ ) -> bool:
68
+ normalized_apiurl = normalize_apiurl(apiurl)
69
+ normalized_apikey = str(apikey or "").strip()
70
+ normalized_group_id = str(group_id or "").strip()
71
+ normalized_name = str(name or "").strip()
72
+ if not normalized_apikey:
73
+ raise ValueError("magiccampus apikey is required")
74
+ if not normalized_group_id:
75
+ raise ValueError("group_id is required")
76
+ if not normalized_name:
77
+ raise ValueError("name is required")
78
+
79
+ response = httpx.post(
80
+ f"{normalized_apiurl}/api/v1/space/updateSpaceGroup",
81
+ json={"name": normalized_name, "groupId": normalized_group_id},
82
+ headers={"Authorization": f"Bearer {normalized_apikey}"},
83
+ timeout=timeout_seconds,
84
+ )
85
+
86
+ try:
87
+ response.raise_for_status()
88
+ except httpx.HTTPStatusError as exc:
89
+ raise make_http_error(exc.response.status_code, exc.response.text) from exc
90
+
91
+ payload = response.json()
92
+ if not isinstance(payload, dict):
93
+ raise ValueError("magiccampus updateSpaceGroup response must be a JSON object")
94
+
95
+ code = int(payload.get("code", 0) or 0)
96
+ if code != 200:
97
+ raise make_sdk_error(code, str(payload.get("msg", "") or ""), "")
98
+
99
+ data = payload.get("data")
100
+ if not isinstance(data, bool):
101
+ raise ValueError("magiccampus updateSpaceGroup response data must be a boolean")
102
+ return data
103
+
104
+
105
+ def create_space_notice(
106
+ *,
107
+ apiurl: str,
108
+ apikey: str,
109
+ space_id: str,
110
+ title: str,
111
+ text: str,
112
+ expiretime: int,
113
+ timeout_seconds: float,
114
+ make_http_error: Callable[[int, str], Exception],
115
+ make_sdk_error: Callable[[int, str, str], Exception],
116
+ ) -> Any:
117
+ normalized_apiurl = normalize_apiurl(apiurl)
118
+ normalized_apikey = str(apikey or "").strip()
119
+ normalized_space_id = str(space_id or "").strip()
120
+ normalized_title = str(title or "").strip()
121
+ normalized_text = str(text or "").strip()
122
+ if isinstance(expiretime, bool):
123
+ raise ValueError("expiretime must be an integer")
124
+ try:
125
+ normalized_expiretime = int(expiretime)
126
+ except (TypeError, ValueError) as exc:
127
+ raise ValueError("expiretime must be an integer") from exc
128
+
129
+ if not normalized_apikey:
130
+ raise ValueError("magiccampus apikey is required")
131
+ if not normalized_space_id:
132
+ raise ValueError("space_id is required")
133
+ if not normalized_title:
134
+ raise ValueError("title is required")
135
+ if not normalized_text:
136
+ raise ValueError("text is required")
137
+
138
+ response = httpx.post(
139
+ f"{normalized_apiurl}/api/v1/space/notices",
140
+ json={
141
+ "spaceId": normalized_space_id,
142
+ "title": normalized_title,
143
+ "text": normalized_text,
144
+ "expiretime": normalized_expiretime,
145
+ },
146
+ headers={
147
+ "Authorization": f"Bearer {normalized_apikey}",
148
+ "Content-Type": "application/json",
149
+ },
150
+ timeout=timeout_seconds,
151
+ )
152
+
153
+ try:
154
+ response.raise_for_status()
155
+ except httpx.HTTPStatusError as exc:
156
+ raise make_http_error(exc.response.status_code, exc.response.text) from exc
157
+
158
+ payload = response.json()
159
+ if not isinstance(payload, dict):
160
+ raise ValueError("magiccampus createNotice response must be a JSON object")
161
+
162
+ code = int(payload.get("code", 0) or 0)
163
+ if code != 200:
164
+ raise make_sdk_error(
165
+ code,
166
+ str(payload.get("msg", "") or ""),
167
+ str(payload.get("detail", "") or ""),
168
+ )
169
+
170
+ return payload.get("data")
@@ -0,0 +1,93 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any
5
+
6
+ from .platform_http import MagicCampusAPIHTTPError, MagicCampusAPIRemoteError
7
+ from .space_api import (
8
+ create_space_notice,
9
+ fetch_all_space_notices,
10
+ update_space_group_name,
11
+ )
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class MagicCampusSpaceClientConfig:
16
+ apiurl: str
17
+ apikey: str
18
+ platform: str = "IOS"
19
+ credential_timeout_seconds: float = 15.0
20
+ request_timeout_seconds: float = 15.0
21
+
22
+
23
+ class MagicCampusSpaceClient:
24
+ def __init__(self, config: MagicCampusSpaceClientConfig) -> None:
25
+ self._config = config
26
+
27
+ def update_group_name(self, group_id: str, name: str) -> bool:
28
+ normalized_group_id = str(group_id or "").strip()
29
+ normalized_name = str(name or "").strip()
30
+ if not normalized_group_id:
31
+ raise ValueError("group_id is required")
32
+ if not normalized_name:
33
+ raise ValueError("name is required")
34
+
35
+ return update_space_group_name(
36
+ apiurl=self._config.apiurl,
37
+ apikey=self._config.apikey,
38
+ group_id=normalized_group_id,
39
+ name=normalized_name,
40
+ timeout_seconds=self._config.request_timeout_seconds,
41
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
42
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
43
+ )
44
+
45
+ def list_notices(self, space_id: str) -> list[dict[str, Any]]:
46
+ normalized_space_id = str(space_id or "").strip()
47
+ if not normalized_space_id:
48
+ raise ValueError("space_id is required")
49
+
50
+ return fetch_all_space_notices(
51
+ apiurl=self._config.apiurl,
52
+ apikey=self._config.apikey,
53
+ space_id=normalized_space_id,
54
+ timeout_seconds=self._config.request_timeout_seconds,
55
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
56
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
57
+ )
58
+
59
+ def create_notice(
60
+ self,
61
+ *,
62
+ space_id: str,
63
+ title: str,
64
+ text: str,
65
+ expiretime: int,
66
+ ) -> Any:
67
+ normalized_space_id = str(space_id or "").strip()
68
+ normalized_title = str(title or "").strip()
69
+ normalized_text = str(text or "").strip()
70
+ if not normalized_space_id:
71
+ raise ValueError("space_id is required")
72
+ if not normalized_title:
73
+ raise ValueError("title is required")
74
+ if not normalized_text:
75
+ raise ValueError("text is required")
76
+ if isinstance(expiretime, bool):
77
+ raise ValueError("expiretime must be an integer")
78
+ try:
79
+ normalized_expiretime = int(expiretime)
80
+ except (TypeError, ValueError) as exc:
81
+ raise ValueError("expiretime must be an integer") from exc
82
+
83
+ return create_space_notice(
84
+ apiurl=self._config.apiurl,
85
+ apikey=self._config.apikey,
86
+ space_id=normalized_space_id,
87
+ title=normalized_title,
88
+ text=normalized_text,
89
+ expiretime=normalized_expiretime,
90
+ timeout_seconds=self._config.request_timeout_seconds,
91
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
92
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
93
+ )