@@ -59,49 +59,117 @@ def _update_from_old_data(self, data:OldUserPayload):
5959
6060 @property
6161 def joined_at (self ) -> datetime .datetime | common .UNKNOWN_TYPE :
62+ """
63+ ユーザーが参加した時間を返す。
64+
65+ Returns:
66+ datetime.datetime|UNKNOWN_TYPE: データがある場合、その時間。
67+ """
6268 return common .dt_from_isoformat (self ._joined_at )
6369
6470
6571 async def get_featured (self ) -> "project.ProjectFeatured|None" :
72+ """
73+ ユーザーの注目のプロジェクト欄を取得する。
74+
75+ Returns:
76+ project.ProjectFeatured|None: ユーザーが設定している場合、そのデータ。
77+ """
6678 response = await self .client .get (f"https://scratch.mit.edu/site-api/users/all/{ self .username } /" )
6779 return project .ProjectFeatured (response .json (),self )
6880
6981 async def get_followers (self ,limit :int | None = None ,offset :int | None = None ) -> AsyncGenerator ["User" , None ]:
82+ """
83+ ユーザーのフォロワーを取得する。
84+
85+ Args:
86+ limit (int|None, optional): 取得するユーザーの数。初期値は40です。
87+ offset (int|None, optional): 取得するユーザーの開始位置。初期値は0です。
88+
89+ Yields:
90+ User: 取得したユーザー
91+ """
7092 async for _u in common .api_iterative (
7193 self .client ,f"https://api.scratch.mit.edu/users/{ self .username } /followers/" ,
7294 limit = limit ,offset = offset
7395 ):
7496 yield User ._create_from_data (_u ["username" ],_u ,self .client_or_session )
7597
7698 async def get_followings (self ,limit :int | None = None ,offset :int | None = None ) -> AsyncGenerator ["User" , None ]:
99+ """
100+ ユーザーがフォローしているユーザーを取得する。
101+
102+ Args:
103+ limit (int|None, optional): 取得するユーザーの数。初期値は40です。
104+ offset (int|None, optional): 取得するユーザーの開始位置。初期値は0です。
105+
106+ Yields:
107+ User: 取得したユーザー
108+ """
77109 async for _u in common .api_iterative (
78110 self .client ,f"https://api.scratch.mit.edu/users/{ self .username } /following/" ,
79111 limit = limit ,offset = offset
80112 ):
81113 yield User ._create_from_data (_u ["username" ],_u ,self .client_or_session )
82114
83115 async def get_projects (self ,limit :int | None = None ,offset :int | None = None ) -> AsyncGenerator ["project.Project" , None ]:
116+ """
117+ ユーザーが共有しているプロジェクトを取得する。
118+
119+ Args:
120+ limit (int|None, optional): 取得するプロジェクトの数。初期値は40です。
121+ offset (int|None, optional): 取得するプロジェクトの開始位置。初期値は0です。
122+
123+ Yields:
124+ Project: 取得したプロジェクト
125+ """
84126 async for _p in common .api_iterative (
85127 self .client ,f"https://api.scratch.mit.edu/users/{ self .username } /projects/" ,
86128 limit = limit ,offset = offset
87129 ):
88130 yield project .Project ._create_from_data (_p ["id" ],_p ,self .client_or_session )
89131
90132 async def get_favorites (self ,limit :int | None = None ,offset :int | None = None ) -> AsyncGenerator ["project.Project" , None ]:
133+ """
134+ ユーザーのお気に入りのプロジェクトを取得する。
135+
136+ Args:
137+ limit (int|None, optional): 取得するプロジェクトの数。初期値は40です。
138+ offset (int|None, optional): 取得するプロジェクトの開始位置。初期値は0です。
139+
140+ Yields:
141+ Project: 取得したプロジェクト
142+ """
91143 async for _p in common .api_iterative (
92144 self .client ,f"https://api.scratch.mit.edu/users/{ self .username } /favorites/" ,
93145 limit = limit ,offset = offset
94146 ):
95147 yield project .Project ._create_from_data (_p ["id" ],_p ,self .client_or_session )
96148
97149 async def get_studios (self ,limit :int | None = None ,offset :int | None = None ) -> AsyncGenerator ["studio.Studio" , None ]:
150+ """
151+ ユーザーが参加しているスタジオを取得する。
152+
153+ Args:
154+ limit (int|None, optional): 取得するスタジオの数。初期値は40です。
155+ offset (int|None, optional): 取得するスタジオの開始位置。初期値は0です。
156+
157+ Yields:
158+ Studio: 取得したスタジオ
159+ """
98160 async for _s in common .api_iterative (
99161 self .client ,f"https://api.scratch.mit.edu/users/{ self .username } /studios/curate" ,
100162 limit = limit ,offset = offset
101163 ):
102164 yield studio .Studio ._create_from_data (_s ["id" ],_s ,self .client_or_session )
103165
104166 async def get_message_count (self ) -> int :
167+ """
168+ ユーザーのメッセージの未読数を取得する。
169+
170+ Returns:
171+ int: 未読のメッセージの数
172+ """
105173 response = await self .client .get (
106174 f"https://api.scratch.mit.edu/users/{ self .username } /messages/count/" ,
107175 params = {"cachebust" :str (random .randint (0 ,10000 ))}
@@ -110,6 +178,16 @@ async def get_message_count(self) -> int:
110178 return data .get ("count" )
111179
112180 def get_comments (self ,start_page :int | None = None ,end_page :int | None = None ) -> AsyncGenerator ["comment.Comment" , None ]:
181+ """
182+ プロフィールに投稿されたコメントを取得する。
183+
184+ Args:
185+ start_page (int|None, optional): 取得するコメントの開始ページ位置。初期値は1です。
186+ end_page (int|None, optional): 取得するコメントの終了ページ位置。初期値はstart_pageの値です。
187+
188+ Returns:
189+ Comment: 取得したコメント
190+ """
113191 return comment .get_comment_from_old (self ,start_page ,end_page )
114192
115193 get_comments_from_old = get_comments
@@ -120,15 +198,35 @@ async def post_comment(
120198 parent :"comment.Comment|int|None" = None ,commentee :"User|int|None" = None ,
121199 is_old :bool = True
122200 ) -> "comment.Comment" :
201+ """
202+ コメントを投稿します。
203+
204+ Args:
205+ content (str): コメントの内容
206+ parent (Comment|int|None, optional): 返信する場合、返信元のコメントかID
207+ commentee (User|int|None, optional): メンションする場合、ユーザーかそのユーザーのID
208+ is_old (bool, optional): 古いAPIを使用して送信するか この値は使用されず、常に古いAPIが使用されます。
209+
210+ Returns:
211+ comment.Comment: 投稿されたコメント
212+ """
123213 return await comment .Comment .post_comment (self ,content ,parent ,commentee ,is_old )
124214
125215 async def follow (self ):
216+ """
217+ ユーザーをフォローする
218+ """
219+ self .require_session ()
126220 await self .client .put (
127221 f"https://scratch.mit.edu/site-api/users/followers/{ self .username } /add/" ,
128222 params = {"usernames" :self ._session .username }
129223 )
130224
131225 async def unfollow (self ):
226+ """
227+ ユーザーのフォローを解除する
228+ """
229+ self .require_session ()
132230 await self .client .put (
133231 f"https://scratch.mit.edu/site-api/users/followers/{ self .username } /remove/" ,
134232 params = {"usernames" :self ._session .username }
@@ -139,10 +237,25 @@ async def edit(
139237 self ,* ,
140238 bio :str | None = None ,
141239 status :str | None = None ,
142- featured_project_id :int | None = None ,
240+ featured_project_id :" int|project.Project| None" = None ,
143241 featured_project_label :"ProjectFeaturedLabel|None" = None
144242 ) -> "None | project.ProjectFeatured" :
243+ """
244+ プロフィール欄を編集する。
245+
246+ Args:
247+ bio (str | None, optional): 私について欄の内容
248+ status (str | None, optional): 私が取り組んでいることの内容
249+ featured_project_id (int|project.Project|None, optional): 注目のプロジェクト欄に設定したいプロジェクトかそのID
250+ featured_project_label (ProjectFeaturedLabel|None, optional): 注目のプロジェクト欄に使用したいラベル
251+
252+ Returns:
253+ None | project.ProjectFeatured: 変更された注目のプロジェクト欄
254+ """
255+ self .require_session ()
145256 _data = {}
257+ if isinstance (featured_project_id ,project .Project ):
258+ featured_project_id = featured_project_id .id
146259 if bio is not None : _data ["bio" ] = bio
147260 if status is not None : _data ["status" ] = status
148261 if featured_project_id is not None : _data ["featured_project" ] = featured_project_id
@@ -155,9 +268,20 @@ async def edit(
155268 return project .ProjectFeatured (data ,self )
156269
157270 async def toggle_comment (self ):
271+ """
272+ プロフィールのコメント欄を開閉する。
273+ """
274+ self .require_session ()
158275 await self .client .post (f"https://scratch.mit.edu/site-api/comments/user/{ self .username } /toggle-comments/" )
159276
160277 async def set_icon (self ,icon :file .File | bytes ):
278+ """
279+ アイコンを変更する。
280+
281+ Args:
282+ icon (file.File | bytes): アイコンのデータ
283+ """
284+ self .require_session ()
161285 async with file ._read_file (icon ) as f :
162286 self .require_session ()
163287 await self .client .post (
@@ -167,6 +291,9 @@ async def set_icon(self,icon:file.File|bytes):
167291
168292
169293class ProjectFeaturedLabel (Enum ):
294+ """
295+ 注目のプロジェクト欄のラベルを表す。
296+ """
170297 ProjectFeatured = ""
171298 Tutorial = "0"
172299 WorkInProgress = "1"
@@ -185,4 +312,13 @@ async def get_from_id(cls,id:int|None) -> "ProjectFeaturedLabel":
185312 raise ValueError ()
186313
187314def get_user (username :str ,* ,_client :client .HTTPClient | None = None ) -> common ._AwaitableContextManager [User ]:
315+ """
316+ ユーザーを取得する。
317+
318+ Args:
319+ username (str): 取得したいユーザーのユーザー名
320+
321+ Returns:
322+ common._AwaitableContextManager[Studio]: await か async with で取得できるユーザー
323+ """
188324 return common ._AwaitableContextManager (User ._create_from_api (username ,_client ))
0 commit comments