-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Literal, overload | ||
|
||
from mipac.abstract.action import AbstractAction | ||
from mipac.http import HTTPClient, Route | ||
from mipac.models.channel import Channel | ||
from mipac.models.lite.channel import ChannelLite | ||
from mipac.types.channel import IChannel, IChannelLite | ||
|
||
if TYPE_CHECKING: | ||
from mipac.client import ClientManager | ||
|
||
|
||
class ClientChannelActions(AbstractAction): | ||
def __init__( | ||
self, channel_id: str | None = None, *, session: HTTPClient, client: ClientManager | ||
): | ||
self._channel_id: str | None = channel_id | ||
self._session: HTTPClient = session | ||
self._client: ClientManager = client | ||
|
||
async def favorite(self, channel_id: str | None = None): | ||
if self._client._config.use_version < 13: | ||
raise Exception() | ||
|
||
channel_id = self._channel_id or channel_id | ||
if channel_id is None: | ||
raise Exception() | ||
|
||
res: bool = await self._session.request( | ||
Route('POST', '/api/channels/favorite'), auth=True, json={'channelId': channel_id} | ||
) | ||
|
||
return res | ||
|
||
async def unfavorite(self, channel_id: str | None = None): | ||
|
||
if self._client._config.use_version < 13: | ||
raise Exception() | ||
|
||
channel_id = self._channel_id or channel_id | ||
if channel_id is None: | ||
raise Exception() | ||
|
||
res: bool = await self._session.request( | ||
Route('POST', '/api/channels/unfavorite'), auth=True, json={'channelId': channel_id} | ||
) | ||
|
||
return res | ||
|
||
|
||
class ChannelActions(ClientChannelActions): | ||
def __init__( | ||
self, channel_id: str | None = None, *, session: HTTPClient, client: ClientManager | ||
): | ||
super().__init__(channel_id=channel_id, session=session, client=client) | ||
|
||
async def get_my_favorite(self) -> list[Channel]: | ||
"""お気に入りに登録したチャンネルの一覧を取得します。 | ||
Returns | ||
------- | ||
Channel | ||
チャンネル | ||
""" | ||
if self._client._config.use_version < 13: | ||
raise Exception() | ||
|
||
res: list[IChannel] = await self._session.request( | ||
Route('POST', '/api/channels/my-favorites'), auth=True | ||
) | ||
return [Channel(i, client=self._client) for i in res] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
from mipac.abstract.manager import AbstractManager | ||
from mipac.http import HTTPClient | ||
from mipac.actions.channel import ChannelActions | ||
|
||
if TYPE_CHECKING: | ||
from mipac.manager.client import ClientManager | ||
|
||
|
||
class ChannelManager(AbstractManager): | ||
def __init__(self, channel_id: str | None = None, *, session: HTTPClient, client: ClientManager): | ||
self.__channel_id: str | None = channel_id | ||
self.__session: HTTPClient = session | ||
self.__client: ClientManager = client | ||
|
||
@property | ||
def action(self) -> ChannelActions: | ||
return ChannelActions(channel_id=self.__channel_id, session=self.__session, client=self.__client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters