Skip to content

Commit

Permalink
add new methods related to custom list following
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Mar 31, 2022
1 parent 5861a32 commit 44d6374
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
79 changes: 79 additions & 0 deletions hondana/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,43 @@ async def check_if_following_manga(self, manga_id: str, /) -> bool:
else:
return True

@require_authentication
async def get_my_custom_list_follows(self, limit: int = 10, offset: int = 0) -> list[CustomList]:
"""|coro|
This method will return the current authenticated user's custom list follows.
Returns
--------
list[:class:`CustomList`]
The list of custom lists you follow.
"""
data = await self._http._get_user_custom_list_follows(limit=limit, offset=offset)

fmt: list[CustomList] = []
for item in data["data"]:
fmt.append(CustomList(self._http, item))

return fmt

@require_authentication
async def check_if_following_custom_list(self, custom_list_id: str, /) -> bool:
"""|coro|
This method will check if the current authenticated user is following the specified custom list.
Returns
--------
:class:`bool`
Whether you follow this custom list or not.
"""
try:
await self._http._check_if_following_list(custom_list_id)
except errors.NotFound:
return False
else:
return True

async def create_account(self, *, username: str, password: str, email: str) -> User:
"""|coro|
Expand Down Expand Up @@ -2698,6 +2735,48 @@ async def delete_custom_list(self, custom_list_id: str, /) -> None:
"""
await self._http._delete_custom_list(custom_list_id)

@require_authentication
async def follow_custom_list(self, custom_list_id: str, /) -> None:
"""|coro|
This method will follow a custom list within the MangaDex API.
Parameters
-----------
custom_list_id: :class:`str`
The UUID relating to the custom list we wish to follow.
Raises
-------
:exc:`BadRequest`
The request was malformed.
:exc:`Forbidden`
You are not authorized to follow this custom list.
:exc:`NotFound`
The specified custom list does not exist.
"""
await self._http._follow_custom_list(custom_list_id)

@require_authentication
async def unfollow_custom_list(self, custom_list_id: str, /) -> None:
"""|coro|
The method will unfollow a custom list within the MangaDex API.
Parameters
-----------
custom_list_id: :class:`str`
The UUID relating to the custom list we wish to unfollow.
Raises
-------
:exc:`Forbidden`
You are not authorized to unfollow this custom list.
:exc:`NotFound`
The specified custom list does not exist.
"""
await self._http._unfollow_custom_list(custom_list_id)

@require_authentication
async def get_my_custom_lists(self, *, limit: Optional[int] = 10, offset: int = 0) -> CustomListCollection:
"""|coro|
Expand Down
30 changes: 30 additions & 0 deletions hondana/custom_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,33 @@ async def delete_custom_list(self) -> None:
The custom list with this UUID was not found.
"""
await self._http._delete_custom_list(self.id)

@require_authentication
async def follow(self) -> None:
"""|coro|
The method will follow a custom list within the MangaDex API.
Raises
-------
:exc:`Forbidden`
You are not authorized to follow this custom list.
:exc:`NotFound`
The specified custom list does not exist.
"""
await self._http._follow_custom_list(self.id)

@require_authentication
async def unfollow(self) -> None:
"""|coro|
The method will unfollow a custom list within the MangaDex API.
Raises
-------
:exc:`Forbidden`
You are not authorized to unfollow this custom list.
:exc:`NotFound`
The specified custom list does not exist.
"""
await self._http._unfollow_custom_list(self.id)
20 changes: 20 additions & 0 deletions hondana/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,18 @@ def _check_if_following_manga(self, manga_id: str, /) -> Response[dict[Literal["
route = Route("GET", "/user/follows/manga/{manga_id}", manga_id=manga_id)
return self.request(route)

def _get_user_custom_list_follows(self, limit: int, offset: int) -> Response[custom_list.GetMultiCustomListResponse]:
route = Route("GET", "/user/follows/list")

limit, offset = calculate_limits(limit, offset, max_limit=100)
query: dict[str, Any] = {"limit": limit, "offset": offset}

return self.request(route, params=query)

def _check_if_following_list(self, custom_list_id: str, /) -> Response[dict[Literal["result"], Literal["ok"]]]:
route = Route("GET", "/user/follows/list/{custom_list_id}", custom_list_id=custom_list_id)
return self.request(route)

def _get_user_followed_manga(
self, limit: int, offset: int, includes: Optional[MangaIncludes]
) -> Response[manga.MangaSearchResponse]:
Expand Down Expand Up @@ -1501,6 +1513,14 @@ def _delete_custom_list(self, custom_list_id: str, /) -> Response[dict[Literal["
route = Route("DELETE", "/list/{custom_list_id}", custom_list_id=custom_list_id)
return self.request(route)

def _follow_custom_list(self, custom_list_id: str, /) -> Response[dict[Literal["result"], Literal["ok", "error"]]]:
route = Route("POST", "/list/{custom_list_id}/follow", custom_list_id=custom_list_id)
return self.request(route)

def _unfollow_custom_list(self, custom_list_id: str, /) -> Response[dict[Literal["result"], Literal["ok", "error"]]]:
route = Route("DELETE", "/list/{custom_list_id}/follow", custom_list_id=custom_list_id)
return self.request(route)

def _add_manga_to_custom_list(
self, *, custom_list_id: str, manga_id: str
) -> Response[dict[Literal["result"], Literal["ok", "error"]]]:
Expand Down

0 comments on commit 44d6374

Please sign in to comment.