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,182 @@
1
+ import threading
2
+ import time
3
+ from dataclasses import dataclass
4
+ from typing import Any, Callable, Dict, List, Optional
5
+
6
+ from .http_api import post_json_data
7
+ from .models import SelfUserInfo
8
+
9
+
10
+ @dataclass
11
+ class _SelfUserInfoFetch:
12
+ generation: int
13
+ done: bool = False
14
+ result: Optional[SelfUserInfo] = None
15
+ error: Optional[Exception] = None
16
+ stale: bool = False
17
+
18
+
19
+ def fetch_self_user_info(
20
+ *,
21
+ api_addr: str,
22
+ user_id: str,
23
+ token: str,
24
+ operation_id: str,
25
+ timeout_seconds: float,
26
+ make_http_error: Callable[[int, str], Exception],
27
+ make_sdk_error: Callable[[int, str, str], Exception],
28
+ make_not_found_error: Callable[[str], Exception],
29
+ ) -> SelfUserInfo:
30
+ data = post_json_data(
31
+ api_addr=api_addr,
32
+ route="/user/get_users_info",
33
+ payload={"userIDs": [user_id]},
34
+ token=token,
35
+ operation_id=operation_id,
36
+ timeout_seconds=timeout_seconds,
37
+ make_http_error=make_http_error,
38
+ make_sdk_error=make_sdk_error,
39
+ )
40
+ users = _extract_users(data)
41
+ if not users:
42
+ raise make_not_found_error(user_id)
43
+
44
+ for user in users:
45
+ if str(user.get("userID", "") or "") == user_id:
46
+ return SelfUserInfo.from_dict(user)
47
+ return SelfUserInfo.from_dict(users[0])
48
+
49
+
50
+ class SelfUserInfoResolver:
51
+ def __init__(
52
+ self,
53
+ fetcher: Callable[[], SelfUserInfo],
54
+ *,
55
+ cache_ttl_seconds: float = 600.0,
56
+ ) -> None:
57
+ self._fetcher = fetcher
58
+ self._cache_ttl_seconds = float(cache_ttl_seconds)
59
+ self._condition = threading.Condition()
60
+ self._cached: Optional[SelfUserInfo] = None
61
+ self._cached_at: Optional[float] = None
62
+ self._generation = 0
63
+ self._flight: Optional[_SelfUserInfoFetch] = None
64
+
65
+ def _get_cached_locked(self) -> Optional[SelfUserInfo]:
66
+ if self._cached is None:
67
+ return None
68
+ if self._cache_ttl_seconds <= 0:
69
+ self._cached = None
70
+ self._cached_at = None
71
+ return None
72
+ if self._cached_at is None or time.monotonic() - self._cached_at > self._cache_ttl_seconds:
73
+ self._cached = None
74
+ self._cached_at = None
75
+ return None
76
+ return self._cached
77
+
78
+ def get_cached(self) -> Optional[SelfUserInfo]:
79
+ with self._condition:
80
+ return self._get_cached_locked()
81
+
82
+ def set(self, info: SelfUserInfo) -> None:
83
+ with self._condition:
84
+ self._generation += 1
85
+ self._cached = info
86
+ self._cached_at = time.monotonic()
87
+ self._condition.notify_all()
88
+
89
+ def clear(self) -> None:
90
+ with self._condition:
91
+ self._generation += 1
92
+ self._cached = None
93
+ self._cached_at = None
94
+ self._condition.notify_all()
95
+
96
+ def get(self, *, force_refresh: bool = False) -> SelfUserInfo:
97
+ should_force_refresh = force_refresh
98
+ while True:
99
+ with self._condition:
100
+ if not should_force_refresh:
101
+ cached = self._get_cached_locked()
102
+ if cached is not None:
103
+ return cached
104
+ flight = self._flight
105
+ if flight is not None:
106
+ while not flight.done:
107
+ self._condition.wait()
108
+ if flight.stale or self._generation != flight.generation:
109
+ should_force_refresh = False
110
+ continue
111
+ if flight.error is not None:
112
+ raise flight.error
113
+ if flight.result is not None:
114
+ return flight.result
115
+ should_force_refresh = False
116
+ continue
117
+
118
+ flight = _SelfUserInfoFetch(generation=self._generation)
119
+ self._flight = flight
120
+
121
+ try:
122
+ info = self._fetcher()
123
+ except Exception as exc:
124
+ with self._condition:
125
+ flight.stale = self._generation != flight.generation
126
+ if not flight.stale:
127
+ flight.error = exc
128
+ flight.done = True
129
+ if self._flight is flight:
130
+ self._flight = None
131
+ self._condition.notify_all()
132
+ if flight.stale:
133
+ should_force_refresh = False
134
+ continue
135
+ raise
136
+
137
+ with self._condition:
138
+ flight.stale = self._generation != flight.generation
139
+ if not flight.stale:
140
+ self._cached = info
141
+ self._cached_at = time.monotonic()
142
+ flight.result = info
143
+ flight.done = True
144
+ if self._flight is flight:
145
+ self._flight = None
146
+ self._condition.notify_all()
147
+ if flight.stale:
148
+ should_force_refresh = False
149
+ continue
150
+ return info
151
+
152
+ def resolve_sender_profile(
153
+ self,
154
+ sender_nickname: str = "",
155
+ sender_face_url: str = "",
156
+ *,
157
+ on_error: Optional[Callable[[Exception], None]] = None,
158
+ ) -> tuple[str, str]:
159
+ resolved_nickname = str(sender_nickname or "")
160
+ resolved_face_url = str(sender_face_url or "")
161
+ if resolved_nickname and resolved_face_url:
162
+ return resolved_nickname, resolved_face_url
163
+ try:
164
+ info = self.get()
165
+ except Exception as exc:
166
+ if on_error is not None:
167
+ on_error(exc)
168
+ return resolved_nickname, resolved_face_url
169
+ return resolved_nickname or info.nickname, resolved_face_url or info.face_url
170
+
171
+
172
+ def _extract_users(data: Dict[str, Any]) -> List[Dict[str, Any]]:
173
+ users_raw = data.get("usersInfo", [])
174
+ if isinstance(users_raw, list):
175
+ return [item for item in users_raw if isinstance(item, dict)]
176
+ if isinstance(users_raw, dict):
177
+ return [users_raw]
178
+
179
+ single = data.get("userInfo")
180
+ if isinstance(single, dict):
181
+ return [single]
182
+ return []
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from typing import Any, Callable
5
+
6
+
7
+ _AT_TAG_RE = re.compile(
8
+ r"<at\s+user_id=(?P<quote>['\"])(?P<user_id>.*?)(?P=quote)>(?P<label>.*?)</at>",
9
+ re.DOTALL,
10
+ )
11
+
12
+
13
+ def parse_at_text_markup(
14
+ text: str,
15
+ *,
16
+ user_info_resolver: Callable[[str], Any] | None = None,
17
+ ) -> tuple[str, list[str], list[dict[str, str]]] | None:
18
+ matches = list(_AT_TAG_RE.finditer(text))
19
+ if not matches:
20
+ if "<at" in text or "</at>" in text:
21
+ raise ValueError('invalid at tag, expected <at user_id="USER_ID">Display Name</at>')
22
+ return None
23
+
24
+ rendered_parts: list[str] = []
25
+ at_user_list: list[str] = []
26
+ at_users_info: list[dict[str, str]] = []
27
+ last_end = 0
28
+ for match in matches:
29
+ rendered_parts.append(text[last_end : match.start()])
30
+ user_id = match.group("user_id").strip()
31
+ display_name = match.group("label").strip()
32
+ if not user_id:
33
+ raise ValueError('invalid at tag, user_id is required in <at user_id="...">...</at>')
34
+ if not display_name or display_name.lstrip("@") == user_id:
35
+ display_name = ""
36
+ if user_info_resolver is not None:
37
+ try:
38
+ user_info = user_info_resolver(user_id)
39
+ if isinstance(user_info, dict):
40
+ display_name = str(
41
+ user_info.get("nickname")
42
+ or user_info.get("name")
43
+ or user_info.get("userName")
44
+ or ""
45
+ ).strip()
46
+ else:
47
+ display_name = str(
48
+ getattr(user_info, "nickname", "")
49
+ or getattr(user_info, "name", "")
50
+ or ""
51
+ ).strip()
52
+ except Exception:
53
+ display_name = ""
54
+ if not display_name or display_name.lstrip("@") == user_id:
55
+ last_end = match.end()
56
+ continue
57
+ mention_text = display_name if display_name.startswith("@") else f"@{display_name}"
58
+ rendered_parts.append(mention_text)
59
+ at_user_list.append(user_id)
60
+ at_users_info.append(
61
+ {
62
+ "atUserID": user_id,
63
+ "groupNickname": display_name.lstrip("@"),
64
+ }
65
+ )
66
+ last_end = match.end()
67
+
68
+ trailing_text = text[last_end:]
69
+ if "<at" in trailing_text or "</at>" in trailing_text:
70
+ raise ValueError('invalid at tag, expected <at user_id="USER_ID">Display Name</at>')
71
+ rendered_parts.append(trailing_text)
72
+ return ("".join(rendered_parts), at_user_list, at_users_info)
73
+
74
+
75
+ __all__ = ["parse_at_text_markup"]
@@ -0,0 +1,279 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Any, Dict, List, Mapping, Optional
5
+
6
+
7
+ def _to_int(value: Any) -> int:
8
+ try:
9
+ return int(value)
10
+ except (TypeError, ValueError):
11
+ return 0
12
+
13
+
14
+ def _to_bool(value: Any) -> bool:
15
+ if isinstance(value, bool):
16
+ return value
17
+ if isinstance(value, str):
18
+ return value.lower() in {"1", "true", "yes", "on"}
19
+ if isinstance(value, int):
20
+ return value != 0
21
+ return bool(value)
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class BaseSpace:
26
+ id: str = ""
27
+ name: str = ""
28
+ thumbnail: str = ""
29
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
30
+
31
+ @classmethod
32
+ def from_dict(cls, data: Mapping[str, Any]) -> "BaseSpace":
33
+ return cls(
34
+ id=str(data.get("id", "") or ""),
35
+ name=str(data.get("name", "") or ""),
36
+ thumbnail=str(data.get("thumbnail", "") or ""),
37
+ raw=dict(data),
38
+ )
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class Space:
43
+ id: str = ""
44
+ name: str = ""
45
+ introduction: str = ""
46
+ space_id: str = ""
47
+ thumbnail: str = ""
48
+ group_id: str = ""
49
+ inner_data: Any = None
50
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
51
+
52
+ @classmethod
53
+ def from_dict(cls, data: Mapping[str, Any]) -> "Space":
54
+ return cls(
55
+ id=str(data.get("id", "") or ""),
56
+ space_id=str(data.get("spaceId", "") or ""),
57
+ name=str(data.get("name", "") or ""),
58
+ introduction=str(data.get("introduction", "") or ""),
59
+ thumbnail=str(data.get("thumbnail", "") or ""),
60
+ group_id=str(data.get("groupId", "") or ""),
61
+ inner_data=data.get("innerData"),
62
+ raw=dict(data),
63
+ )
64
+
65
+
66
+ @dataclass(frozen=True)
67
+ class Notice:
68
+ title: str = ""
69
+ text: str = ""
70
+ expiretime: int = 0
71
+ space_name: str = ""
72
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
73
+
74
+ @classmethod
75
+ def from_dict(cls, data: Mapping[str, Any]) -> "Notice":
76
+ return cls(
77
+ title=str(data.get("title", "") or ""),
78
+ text=str(data.get("text", "") or ""),
79
+ expiretime=_to_int(data.get("expiretime", 0)),
80
+ space_name=str(data.get("spaceName", "") or ""),
81
+ raw=dict(data),
82
+ )
83
+
84
+
85
+ @dataclass(frozen=True)
86
+ class AgentData:
87
+ name: str = ""
88
+ did: str = ""
89
+ avatar: str = ""
90
+ age: int = 0
91
+ birth: str = ""
92
+ gender: str = ""
93
+ star_sign: str = ""
94
+ voice_id: str = ""
95
+ host_mode: bool = False
96
+ introduction: str = ""
97
+ tags: str = ""
98
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False)
99
+
100
+ @classmethod
101
+ def from_dict(cls, data: Mapping[str, Any]) -> "AgentData":
102
+ return cls(
103
+ name=str(data.get("name", "") or ""),
104
+ did=str(data.get("did", "") or ""),
105
+ avatar=str(data.get("avatar", "") or ""),
106
+ age=_to_int(data.get("age", 0)),
107
+ birth=str(data.get("birth", "") or ""),
108
+ gender=str(data.get("gender", "") or ""),
109
+ star_sign=str(data.get("starSign", "") or ""),
110
+ voice_id=str(data.get("voice_id", data.get("voiceId", "")) or ""),
111
+ host_mode=_to_bool(data.get("host_mode", data.get("hostMode", False))),
112
+ introduction=str(data.get("introduction", "") or ""),
113
+ tags=str(data.get("tags", "") or ""),
114
+ raw=dict(data),
115
+ )
116
+
117
+
118
+ @dataclass(frozen=True)
119
+ class GrowthProfile:
120
+ metal_element: int = 0
121
+ wood_element: int = 0
122
+ water_element: int = 0
123
+ fire_element: int = 0
124
+ earth_element: int = 0
125
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False)
126
+
127
+ @classmethod
128
+ def from_dict(cls, data: Mapping[str, Any]) -> "GrowthProfile":
129
+ return cls(
130
+ metal_element=_to_int(data.get("metalElement", 0)),
131
+ wood_element=_to_int(data.get("woodElement", 0)),
132
+ water_element=_to_int(data.get("waterElement", 0)),
133
+ fire_element=_to_int(data.get("fireElement", 0)),
134
+ earth_element=_to_int(data.get("earthElement", 0)),
135
+ raw=dict(data),
136
+ )
137
+
138
+
139
+ @dataclass(frozen=True)
140
+ class GrowthProfileView:
141
+ user_id: int = 0
142
+ academy_code: str = ""
143
+ academy_level: str = ""
144
+ metal_element: int = 0
145
+ wood_element: int = 0
146
+ water_element: int = 0
147
+ fire_element: int = 0
148
+ earth_element: int = 0
149
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False)
150
+
151
+ @classmethod
152
+ def from_dict(cls, data: Mapping[str, Any]) -> "GrowthProfileView":
153
+ return cls(
154
+ user_id=_to_int(data.get("userId", 0)),
155
+ academy_code=str(data.get("academyCode", "") or ""),
156
+ academy_level=str(data.get("academyLevel", "") or ""),
157
+ metal_element=_to_int(data.get("metalElement", 0)),
158
+ wood_element=_to_int(data.get("woodElement", 0)),
159
+ water_element=_to_int(data.get("waterElement", 0)),
160
+ fire_element=_to_int(data.get("fireElement", 0)),
161
+ earth_element=_to_int(data.get("earthElement", 0)),
162
+ raw=dict(data),
163
+ )
164
+
165
+
166
+ @dataclass(frozen=True)
167
+ class MagicCampusUserInfo:
168
+ user_id: str = ""
169
+ new_user: bool = False
170
+ nickname: str = ""
171
+ avatar_url: str = ""
172
+ face_url: str = ""
173
+ birth: str = ""
174
+ gender: str = ""
175
+ agent_type: str = ""
176
+ account_status: str = ""
177
+ academy: str = ""
178
+ element: str = ""
179
+ element_color: str = ""
180
+ phone: str = ""
181
+ email: str = ""
182
+ login_methods: List[str] = field(default_factory=list)
183
+ bg_image: str = ""
184
+ agent_data: Optional[AgentData] = None
185
+ host_mode: bool = False
186
+ allow_rtc_call: bool = False
187
+ tags: List[str] = field(default_factory=list)
188
+ introduction: str = ""
189
+ spaces: List[BaseSpace] = field(default_factory=list)
190
+ setup_status: str = ""
191
+ allow_invite: bool = False
192
+ invite_code: str = ""
193
+ welcome_msg: str = ""
194
+ growth_profile: Optional[GrowthProfile] = None
195
+ is_admin: bool = False
196
+ raw: Dict[str, Any] = field(default_factory=dict, repr=False)
197
+
198
+ @classmethod
199
+ def from_dict(cls, data: Mapping[str, Any]) -> "MagicCampusUserInfo":
200
+ login_methods_raw = data.get("loginMethods", [])
201
+ tags_raw = data.get("tags", [])
202
+ spaces_raw = data.get("spaces", [])
203
+ agent_data_raw = data.get("agentData")
204
+ growth_profile_raw = data.get("growthProfile")
205
+ return cls(
206
+ user_id=str(data.get("userId", "") or ""),
207
+ new_user=_to_bool(data.get("newUser", False)),
208
+ nickname=str(data.get("nickname", "") or ""),
209
+ avatar_url=str(data.get("avatarUrl", "") or ""),
210
+ face_url=str(data.get("faceUrl", "") or ""),
211
+ birth=str(data.get("birth", "") or ""),
212
+ gender=str(data.get("gender", "") or ""),
213
+ agent_type=str(data.get("agentType", "") or ""),
214
+ account_status=str(data.get("accountStatus", "") or ""),
215
+ academy=str(data.get("academy", "") or ""),
216
+ element=str(data.get("element", "") or ""),
217
+ element_color=str(data.get("elementColor", "") or ""),
218
+ phone=str(data.get("phone", "") or ""),
219
+ email=str(data.get("email", "") or ""),
220
+ login_methods=[str(v) for v in login_methods_raw] if isinstance(login_methods_raw, list) else [],
221
+ bg_image=str(data.get("bgImage", "") or ""),
222
+ agent_data=AgentData.from_dict(agent_data_raw) if isinstance(agent_data_raw, Mapping) else None,
223
+ host_mode=_to_bool(data.get("hostMode", False)),
224
+ allow_rtc_call=_to_bool(data.get("allowRTCCall", False)),
225
+ tags=[str(v) for v in tags_raw] if isinstance(tags_raw, list) else [],
226
+ introduction=str(data.get("introduction", "") or ""),
227
+ spaces=[BaseSpace.from_dict(v) for v in spaces_raw if isinstance(v, Mapping)]
228
+ if isinstance(spaces_raw, list)
229
+ else [],
230
+ setup_status=str(data.get("setupStatus", "") or ""),
231
+ allow_invite=_to_bool(data.get("allowInvite", False)),
232
+ invite_code=str(data.get("inviteCode", "") or ""),
233
+ welcome_msg=str(data.get("welcomeMsg", "") or ""),
234
+ growth_profile=GrowthProfile.from_dict(growth_profile_raw)
235
+ if isinstance(growth_profile_raw, Mapping)
236
+ else None,
237
+ is_admin=_to_bool(data.get("isAdmin", False)),
238
+ raw=dict(data),
239
+ )
240
+
241
+
242
+ @dataclass(frozen=True)
243
+ class MagicCampusPageInfo:
244
+ size: int = 0
245
+ page_size: int = 0
246
+ page_num: int = 0
247
+ total_elements: int = 0
248
+ total_pages: int = 0
249
+
250
+ @classmethod
251
+ def from_dict(cls, data: Mapping[str, Any]) -> "MagicCampusPageInfo":
252
+ return cls(
253
+ size=_to_int(data.get("size", 0)),
254
+ page_size=_to_int(data.get("pageSize", 0)),
255
+ page_num=_to_int(data.get("pageNum", 0)),
256
+ total_elements=_to_int(data.get("totalElements", 0)),
257
+ total_pages=_to_int(data.get("totalPages", 0)),
258
+ )
259
+
260
+
261
+ @dataclass(frozen=True)
262
+ class MagicCampusUserPage:
263
+ page: MagicCampusPageInfo = field(default_factory=MagicCampusPageInfo)
264
+ content: List[MagicCampusUserInfo] = field(default_factory=list)
265
+
266
+ @classmethod
267
+ def from_dict(cls, data: Mapping[str, Any]) -> "MagicCampusUserPage":
268
+ page_raw = data.get("page")
269
+ content_raw = data.get("content", [])
270
+ return cls(
271
+ page=MagicCampusPageInfo.from_dict(page_raw) if isinstance(page_raw, Mapping) else MagicCampusPageInfo(),
272
+ content=[
273
+ MagicCampusUserInfo.from_dict(item)
274
+ for item in content_raw
275
+ if isinstance(item, Mapping)
276
+ ]
277
+ if isinstance(content_raw, list)
278
+ else [],
279
+ )
@@ -0,0 +1,137 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ from .comment_client import MagicCampusCommentClient, MagicCampusCommentClientConfig
7
+ from .feed_client import MagicCampusFeedClient, MagicCampusFeedClientConfig
8
+ from .reaction_api import add_message_reaction, delete_message_reaction
9
+ from .playgroup_client import MagicCampusPlaygroupClient, MagicCampusPlaygroupClientConfig
10
+ from .space_client import MagicCampusSpaceClient, MagicCampusSpaceClientConfig
11
+ from .user_client import MagicCampusUserClient, MagicCampusUserClientConfig
12
+
13
+ if TYPE_CHECKING:
14
+ from .http.http_send import MagicCampusHTTPSendClient, MagicCampusHTTPSendConfig
15
+
16
+
17
+ @dataclass
18
+ class MagicCampusClientConfig:
19
+ apiurl: str
20
+ apikey: str
21
+ platform: str = "IOS"
22
+ credential_timeout_seconds: float = 15.0
23
+ self_user_info_cache_ttl_seconds: float = 600.0
24
+ request_timeout_seconds: float = 15.0
25
+
26
+ def to_http_send_config(self) -> "MagicCampusHTTPSendConfig":
27
+ from .http.http_send import MagicCampusHTTPSendConfig
28
+
29
+ return MagicCampusHTTPSendConfig(
30
+ apiurl=self.apiurl,
31
+ apikey=self.apikey,
32
+ platform=self.platform,
33
+ credential_timeout_seconds=self.credential_timeout_seconds,
34
+ request_timeout_seconds=self.request_timeout_seconds,
35
+ self_user_info_cache_ttl_seconds=self.self_user_info_cache_ttl_seconds,
36
+ )
37
+
38
+ def to_user_config(self) -> MagicCampusUserClientConfig:
39
+ return MagicCampusUserClientConfig(
40
+ apiurl=self.apiurl,
41
+ apikey=self.apikey,
42
+ platform=self.platform,
43
+ credential_timeout_seconds=self.credential_timeout_seconds,
44
+ request_timeout_seconds=self.request_timeout_seconds,
45
+ )
46
+
47
+ def to_feed_config(self) -> MagicCampusFeedClientConfig:
48
+ return MagicCampusFeedClientConfig(
49
+ apiurl=self.apiurl,
50
+ apikey=self.apikey,
51
+ platform=self.platform,
52
+ credential_timeout_seconds=self.credential_timeout_seconds,
53
+ request_timeout_seconds=self.request_timeout_seconds,
54
+ )
55
+
56
+ def to_space_config(self) -> MagicCampusSpaceClientConfig:
57
+ return MagicCampusSpaceClientConfig(
58
+ apiurl=self.apiurl,
59
+ apikey=self.apikey,
60
+ platform=self.platform,
61
+ credential_timeout_seconds=self.credential_timeout_seconds,
62
+ request_timeout_seconds=self.request_timeout_seconds,
63
+ )
64
+
65
+
66
+ class MagicCampusIMClient:
67
+ def __init__(self, config: MagicCampusClientConfig) -> None:
68
+ self._config = config
69
+
70
+ def add_message_reaction(
71
+ self,
72
+ *,
73
+ conversation_id: str,
74
+ server_msg_id: str,
75
+ msg_sender_id: str,
76
+ reaction_code: str,
77
+ ) -> dict[str, Any] | None:
78
+ """Reply with a reaction using the configured Bearer JWT, without IM login."""
79
+ return add_message_reaction(
80
+ apiurl=self._config.apiurl,
81
+ apikey=self._config.apikey,
82
+ conversation_id=conversation_id,
83
+ server_msg_id=server_msg_id,
84
+ msg_sender_id=msg_sender_id,
85
+ reaction_code=reaction_code,
86
+ timeout_seconds=self._config.request_timeout_seconds,
87
+ )
88
+
89
+ def delete_message_reaction(
90
+ self,
91
+ *,
92
+ conversation_id: str,
93
+ server_msg_id: str,
94
+ msg_sender_id: str,
95
+ reaction_id: str,
96
+ ) -> dict[str, Any] | None:
97
+ """Cancel a reaction; an already removed record may return None."""
98
+ return delete_message_reaction(
99
+ apiurl=self._config.apiurl,
100
+ apikey=self._config.apikey,
101
+ conversation_id=conversation_id,
102
+ server_msg_id=server_msg_id,
103
+ msg_sender_id=msg_sender_id,
104
+ reaction_id=reaction_id,
105
+ timeout_seconds=self._config.request_timeout_seconds,
106
+ )
107
+
108
+ def http(self) -> "MagicCampusHTTPSendClient":
109
+ from .http.http_send import MagicCampusHTTPSendClient
110
+
111
+ return MagicCampusHTTPSendClient(self._config.to_http_send_config())
112
+
113
+
114
+ class MagicCampusClient:
115
+ def __init__(self, config: MagicCampusClientConfig) -> None:
116
+ self.config = config
117
+ self.im = MagicCampusIMClient(config)
118
+ from .group_client import MagicCampusGroupClient
119
+
120
+ self.group = MagicCampusGroupClient(config)
121
+ self.user = MagicCampusUserClient(config.to_user_config())
122
+ self.feed = MagicCampusFeedClient(config.to_feed_config())
123
+ self.comment = MagicCampusCommentClient(
124
+ MagicCampusCommentClientConfig(
125
+ apiurl=config.apiurl,
126
+ apikey=config.apikey,
127
+ request_timeout_seconds=config.request_timeout_seconds,
128
+ )
129
+ )
130
+ self.space = MagicCampusSpaceClient(config.to_space_config())
131
+ self.playgroup = MagicCampusPlaygroupClient(
132
+ MagicCampusPlaygroupClientConfig(
133
+ apiurl=config.apiurl,
134
+ apikey=config.apikey,
135
+ request_timeout_seconds=config.request_timeout_seconds,
136
+ )
137
+ )