Skip to content

Commit

Permalink
Fix auth token bug + remove deprecated code (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
i-be-snek authored Jun 29, 2023
1 parent f2e84b9 commit 813da01
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
3 changes: 0 additions & 3 deletions pythorhead/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions pythorhead/mention.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions pythorhead/private_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ def list(
self,
unread_only: bool,
page: int,
limit: int
limit: int = 20
) -> Optional[dict]:
"""
List private messages
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)
3 changes: 0 additions & 3 deletions pythorhead/requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 813da01

Please sign in to comment.