Skip to content

Commit

Permalink
feat: フォローリクエストを取得できるように close #12
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Oct 4, 2022
1 parent f1fc584 commit d142355
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mipac/actions/my.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from mipac.abc.action import AbstractAction
from mipac.http import HTTPClient, Route
from mipac.models.follow import FollowRequest
from mipac.types.follow import IFollowRequest

if TYPE_CHECKING:
from mipac.manager.client import ClientActions


class MyActions(AbstractAction):
def __init__(self, session: HTTPClient, client: ClientActions):
self.__session = session
self.__client = client

async def fetch_follow_requests(self):
res: list[IFollowRequest] = await self.__session.request(Route('POST', '/api/following/requests/list'), auth=True, lower=True)
return [FollowRequest(i, client=self.__client) for i in res]
2 changes: 2 additions & 0 deletions mipac/manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mipac.manager.chart import ChartManager
from mipac.manager.chat import ChatManager
from mipac.manager.drive import DriveManager
from mipac.manager.my import MyManager
from mipac.manager.note import NoteManager
from mipac.manager.reaction import ReactionManager
from mipac.manager.user import UserManager
Expand All @@ -21,6 +22,7 @@
class ClientActions:
def __init__(self, session: HTTPClient, config: Config):
self.__session: HTTPClient = session
self.i = MyManager(session=session, client=self)
self.note: NoteManager = NoteManager(session=session, client=self)
self.chat: ChatManager = ChatManager(session=session, client=self)
self.user: UserManager = UserManager(session=session, client=self)
Expand Down
20 changes: 20 additions & 0 deletions mipac/manager/my.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from mipac.abc.manager import AbstractManager
from mipac.actions.my import MyActions
from mipac.http import HTTPClient

if TYPE_CHECKING:
from mipac.manager.client import ClientActions


class MyManager(AbstractManager):
def __init__(self, *, session: HTTPClient, client: ClientActions):
self.__session = session
self.__client = client

@property
def action(self):
return MyActions(session=self.__session, client=self.__client)

25 changes: 25 additions & 0 deletions mipac/models/follow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from mipac.models.lite.user import LiteUser
from mipac.types.follow import IFollowRequest

if TYPE_CHECKING:
from mipac.manager.client import ClientActions

class FollowRequest:
def __init__(self, follow_request: IFollowRequest, *, client: ClientActions) -> None:
self.__follow_request = follow_request
self.__client = client

@property
def id(self) -> str:
return self.__follow_request['id']

@property
def follower(self) -> LiteUser:
return LiteUser(self.__follow_request['follower'])

@property
def followee(self) -> LiteUser:
return LiteUser(self.__follow_request['followee'])

9 changes: 9 additions & 0 deletions mipac/types/follow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import TypedDict

from mipac.types.user import IUserLite


class IFollowRequest(TypedDict):
id: str
follower: IUserLite
followee: IUserLite

0 comments on commit d142355

Please sign in to comment.