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,211 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from dataclasses import dataclass
5
+ from typing import Any
6
+ import warnings
7
+
8
+ from .platform_http import MagicCampusAPIHTTPError, MagicCampusAPINotFoundError, MagicCampusAPIRemoteError
9
+ from .user_info_api import (
10
+ adjust_user_elements,
11
+ fetch_all_users_page,
12
+ fetch_growth_profile,
13
+ fetch_random_users,
14
+ fetch_user_info,
15
+ initialize_growth_profile,
16
+ set_user_academy,
17
+ update_user_ext,
18
+ update_user_info,
19
+ update_user_profile,
20
+ )
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class MagicCampusUserClientConfig:
25
+ apiurl: str
26
+ apikey: str
27
+ platform: str = "IOS"
28
+ credential_timeout_seconds: float = 15.0
29
+ request_timeout_seconds: float = 15.0
30
+
31
+
32
+ class MagicCampusUserClient:
33
+ def __init__(self, config: MagicCampusUserClientConfig) -> None:
34
+ self._config = config
35
+
36
+ def get(self, user_id: str) -> dict[str, Any]:
37
+ normalized_user_id = str(user_id or "").strip()
38
+ if not normalized_user_id:
39
+ raise ValueError("user_id is required")
40
+
41
+ return fetch_user_info(
42
+ apiurl=self._config.apiurl,
43
+ apikey=self._config.apikey,
44
+ user_id=normalized_user_id,
45
+ timeout_seconds=self._config.request_timeout_seconds,
46
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
47
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
48
+ make_not_found_error=lambda identity: MagicCampusAPINotFoundError("user", identity),
49
+ )
50
+
51
+ def get_growth_profile(self, user_id: str | int) -> dict[str, Any]:
52
+ return fetch_growth_profile(
53
+ apiurl=self._config.apiurl,
54
+ apikey=self._config.apikey,
55
+ user_id=user_id,
56
+ timeout_seconds=self._config.request_timeout_seconds,
57
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
58
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
59
+ make_not_found_error=lambda identity: MagicCampusAPINotFoundError(
60
+ "growth profile for user", identity
61
+ ),
62
+ )
63
+
64
+ def init_growth_profile(
65
+ self,
66
+ user_id: str | int,
67
+ *,
68
+ reset: bool = False,
69
+ ) -> dict[str, object]:
70
+ return initialize_growth_profile(
71
+ apiurl=self._config.apiurl,
72
+ apikey=self._config.apikey,
73
+ user_id=user_id,
74
+ reset=reset,
75
+ timeout_seconds=self._config.request_timeout_seconds,
76
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
77
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
78
+ )
79
+
80
+ def set_academy(
81
+ self,
82
+ user_id: str | int,
83
+ academy_code: str,
84
+ ) -> dict[str, object]:
85
+ return set_user_academy(
86
+ apiurl=self._config.apiurl,
87
+ apikey=self._config.apikey,
88
+ user_id=user_id,
89
+ academy_code=academy_code,
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
+ )
94
+
95
+ def update_ext(self, ext: Mapping[str, str]) -> dict[str, object]:
96
+ """Merge string fields into the authenticated user (owner for MUSHROOM keys)."""
97
+ return update_user_ext(
98
+ apiurl=self._config.apiurl,
99
+ apikey=self._config.apikey,
100
+ ext=ext,
101
+ timeout_seconds=self._config.request_timeout_seconds,
102
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
103
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
104
+ )
105
+
106
+ def update_info(
107
+ self, *, nickname: str | None = None, avatar_url: str | None = None,
108
+ introduction: str | None = None, birth: str | None = None,
109
+ gender: str | None = None, tags: list[str] | None = None,
110
+ ) -> dict[str, Any]:
111
+ """Update basic fields of the authenticated user (owner for MUSHROOM keys)."""
112
+ info = {key: value for key, value in {
113
+ "nickname": nickname, "avatarUrl": avatar_url, "introduction": introduction,
114
+ "birth": birth, "gender": gender, "tags": tags,
115
+ }.items() if value is not None}
116
+ return update_user_info(
117
+ apiurl=self._config.apiurl, apikey=self._config.apikey, info=info,
118
+ timeout_seconds=self._config.request_timeout_seconds,
119
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
120
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
121
+ )
122
+
123
+ def update_profile(
124
+ self,
125
+ user_id: str,
126
+ *,
127
+ nickname: str | None = None,
128
+ avatar_url: str | None = None,
129
+ ) -> Any:
130
+ """Deprecated explicit-target compatibility API; use update_info for self/owner."""
131
+ warnings.warn("update_profile is deprecated; use update_info for current-user/owner fields. "
132
+ "Explicit bound-assistant targets and avatar reset retain the legacy route.",
133
+ DeprecationWarning, stacklevel=2)
134
+ return update_user_profile(
135
+ apiurl=self._config.apiurl,
136
+ apikey=self._config.apikey,
137
+ user_id=user_id,
138
+ nickname=nickname,
139
+ avatar_url=avatar_url,
140
+ timeout_seconds=self._config.request_timeout_seconds,
141
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
142
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
143
+ )
144
+
145
+ def adjust_elements(
146
+ self,
147
+ user_id: str | int,
148
+ *,
149
+ metal_delta: int | None = None,
150
+ wood_delta: int | None = None,
151
+ water_delta: int | None = None,
152
+ fire_delta: int | None = None,
153
+ earth_delta: int | None = None,
154
+ ) -> dict[str, object]:
155
+ return adjust_user_elements(
156
+ apiurl=self._config.apiurl,
157
+ apikey=self._config.apikey,
158
+ user_id=user_id,
159
+ metal_delta=metal_delta,
160
+ wood_delta=wood_delta,
161
+ water_delta=water_delta,
162
+ fire_delta=fire_delta,
163
+ earth_delta=earth_delta,
164
+ timeout_seconds=self._config.request_timeout_seconds,
165
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
166
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
167
+ )
168
+
169
+ def list(
170
+ self,
171
+ page: int = 1,
172
+ academy_code: str | None = None,
173
+ ) -> dict[str, Any]:
174
+ return fetch_all_users_page(
175
+ apiurl=self._config.apiurl,
176
+ apikey=self._config.apikey,
177
+ page=page,
178
+ academy_code=academy_code,
179
+ timeout_seconds=self._config.request_timeout_seconds,
180
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
181
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
182
+ )
183
+
184
+ def list_all(self, academy_code: str | None = None) -> list[dict[str, Any]]:
185
+ users: list[dict[str, Any]] = []
186
+ page_num = 1
187
+ while True:
188
+ result = self.list(page_num, academy_code=academy_code)
189
+ content = result.get("content", [])
190
+ if not isinstance(content, list) or any(not isinstance(user, dict) for user in content):
191
+ raise ValueError("magiccampus allUsers response content must be a JSON array of objects")
192
+ users.extend(content)
193
+ page = result.get("page") or {}
194
+ if page_num >= int(page.get("totalPages", 0) or 0):
195
+ return users
196
+ page_num += 1
197
+
198
+ def list_random(
199
+ self,
200
+ filter_no_face_url: bool = True,
201
+ academy_code: str | None = None,
202
+ ) -> list[dict[str, Any]]:
203
+ return fetch_random_users(
204
+ apiurl=self._config.apiurl,
205
+ apikey=self._config.apikey,
206
+ filter_no_face_url=filter_no_face_url,
207
+ academy_code=academy_code,
208
+ timeout_seconds=self._config.request_timeout_seconds,
209
+ make_http_error=lambda status_code, body: MagicCampusAPIHTTPError(status_code, body),
210
+ make_sdk_error=lambda code, message, detail: MagicCampusAPIRemoteError(code, message, detail),
211
+ )