Skip to content

Commit

Permalink
API version 5.3.14 - updates to scanlation groups, small changes to r…
Browse files Browse the repository at this point in the history
…eports for authors and group filter on manga list.
  • Loading branch information
AbstractUmbra committed Nov 29, 2021
1 parent 1e03100 commit 3a68c6d
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target/
*.jpg
*.gif
*.jpeg
_*.py
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ Utilities

.. autoclass:: hondana.utils.CustomRoute
:members:

.. autoclass:: hondana.utils.MANGADEX_TIME_REGEX
:members:
2 changes: 2 additions & 0 deletions docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ Report

Scanlator Group
---------------
.. autoclass:: ScanlationGroupOrderQuery

.. autoclass:: ScanlatorGroupIncludes
:members:
:undoc-members:
Expand Down
92 changes: 81 additions & 11 deletions hondana/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ async def manga_list(
order: Optional[manga.MangaOrderQuery] = None,
includes: Optional[list[manga.MangaIncludes]] = ["author", "artist", "cover_art", "manga"],
has_available_chapters: Optional[bool] = None,
group: Optional[str] = None,
) -> list[Manga]:
"""|coro|
Expand Down Expand Up @@ -406,6 +407,8 @@ async def manga_list(
Defaults to these values.
has_available_chapters: Optional[:class:`bool`]
Filter the manga list to only those that have chapters.
group: Optional[:class:`str`]
Filter the manga list to only those uploaded by this group.
Raises
-------
Expand Down Expand Up @@ -441,6 +444,7 @@ async def manga_list(
order=order,
includes=includes,
has_available_chapters=has_available_chapters,
group=group,
)

return [Manga(self._http, item) for item in data["data"]]
Expand Down Expand Up @@ -1668,6 +1672,8 @@ async def scanlation_group_list(
offset: int = 0,
ids: Optional[list[str]] = None,
name: Optional[str] = None,
focused_language: Optional[common.LanguageCode] = None,
order: Optional[scanlator_group.ScanlationGroupOrderQuery] = None,
includes: Optional[list[scanlator_group.ScanlatorGroupIncludes]] = ["leader", "member"],
) -> list[ScanlatorGroup]:
"""|coro|
Expand All @@ -1684,6 +1690,10 @@ async def scanlation_group_list(
A list of scanlator group UUID(s) to limit the request to.
name: Optional[:class:`str`]
A name to limit the request to.
focused_language: Optional[:class:`~hondana.types.LanguageCode`]
A focused language to limit the request to.
order: Optional[:class:`~hondana.types.ScanlationGroupOrderQuery`]
An ordering statement for the request.
includes: Optional[List[:class:`~hondana.types.ScanlatorGroupIncludes`]]
An optional list of includes to request increased payloads during the request.
Expand All @@ -1702,7 +1712,9 @@ async def scanlation_group_list(
limit = min(max(1, limit), 100)
offset = max(offset, 0)

data = await self._http._scanlation_group_list(limit=limit, offset=offset, ids=ids, name=name, includes=includes)
data = await self._http._scanlation_group_list(
limit=limit, offset=offset, ids=ids, name=name, focused_language=focused_language, order=order, includes=includes
)

return [ScanlatorGroup(self._http, item) for item in data["data"]]

Expand Down Expand Up @@ -2466,7 +2478,18 @@ async def get_custom_list_manga_feed(

@require_authentication
async def create_scanlation_group(
self, *, name: str, leader: Optional[str] = None, members: Optional[list[str]] = None, version: Optional[int] = None
self,
*,
name: str,
website: Optional[str] = None,
irc_server: Optional[str] = None,
irc_channel: Optional[str] = None,
discord: Optional[str] = None,
contact_email: Optional[str] = None,
description: Optional[str] = None,
twitter: Optional[str] = None,
inactive: Optional[bool] = None,
publish_delay: Optional[str] = None,
) -> ScanlatorGroup:
"""|coro|
Expand All @@ -2476,12 +2499,29 @@ async def create_scanlation_group(
-----------
name: :class:`str`
The name of the scanlation group.
leader: Optional[:class:`str`]
The UUID relating to the leader of the scanlation group.
members: Optional[List[:class:`str`]]
A list of UUIDs for the members of the scanlation group.
version: Optional[:class:`int`]
The version revision of this scanlation group.
website: Optional[:class:`str`]
The scanlation group's website, if any.
irc_server: Optional[:class:`str`]
The scanlation group's irc server, if any.
irc_channel: Optional[:class:`str`]
The scanlation group's irc channel, if any.
discord: Optional[:class:`str`]
The scanlation group's discord server, if any.
contact_email: Optional[:class:`str`]
The scanlation group's email, if any.
description: Optional[:class:`str`]
The scanlation group's description, if any.
twitter: Optional[:class:`str`]
The scanlation group's twitter url, if any.
inactive: Optional[:class:`bool`]
If the scanlation group is inactive or not.
publish_delay: Optional[:class:`str`]
If the scanlation group's releases are published on a delay.
.. note::
The ``publish_delay`` parameter must match the :class:`hondana.utils.MANGADEX_TIME_REGEX` pattern.
Raises
-------
Expand All @@ -2495,7 +2535,18 @@ async def create_scanlation_group(
:class:`ScanlatorGroup`
The group returned from the API on creation.
"""
data = await self._http._create_scanlation_group(name=name, leader=leader, members=members, version=version)
data = await self._http._create_scanlation_group(
name=name,
website=website,
irc_server=irc_server,
irc_channel=irc_channel,
discord=discord,
contact_email=contact_email,
description=description,
twitter=twitter,
inactive=inactive,
publish_delay=publish_delay,
)
return ScanlatorGroup(self._http, data["data"])

async def get_scanlation_group(
Expand Down Expand Up @@ -2538,15 +2589,19 @@ async def update_scanlation_group(
/,
*,
name: Optional[str] = None,
leader: Optional[str] = MISSING,
leader: Optional[str] = None,
members: Optional[list[str]] = None,
website: Optional[str] = MISSING,
irc_server: Optional[str] = MISSING,
irc_channel: Optional[str] = MISSING,
discord: Optional[str] = MISSING,
contact_email: Optional[str] = MISSING,
description: Optional[str] = MISSING,
twitter: Optional[str] = MISSING,
focused_languages: list[common.LanguageCode] = MISSING,
inactive: Optional[bool] = None,
locked: Optional[bool] = None,
publish_delay: Optional[str] = MISSING,
version: int,
) -> ScanlatorGroup:
"""|coro|
Expand Down Expand Up @@ -2575,16 +2630,27 @@ async def update_scanlation_group(
The contact email to update the group with.
description: Optional[:class:`str`]
The new description to update the group with.
twitter: Optional[:class:`str`]
The new twitter url to update the group with.
focused_language: Optional[List[:class:`~hondana.types.LanguageCode`]]
The new list of language codes to update the group with.
inactive: Optional[:class:`bool`]
If the group is inactive or not.
locked: Optional[:class:`bool`]
Update the lock status of this scanlator group.
publish_delay: Optional[:class:`str`]
The publish delay to add to all group releases.
version: :class:`int`
The version revision of this scanlator group.
.. note::
The ``leader``, ``website``, ``irc_server``, ``irc_channel``, ``discord``, ``contact_email``, and ``description``
The ``website``, ``irc_server``, ``irc_channel``, ``discord``, ``contact_email``, ``description``, ``twitter``, ``focused_language`` and ``publish_delay``
keys are all nullable in the API. To do so please pass ``None`` to these keys.
.. note::
The ``publish_delay`` parameter must match the :class:`hondana.utils.MANGADEX_TIME_REGEX` pattern.
Raises
-------
:exc:`BadRequest`
Expand All @@ -2610,7 +2676,11 @@ async def update_scanlation_group(
discord=discord,
contact_email=contact_email,
description=description,
twitter=twitter,
focused_languages=focused_languages,
inactive=inactive,
locked=locked,
publish_delay=publish_delay,
version=version,
)

Expand Down
75 changes: 66 additions & 9 deletions hondana/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ def _manga_list(
order: Optional[manga.MangaOrderQuery],
includes: Optional[list[manga.MangaIncludes]],
has_available_chapters: Optional[bool],
group: Optional[str],
) -> Response[manga.MangaSearchResponse]:
route = Route("GET", "/manga")

Expand Down Expand Up @@ -621,6 +622,9 @@ def _manga_list(
if has_available_chapters is not None:
query["hasAvailableChapters"] = has_available_chapters

if group:
query["group"] = group

return self.request(route, params=query)

def _create_manga(
Expand Down Expand Up @@ -1206,7 +1210,9 @@ def _scanlation_group_list(
offset: int,
ids: Optional[list[str]],
name: Optional[str],
focused_language: Optional[common.LanguageCode],
includes: Optional[list[scanlator_group.ScanlatorGroupIncludes]],
order: Optional[scanlator_group.ScanlationGroupOrderQuery],
) -> Response[scanlator_group.GetMultiScanlationGroupResponse]:
route = Route("GET", "/group")

Expand All @@ -1220,9 +1226,15 @@ def _scanlation_group_list(
if name:
query["name"] = name

if focused_language:
query["focusedLanguage"] = focused_language

if includes:
query["includes"] = includes

if order:
query["order"] = order

return self.request(route, params=query)

def _user_list(
Expand Down Expand Up @@ -1508,20 +1520,49 @@ def _custom_list_manga_feed(
return self.request(route, params=query)

def _create_scanlation_group(
self, *, name: str, leader: Optional[str], members: Optional[list[str]], version: Optional[int]
self,
*,
name: str,
website: Optional[str],
irc_server: Optional[str],
irc_channel: Optional[str],
discord: Optional[str],
contact_email: Optional[str],
description: Optional[str],
twitter: Optional[str],
inactive: Optional[bool],
publish_delay: Optional[str],
) -> Response[scanlator_group.GetSingleScanlationGroupResponse]:
route = Route("POST", "/group")

query: dict[str, Any] = {"name": name}

if leader:
query["leader"] = leader
if website:
query["website"] = website

if members:
query["members"] = members
if irc_server:
query["ircServer"] = irc_server

if version:
query["version"] = version
if irc_channel:
query["ircChannel"] = irc_channel

if discord:
query["discord"] = discord

if contact_email:
query["contactEmail"] = contact_email

if description:
query["description"] = description

if twitter:
query["twitter"] = twitter

if isinstance(inactive, bool):
query["inactive"] = inactive

if publish_delay:
query["publishDelay"] = publish_delay

return self.request(route, json=query)

Expand All @@ -1546,7 +1587,11 @@ def _update_scanlation_group(
discord: Optional[str],
contact_email: Optional[str],
description: Optional[str],
twitter: Optional[str],
focused_languages: Optional[list[common.LanguageCode]],
inactive: Optional[bool],
locked: Optional[bool],
publish_delay: Optional[str],
version: int,
) -> Response[scanlator_group.GetSingleScanlationGroupResponse]:
route = Route("PUT", "/group/{scanlation_group_id}", scanlation_group_id=scanlation_group_id)
Expand Down Expand Up @@ -1580,8 +1625,20 @@ def _update_scanlation_group(
if description is not MISSING:
query["description"] = description

if locked:
query["locked"] = str(locked).lower()
if twitter is not MISSING:
query["twitter"] = twitter

if focused_languages is not MISSING:
query["focusedLanguages"] = focused_languages

if publish_delay is not MISSING:
query["publishDelay"] = publish_delay

if isinstance(inactive, bool):
query["inactive"] = inactive

if isinstance(locked, bool):
query["locked"] = locked

return self.request(route, json=query)

Expand Down
2 changes: 1 addition & 1 deletion hondana/types/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)


ReportCategory = Literal["manga", "chapter", "scanlation_group", "user"]
ReportCategory = Literal["manga", "chapter", "scanlation_group", "user", "author"]


class GetReportReasonAttributesResponse(TypedDict):
Expand Down
10 changes: 10 additions & 0 deletions hondana/types/scanlator_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@


__all__ = (
"ScanlationGroupOrderQuery",
"ScanlatorGroupIncludes",
"ScanlationGroupAttributesResponse",
"ScanlationGroupResponse",
Expand All @@ -42,6 +43,15 @@
ScanlatorGroupIncludes = Literal["leader", "member"]


class ScanlationGroupOrderQuery(TypedDict, total=False):
name: Literal["asc", "desc"]
createdAt: Literal["asc", "desc"]
updatedAt: Literal["asc", "desc"]
followedCount: Literal["asc", "desc"]
relevance: Literal["asc", "desc"]
latestUploadedChapter: Literal["asc", "desc"]


class ScanlationGroupAttributesResponse(TypedDict):
"""
name: :class:`str`
Expand Down
Loading

0 comments on commit 3a68c6d

Please sign in to comment.