Skip to content

Commit

Permalink
Merge pull request #25 from sab666/feature/community
Browse files Browse the repository at this point in the history
feat: community create
  • Loading branch information
db0 authored Jun 24, 2023
2 parents b413f1b + 26381f1 commit fc9b679
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pythorhead/community.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Optional

from pythorhead.requestor import Requestor, Request


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

def create(
self,
name: str,
title: str,
description: Optional[str] = None,
icon: Optional[str] = None,
nsfw: Optional[bool] = None,
posting_restricted_to_mods: Optional[bool] = None
) -> Optional[dict]:
"""
Create a community
Args:
name (str)
title (str)
description (str, optional): Defaults to None
icon (str, optional): Defaults to None
nsfw (bool, optional): Defaults to None
posting_restricted_to_mods (bool, optional): Defaults to None
Returns:
Optional[dict]: post data if successful
"""
new_community = {
"name": name,
"title": title,

}
if description is not None:
new_community['description'] = description
if icon is not None:
new_community['icon'] = icon
if nsfw is not None:
new_community['nsfw'] = nsfw
if [posting_restricted_to_mods] is not None:
new_community['[posting_restricted_to_mods]'] = [posting_restricted_to_mods]

return self._requestor.api(Request.POST, "/post", json=new_community)
2 changes: 2 additions & 0 deletions pythorhead/lemmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from pythorhead.comment import Comment
from pythorhead.community import Community
from pythorhead.image import Image
from pythorhead.post import Post
from pythorhead.private_message import PrivateMessage
Expand All @@ -20,6 +21,7 @@ def __init__(self, api_base_url: str) -> None:
self._requestor = Requestor()
self._requestor.set_domain(api_base_url)
self.post = Post(self._requestor)
self.community = Community(self._requestor)
self.comment = Comment(self._requestor)
self.site = Site(self._requestor)
self.user = User(self._requestor)
Expand Down

0 comments on commit fc9b679

Please sign in to comment.