Skip to content

Commit

Permalink
Merge pull request #34 from i-be-snek/main
Browse files Browse the repository at this point in the history
✨ Add list functions for Mentions and Private Messages
  • Loading branch information
NicKoehler authored Jun 30, 2023
2 parents 7c2a751 + 1febafd commit ccb9293
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pythorhead/lemmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pythorhead.requestor import Requestor
from pythorhead.site import Site
from pythorhead.user import User
from pythorhead.mention import Mention


class Lemmy:
Expand All @@ -25,6 +26,7 @@ def __init__(self, api_base_url: str) -> None:
self.user = User(self._requestor)
self.private_message = PrivateMessage(self._requestor)
self.image = Image(self._requestor)
self.mention = Mention(self._requestor)

@property
def nodeinfo(self):
Expand Down
33 changes: 33 additions & 0 deletions pythorhead/mention.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Any, Optional
from pythorhead.requestor import Request, Requestor
from pythorhead.types import SortType


class Mention:
def __init__(self, _requestor: Requestor):
self._requestor = _requestor

def list(
self,
unread_only: bool,
sort: Optional[SortType] = None,
page: Optional[int] = None,
limit: Optional[int] = None,
) -> Optional[dict]:
"""
List all user mentions
Args:
unread_only (bool).
sort? (SortType)
page? (int).
limit? (int)
Returns:
dict? mentions response
"""
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)
22 changes: 22 additions & 0 deletions pythorhead/private_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,25 @@ def create(
return self._requestor.api(Request.POST, "/private_message", json=params)

__call__ = create

def list(
self,
unread_only: bool,
page: int,
limit: int = 20
) -> Optional[dict]:
"""
List private messages
Args:
unread_only (bool).
page (int).
limit (int) with a max of 50, defaults to 20.
Returns:
dict? private message response
"""
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)

0 comments on commit ccb9293

Please sign in to comment.