feat: channels/timeline周りのDocStringを更新 & エラーハンドリングを追加

pull/109/head
yupix 7 months ago
parent afe4c8f84f
commit 3c28646caa
No known key found for this signature in database
GPG Key ID: 2FF705F5C56D9C06

@ -234,29 +234,35 @@ class ClientChannelActions(AbstractAction):
*, *,
channel_id: str | None = None, channel_id: str | None = None,
) -> list[Note]: ) -> list[Note]:
"""Get the timeline of a channel """チャンネルのタイムラインを取得します
Endpoint: `/api/channels/timeline` Endpoint: `/api/channels/timeline`
Parameters Parameters
---------- ----------
limit : int, optional limit : int
Limit, by default 10 一度に取得する件数, default=10
since_id : str, optional since_id : str | None
Since ID, by default None 指定したIDのートより後のートを取得します, default=None
until_id : str, optional until_id : str | None
Until ID, by default None 指定したIDのートより前のートを取得します, default=None
since_date : int, optional since_date : int | None
Since date, by default None 指定した日付のノートより後のノートを取得します, default=None
until_date : int, optional until_date : int | None
Until date, by default None 指定した日付のノートより前のノートを取得します, default=None
channel_id : str | None
対象のチャンネルID, default=None
Returns Returns
------- -------
list[Note] list[Note]
List of notes 取得したノートのリスト
""" """
channel_id = channel_id or self._channel_id channel_id = channel_id or self._channel_id
if channel_id is None:
raise ParameterError("channel_id is required")
data = { data = {
"channelId": channel_id, "channelId": channel_id,
"limit": limit, "limit": limit,
@ -280,25 +286,35 @@ class ClientChannelActions(AbstractAction):
*, *,
channel_id: str | None = None, channel_id: str | None = None,
) -> AsyncGenerator[Note, None]: ) -> AsyncGenerator[Note, None]:
"""Get all notes in the timeline of a channel """チャンネルのタイムラインを全て取得します
Endpoint: `/api/channels/timeline`
Parameters Parameters
---------- ----------
since_id : str, optional limit : int
Since ID, by default None 一度に取得する件数, default=10
until_id : str, optional since_id : str | None
Until ID, by default None 指定したIDのートより後のートを取得します, default=None
since_date : int, optional until_id : str | None
Since date, by default None 指定したIDのートより前のートを取得します, default=None
until_date : int, optional since_date : int | None
Until date, by default None 指定した日付のノートより後のノートを取得します, default=None
until_date : int | None
指定した日付のノートより前のノートを取得します, default=None
channel_id : str | None
対象のチャンネルID, default=None
Returns Returns
------- -------
AsyncGenerator[Note, None] AsyncGenerator[Note, None]
Async generator of notes 取得したノートのリスト
""" """
channel_id = channel_id or self._channel_id channel_id = channel_id or self._channel_id
if channel_id is None:
raise ParameterError("channel_id is required")
data = { data = {
"channelId": channel_id, "channelId": channel_id,
"sinceId": since_id, "sinceId": since_id,
@ -317,19 +333,19 @@ class ClientChannelActions(AbstractAction):
@credentials_required @credentials_required
async def favorite(self, *, channel_id: str | None = None) -> bool: async def favorite(self, *, channel_id: str | None = None) -> bool:
"""Favorite a channel """指定したIDのチャンネルをお気に入りにします
Endpoint: `/api/channels/favorite` Endpoint: `/api/channels/favorite`
Parameters Parameters
---------- ----------
channel_id : str, optional channel_id : str | None
ID of the channel, by default None 対象のチャンネルID, default=None
Returns Returns
------- -------
bool bool
Whether the channel is favorited お気に入りに追加できたかどうか
""" """
channel_id = channel_id or self._channel_id channel_id = channel_id or self._channel_id
data = {"channelId": channel_id} data = {"channelId": channel_id}
@ -341,21 +357,25 @@ class ClientChannelActions(AbstractAction):
@credentials_required @credentials_required
async def unfavorite(self, *, channel_id: str | None = None) -> bool: async def unfavorite(self, *, channel_id: str | None = None) -> bool:
"""Unfavorite a channel """指定したIDのチャンネルをお気に入りから外します
Endpoint: `/api/channels/unfavorite` Endpoint: `/api/channels/unfavorite`
Parameters Parameters
---------- ----------
channel_id : str, optional channel_id : str | None
ID of the channel, by default None 対象のチャンネルID, default=None
Returns Returns
------- -------
bool bool
Whether the channel is unfavorited お気に入りから外せたかどうか
""" """
channel_id = channel_id or self._channel_id channel_id = channel_id or self._channel_id
if channel_id is None:
raise ParameterError("channel_id is required")
data = {"channelId": channel_id} data = {"channelId": channel_id}
res: bool = await self._session.request( res: bool = await self._session.request(
@ -701,6 +721,45 @@ class ChannelActions(ClientChannelActions):
""" """
return await super().unfollow(channel_id=channel_id) return await super().unfollow(channel_id=channel_id)
@override
async def timeline(
self,
channel_id: str,
limit: int = 10,
since_id: str | None = None,
until_id: str | None = None,
since_date: int | None = None,
until_date: int | None = None,
) -> list[Note]:
"""チャンネルのタイムラインを取得します
Endpoint: `/api/channels/timeline`
Parameters
----------
channel_id : str
対象のチャンネルID
limit : int
一度に取得する件数, default=10
since_id : str | None
指定したIDのートより後のートを取得します, default=None
until_id : str | None
指定したIDのートより前のートを取得します, default=None
since_date : int | None
指定した日付のノートより後のノートを取得します, default=None
until_date : int | None
指定した日付のノートより前のノートを取得します, default=None
Returns
-------
list[Note]
取得したノートのリスト
"""
return await super().timeline(
channel_id=channel_id, limit=limit, since_id=since_id, until_id=until_id, since_date=since_date, until_date=until_date
)
@override @override
async def get_all_timeline( async def get_all_timeline(
self, self,
@ -710,25 +769,29 @@ class ChannelActions(ClientChannelActions):
since_date: int | None = None, since_date: int | None = None,
until_date: int | None = None, until_date: int | None = None,
) -> AsyncGenerator[Note, None]: ) -> AsyncGenerator[Note, None]:
"""Get all notes in the timeline of a channel """チャンネルのタイムラインを全て取得します
Endpoint: `/api/channels/timeline`
Parameters Parameters
---------- ----------
channel_id : str limit : int
ID of the channel 一度に取得する件数, default=10
since_id : str, optional since_id : str | None
Since ID, by default None 指定したIDのートより後のートを取得します, default=None
until_id : str, optional until_id : str | None
Until ID, by default None 指定したIDのートより前のートを取得します, default=None
since_date : int, optional since_date : int | None
Since date, by default None 指定した日付のノートより後のノートを取得します, default=None
until_date : int, optional until_date : int | None
Until date, by default None 指定した日付のノートより前のノートを取得します, default=None
channel_id : str | None
対象のチャンネルID, default=None
Returns Returns
------- -------
AsyncGenerator[Note, None] AsyncGenerator[Note, None]
Async generator of notes 取得したノートのリスト
""" """
async for i in super().get_all_timeline( async for i in super().get_all_timeline(
since_id=since_id, since_id=since_id,
@ -799,51 +862,51 @@ class ChannelActions(ClientChannelActions):
@credentials_required @credentials_required
@override @override
async def favorite(self, channel_id: str) -> bool: async def favorite(self, channel_id: str) -> bool:
"""Favorite a channel """指定したIDのチャンネルをお気に入りにします
Endpoint: `/api/channels/favorite` Endpoint: `/api/channels/favorite`
Parameters Parameters
---------- ----------
channel_id : str channel_id : str
ID of the channel 対象のチャンネルID
Returns Returns
------- -------
bool bool
Whether the channel is favorited お気に入りに追加できたかどうか
""" """
return await super().favorite(channel_id=channel_id) return await super().favorite(channel_id=channel_id)
@credentials_required @credentials_required
@override @override
async def unfavorite(self, channel_id: str) -> bool: async def unfavorite(self, channel_id: str) -> bool:
"""Unfavorite a channel """指定したIDのチャンネルをお気に入りから外します
Endpoint: `/api/channels/unfavorite` Endpoint: `/api/channels/unfavorite`
Parameters Parameters
---------- ----------
channel_id : str channel_id : str
ID of the channel 対象のチャンネルID
Returns Returns
------- -------
bool bool
Whether the channel is unfavorited お気に入りから外せたかどうか
""" """
return await super().unfavorite(channel_id=channel_id) return await super().unfavorite(channel_id=channel_id)
@credentials_required @credentials_required
async def my_favorites(self) -> list[Channel]: async def my_favorites(self) -> list[Channel]:
"""Get my favorite channels """自分がお気に入りにしているチャンネルを取得します
Endpoint: `/api/channels/myFavorites` Endpoint: `/api/channels/myFavorites`
Returns Returns
------- -------
list[Channel] list[Channel]
List of my favorite channels 取得したチャンネルのリスト
""" """
raw_channels: list[IChannel] = await self._session.request( raw_channels: list[IChannel] = await self._session.request(
Route("POST", "/api/channels/my-favorites"), auth=True, lower=True Route("POST", "/api/channels/my-favorites"), auth=True, lower=True
@ -861,27 +924,27 @@ class ChannelActions(ClientChannelActions):
until_id: str | None = None, until_id: str | None = None,
limit: int = 5, limit: int = 5,
) -> list[Channel]: ) -> list[Channel]:
"""Search channels """チャンネルを検索します
Endpoint: `/api/channels/search` Endpoint: `/api/channels/search`
Parameters Parameters
---------- ----------
query : str query : str
Query 検索するキーワード
type : Literal["nameAndDescription","nameOnly"], optional type : Literal["nameAndDescription","nameOnly"]
Type of the search, by default "nameAndDescription" 検索に用いる形式, default="nameAndDescription"
since_id : str, optional since_id : str | None
Since ID, by default None 指定したIDのチャンネルより後のチャンネルを取得します, default=None
until_id : str, optional until_id : str, optional
Until ID, by default None 指定したIDのチャンネルより前のチャンネルを取得します, default=None
limit : int, optional limit : int, optional
Limit, by default 5 一度に取得するチャンネルの数, default=5
Returns Returns
------- -------
list[Channel] list[Channel]
List of channels 見つかったチャンネルのリスト
""" """
data = { data = {

Loading…
Cancel
Save