Exemple #1
0
    def fetch_followers(self, offset=None):
        """
        Fetch the users that are following the requesting user.

        :param int offset: The number of users to offset by.

        :return: A dictionary containing the a list of previews for the users that
            follow the the requesting user and and the offset needed to get the next
            page of user previews. If there is no next page, ``offset`` will be
            ``None``.

        .. code-block:: python

           {
               'user_previews': [  # List of bookmark tags.
                   {
                       'illustrations': [  # Their 3 most recent illustrations.
                           Illustration,
                           Illustration,
                           Illustration,
                       ],
                       'is_muted': False,  # Are they muted?
                       'novels': [   # Preview of their novels.
                           Novel,
                           Novel,
                           Novel,
                       ],
                       'user': User,  # Basic information about the user.
                   },
                   ...
               ],
               'next': 30,  # Offset for the next page of user previews.
           }

        :rtype: dict

        :raises requests.RequestException: If the request fails.
        :raises BadApiResponse: If the response is not valid JSON.
        """
        response = self._request_json(
            method="get",
            url=f"{BASE_URL}/v1/user/follower",
            params={
                "offset": offset,
                "filter": FILTER
            },
        )

        return {
            "user_previews": [{
                "illustrations": [
                    Illustration(**illust, client=self)
                    for illust in preview["illusts"]
                ],
                "is_muted":
                preview["is_muted"],
                "novels":
                [Novel(**novel, client=self) for novel in preview["novels"]],
                "user":
                User(**preview["user"]),
            } for preview in response["user_previews"]],
            "next":
            parse_qs(response["next_url"], param="offset"),
        }
Exemple #2
0
    def fetch_following(self,
                        user_id,
                        visibility=Visibility.PUBLIC,
                        offset=None):
        """
        Fetch the users that a user is following. A maximum of 30 users are returned in
        a response.

        :param int user_id: The ID of the user.
        :param Visibility visibility: The visibility of the followed users. Applies only
            to one's own follows. If ``Visibility.PRIVATE`` is applied to another user,
            their publicly followed users will be returned.
        :param int offset: The number of users to offset by.

        :return: A dictionary containing the a list of previews for the followed users
            and and the offset needed to get the next page of user previews. If there is
            no next page, ``offset`` will be ``None``.

        .. code-block:: python

           {
               'user_previews': [  # List of bookmark tags.
                   {
                       'illustrations': [  # Their 3 most recent illustrations.
                           Illustration,
                           Illustration,
                           Illustration,
                       ],
                       'is_muted': False,  # Are they muted?
                       'novels': [   # Their 3 most recent novels.
                           Novel,
                           Novel,
                           Novel,
                       ],
                       'user': User,  # Basic information about the user.
                   },
                   ...
               ],
               'next': 30,  # Offset for the next page of user previews.
           }

        :rtype: dict

        :raises requests.RequestException: If the request fails.
        :raises BadApiResponse: If the response is not valid JSON.
        """
        response = self._request_json(
            method="get",
            url=f"{BASE_URL}/v1/user/following",
            params={
                "user_id": user_id,
                "restrict": visibility.value,
                "offset": offset,
            },
        )

        return {
            "user_previews": [{
                "illustrations": [
                    Illustration(**illust, client=self)
                    for illust in preview["illusts"]
                ],
                "is_muted":
                preview["is_muted"],
                "novels":
                [Novel(**novel, client=self) for novel in preview["novels"]],
                "user":
                User(**preview["user"]),
            } for preview in response["user_previews"]],
            "next":
            parse_qs(response["next_url"], param="offset"),
        }