From 813da013e8ab336c818be210b895fb7db1100481 Mon Sep 17 00:00:00 2001 From: Shorouq <94386553+i-be-snek@users.noreply.github.com> Date: Fri, 30 Jun 2023 00:02:08 +0200 Subject: [PATCH] Fix auth token bug + remove deprecated code (#2) --- pythorhead/auth.py | 3 --- pythorhead/mention.py | 9 ++++----- pythorhead/private_message.py | 12 ++++++------ pythorhead/requestor.py | 3 --- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pythorhead/auth.py b/pythorhead/auth.py index e9cb29b..0e74992 100644 --- a/pythorhead/auth.py +++ b/pythorhead/auth.py @@ -7,9 +7,6 @@ class Authentication: def set_token(self, token: str) -> None: self.token = token - - def get_token(self) -> Optional[str]: - return self.token def set_api_base_url(self, base_url: str) -> None: self.api_url = f"{base_url}/api/v3" diff --git a/pythorhead/mention.py b/pythorhead/mention.py index b591a5b..0f42d77 100644 --- a/pythorhead/mention.py +++ b/pythorhead/mention.py @@ -26,9 +26,8 @@ def list( Returns: dict? mentions response """ - - params = {"auth": self._requestor.get_auth_token()} - json: dict[str, Any] = {key: value for key, value in locals( + unread_only = 'true' if unread_only else 'false' + + params: dict[str, Any] = {key: value for key, value in locals( ).items() if value is not None and key != "self"} - - return self._requestor.api(Request.GET, "/user/mention", params=params, json=json) + return self._requestor.api(Request.GET, "/user/mention", params=params) diff --git a/pythorhead/private_message.py b/pythorhead/private_message.py index a45c117..ed79edf 100644 --- a/pythorhead/private_message.py +++ b/pythorhead/private_message.py @@ -30,7 +30,7 @@ def list( self, unread_only: bool, page: int, - limit: int + limit: int = 20 ) -> Optional[dict]: """ List private messages @@ -38,12 +38,12 @@ def list( Args: unread_only (bool). page (int). - limit (int). + limit (int) with a max of 50. Returns: dict? private message response """ - json: dict[str, Any] = {key: value for key, value in locals().items() if value is not None and key != "self"} - params = {"auth": self._requestor.get_auth_token()} - - return self._requestor.api(Request.GET, "/private_message/list", params=params, json=json) + limit = 50 if limit > 50 else limit + unread_only = 'true' if unread_only else 'false' + params: dict[str, Any] = {key: value for key, value in locals().items() if value is not None and key != "self"} + return self._requestor.api(Request.GET, "/private_message/list", params=params) diff --git a/pythorhead/requestor.py b/pythorhead/requestor.py index 608c035..4d40503 100644 --- a/pythorhead/requestor.py +++ b/pythorhead/requestor.py @@ -97,9 +97,6 @@ def log_in(self, username_or_email: str, password: str) -> bool: if data := self.api(Request.POST, "/user/login", json=payload): self._auth.set_token(data["jwt"]) return self._auth.token is not None - - def get_auth_token(self) -> Optional[str]: - return self._auth.get_token() def log_out(self) -> None: self._auth.token = None