Skip to content

Commit

Permalink
Merge pull request #10 from amarpersaud/Refactoring
Browse files Browse the repository at this point in the history
Refactor classes into types submodule
  • Loading branch information
amarpersaud authored Jun 25, 2023
2 parents ede5b56 + 4534837 commit 82fb6f3
Show file tree
Hide file tree
Showing 27 changed files with 304 additions and 122 deletions.
2 changes: 1 addition & 1 deletion build_and_install.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
py -m build
py -m pip install dist/jplaw-0.1.2.tar.gz
py -m pip install dist/jplaw-0.1.3.tar.gz
2 changes: 1 addition & 1 deletion build_and_install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
python3 -m build
python3 -m pip install dist/jplaw-0.1.2.tar.gz
python3 -m pip install dist/jplaw-0.1.3.tar.gz
2 changes: 1 addition & 1 deletion jplaw/api_paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .http_type import HttpType
from .types.http_type import HttpType

API_VERSION = "/api/v3"
API_PATH = {
Expand Down
33 changes: 17 additions & 16 deletions jplaw/comment.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .requestor import Requestor
from .api_paths import *
from .listing_type import ListingType
from .comment_sort_type import CommentSortType
from .types.listing_type import ListingType
from .types.comment_sort_type import CommentSortType

class Comment():
def __init__(self, _req: Requestor):
self._req = _req

def createComment(self, post_id:int, content:str, parent_id:int=None, language_id:str=None, instance:str=None, auth_token:str=None):
def create(self, post_id:int, content:str, parent_id:int=None, language_id:str=None, instance:str=None, auth_token:str=None):
form = {
"content": content,
"post_id": post_id,
Expand All @@ -20,7 +20,7 @@ def createComment(self, post_id:int, content:str, parent_id:int=None, language_i

return res["comment_view"]

def likeComment(self, comment_id:int, score:int=1, instance:str=None, auth_token:str=None):
def like(self, comment_id:int, score:int=1, instance:str=None, auth_token:str=None):
if(score > 1):
score = 1
if(score < -1):
Expand All @@ -32,23 +32,23 @@ def likeComment(self, comment_id:int, score:int=1, instance:str=None, auth_token
res = self._req.lemmyRequest("likeComment", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["comment_view"]

def createCommentReport(self, comment_id:int, reason:str, instance:str=None, auth_token:str=None):
def report(self, comment_id:int, reason:str, instance:str=None, auth_token:str=None):
form = {
"comment_id": comment_id,
"reason": reason
}
res = self._req.lemmyRequest("createCommentReport", instance=instance, form=form, auth=True, auth_token=auth_token)
return res

def deleteComment(self, comment_id:int, deleted:bool=True, instance:str=None, auth_token:str=None):
def delete(self, comment_id:int, deleted:bool=True, instance:str=None, auth_token:str=None):
form = {
"comment_id": comment_id,
"deleted": deleted
}
res = self._req.lemmyRequest("deleteComment", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["comment_view"]

def removeComment(self, comment_id:int, mod_person_id:int, when_:str, removed:bool=True, reason:str=None, instance:str=None, auth_token:str=None):
def remove(self, comment_id:int, mod_person_id:int, when_:str, removed:bool=True, reason:str=None, instance:str=None, auth_token:str=None):
form = {
"comment_id": comment_id,
"mod_person_id": mod_person_id,
Expand All @@ -61,15 +61,15 @@ def removeComment(self, comment_id:int, mod_person_id:int, when_:str, removed:bo
res = self._req.lemmyRequest("removeComment", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res["comment_view"]

def distinguishComment(self, comment_id:int, distinguished:bool=True, instance:str=None, auth_token:str=None):
def distinguish(self, comment_id:int, distinguished:bool=True, instance:str=None, auth_token:str=None):
form = {
"comment_id": comment_id,
"distinguished": distinguished,
}
res = self._req.lemmyRequest("distinguishComment", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["comment_view"]

def editComment(self, comment_id:int, content:str=None, language_id:str=None, form_id:str=None, instance:str=None, auth_token:str=None):
def edit(self, comment_id:int, content:str=None, language_id:str=None, form_id:str=None, instance:str=None, auth_token:str=None):
form = {
"comment_id": comment_id
}
Expand All @@ -80,14 +80,15 @@ def editComment(self, comment_id:int, content:str=None, language_id:str=None, fo
}
res = self._req.lemmyRequest("editComment", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res["comment_view"]

def getComment(self, comment_id:int, instance:str=None, auth:bool=True, auth_token:str=None):
def get(self, comment_id:int, instance:str=None, auth:bool=True, auth_token:str=None):
form = {
"comment_id": comment_id
}
res = self._req.lemmyRequest("getComment", instance=instance, form=form, optional=optional, auth=auth, auth_token=auth_token)
return res["comment_view"]
def getComments(self,

def list(self,
comment_type:ListingType=None,
sort:CommentSortType=None,
max_depth:int=None,
Expand Down Expand Up @@ -119,7 +120,7 @@ def getComments(self,
res = self._req.lemmyRequest("getComments", instance=instance, form=form, optional=optional, auth=auth, auth_token=auth_token)
return res["comment_view"]

def listCommentReports(self, page:int=None, limit:int=None, unresolved_only:bool=None, community_id:int=None, instance:str=None, auth_token:str=None):
def listReports(self, page:int=None, limit:int=None, unresolved_only:bool=None, community_id:int=None, instance:str=None, auth_token:str=None):
form = {}
optional={
"page" : page ,
Expand All @@ -130,23 +131,23 @@ def listCommentReports(self, page:int=None, limit:int=None, unresolved_only:bool
res = self._req.lemmyRequest("listCommentReports", instance=instance, form=form, optional=optional, auth=auth, auth_token=auth_token)
return

def markCommentReplyAsRead(self, comment_reply_id:int, read:bool=True, instance:str=None, auth_token:str=None):
def markReplyAsRead(self, comment_reply_id:int, read:bool=True, instance:str=None, auth_token:str=None):
form = {
"comment_reply_id" : comment_reply_id ,
"read" : read ,
}
res = self._req.lemmyRequest("markCommentReplyAsRead", instance=instance, form=form, auth=auth, auth_token=auth_token)
return

def resolveCommentReport(self, report_id:int, resolved:bool=True, instance:str=None, auth_token:str=None):
def resolveReport(self, report_id:int, resolved:bool=True, instance:str=None, auth_token:str=None):
form = {
"report_id" : report_id ,
"resolved" : resolved ,
}
res = self._req.lemmyRequest("resolveCommentReport", instance=instance, form=form, auth=auth, auth_token=auth_token)
return

def saveComment(self, comment_id:int, save:bool=True, instance:str=None, auth_token:str=None):
def save(self, comment_id:int, save:bool=True, instance:str=None, auth_token:str=None):
form = {
"comment_id" : comment_id ,
"save" : save,
Expand Down
32 changes: 12 additions & 20 deletions jplaw/community.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
from .requestor import Requestor, HttpType
from .requestor import Requestor
from .api_paths import *
from typing import List

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

def getCommunity(self, name:str, instance:str=None, auth:bool=True, auth_token:str=None):
def get(self, name:str, instance:str=None, auth:bool=True, auth_token:str=None):
form = {
"name": name
}
res = self._req.lemmyRequest("getCommunity", instance=instance, form=form, auth=auth, auth_token=auth_token)
return res["community_view"]

def listCommunities(self, instance:str=None, auth:bool=True, auth_token:str=None):
def list(self, instance:str=None, auth:bool=True, auth_token:str=None):
form={}
res = self._req.lemmyRequest("listCommunities", instance=instance, form=form, auth=auth, auth_token=auth_token)
return res["communities"]

def followCommunity(self, community_id:int, follow:bool=True, instance:str=None, auth_token:str=None):
def follow(self, community_id:int, follow:bool=True, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"follow": follow
}
res = self._req.lemmyRequest("followCommunity", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["community_view"]
def addModToCommunity(self, community_id:int, person_id:int, added:bool=True, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"person_id": person_id,
"added": added,
}
res = self._req.lemmyRequest("addModToCommunity", instance=instance, form=form, auth=True, auth_token=auth_token)
return res
def addModToCommunity(self, community_id:int, person_id:int, added:bool=True, instance:str=None, auth_token:str=None):
def addMod(self, community_id:int, person_id:int, added:bool=True, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"person_id": person_id,
Expand All @@ -42,7 +34,7 @@ def addModToCommunity(self, community_id:int, person_id:int, added:bool=True, in
res = self._req.lemmyRequest("addModToCommunity", instance=instance, form=form, auth=True, auth_token=auth_token)
return res

def banFromCommunity(self, community_id:int, person_id:int, ban:bool, remove_data:bool=None, reason:str=None, expires:int=None, instance:str=None, auth_token:str=None):
def banPerson(self, community_id:int, person_id:int, ban:bool, remove_data:bool=None, reason:str=None, expires:int=None, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"person_id": person_id,
Expand All @@ -56,15 +48,15 @@ def banFromCommunity(self, community_id:int, person_id:int, ban:bool, remove_dat
res = self._req.lemmyRequest("banFromCommunity", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res

def blockCommunity(self, community_id:int, block:bool=True, instance:str=None, auth_token:str=None):
def block(self, community_id:int, block:bool=True, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"block": block,
}
res = self._req.lemmyRequest("blockCommunity", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["community_view"]

def createCommunity(self, name:str, title:str, description:str=None, icon:str=None, banner:str=None, nsfw:bool=None, posting_restricted_to_mods:bool=None, discussion_languages:List[str]=None, instance:str=None, auth_token:str=None):
def create(self, name:str, title:str, description:str=None, icon:str=None, banner:str=None, nsfw:bool=None, posting_restricted_to_mods:bool=None, discussion_languages:List[str]=None, instance:str=None, auth_token:str=None):
form={
"name": name,
"title": title,
Expand All @@ -80,15 +72,15 @@ def createCommunity(self, name:str, title:str, description:str=None, icon:str=No
res = self._req.lemmyRequest("createCommunity", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res["community_view"]

def deleteCommunity(self, community_id:int, deleted:bool=True, instance:str=None, auth_token:str=None):
def delete(self, community_id:int, deleted:bool=True, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"deleted": deleted,
}
res = self._req.lemmyRequest("deleteCommunity", instance=instance, form=form, auth=True, auth_token=auth_token)
return res["community_view"]

def editCommunity(self, community_id:int, title:str=None, description:str=None, icon:str=None, banner:str=None, nsfw:bool=None, posting_restricted_to_mods:bool=None, discussion_languages:List[str]=None, instance:str=None, auth_token:str=None):
def edit(self, community_id:int, title:str=None, description:str=None, icon:str=None, banner:str=None, nsfw:bool=None, posting_restricted_to_mods:bool=None, discussion_languages:List[str]=None, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
}
Expand All @@ -104,7 +96,7 @@ def editCommunity(self, community_id:int, title:str=None, description:str=None,
res = self._req.lemmyRequest("createCommunity", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res["community_view"]

def removeCommunity(self, community_id:int, removed:bool=True, reason:str=None, expires:int=None, instance:str=None, auth_token:str=None):
def remove(self, community_id:int, removed:bool=True, reason:str=None, expires:int=None, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"removed":removed,
Expand All @@ -116,7 +108,7 @@ def removeCommunity(self, community_id:int, removed:bool=True, reason:str=None,
res = self._req.lemmyRequest("removeCommunity", instance=instance, form=form, optional=optional, auth=True, auth_token=auth_token)
return res["community_view"]

def transferCommunity(self, community_id:int, person_id:int, instance:str=None, auth_token:str=None):
def transfer(self, community_id:int, person_id:int, instance:str=None, auth_token:str=None):
form={
"community_id": community_id,
"person_id":person_id,
Expand Down
7 changes: 3 additions & 4 deletions jplaw/lemmy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .requestor import Requestor, HttpType
from enum import *
from .requestor import Requestor
from .comment import Comment
from .community import Community
from .post import Post
Expand Down Expand Up @@ -40,12 +39,12 @@ def resolveObject(self, obj, instance=None, auth_token=None):
form={
"q": obj
}
res = self._req.lemmyRequest(HttpType.GET, "resolveObject", instance=instance, form=form, auth_token=auth_token)
res = self._req.lemmyRequest("resolveObject", instance=instance, form=form, auth_token=auth_token)
return res

def search(self, term, instance=None, auth_token=None):
form={
"q": term
}
res = self._req.request(HttpType.GET, "search", instance=instance, auth_token=auth_token, form=form)
res = self._req.request("search", instance=instance, auth_token=auth_token, form=form)
return res
1 change: 0 additions & 1 deletion jplaw/listing_type.py

This file was deleted.

1 change: 0 additions & 1 deletion jplaw/modlog_action_type.py

This file was deleted.

Loading

0 comments on commit 82fb6f3

Please sign in to comment.