@@ -65,6 +65,12 @@ def call_api(self, method: LemmyApiMethod, endpoint: str, params: dict = None, h
6565 self ._logger .debug ("LemmyLib call_api" )
6666 if headers is None :
6767 headers = self .get_headers ()
68+ if data is not None :
69+ for key , value in data .copy ().items ():
70+ if value is None :
71+ data .pop (key )
72+ if isinstance (value , Enum ):
73+ data [key ] = value .value
6874 if params is None :
6975 params = {}
7076 else :
@@ -75,6 +81,8 @@ def call_api(self, method: LemmyApiMethod, endpoint: str, params: dict = None, h
7581 params .pop (key )
7682 if isinstance (value , bool ):
7783 params [key ] = str (value ).lower ()
84+ if isinstance (value , Enum ):
85+ params [key ] = value .value
7886
7987 if self ._url is None :
8088 raise Exception ("LemmyLib: URL not set" )
@@ -201,15 +209,14 @@ def list_comments(self, page: int = 1, post_id: int | None = None, sort: LemmyPo
201209 if post_id is None and community_id is None and community_name is None and user_id is None and user_name is None :
202210 raise Exception ("LemmyLib: Either post_id, community_id, community_name, user_id or user_name must be set" )
203211
204- return self .call_api (LemmyApiMethod .GET , f'comments' ,
205- params = {'page' : page , 'post_id' : post_id , 'sort' : sort .value ,
206- 'type_' : listing_type .value ,
207- 'parent_id' : parent_id ,
208- 'community_id' : community_id ,
209- 'community_name' : community_name ,
210- 'user_id' : user_id ,
211- 'user_name' : user_name ,
212- 'saved_only' : saved_only })
212+ return self .call_api (LemmyApiMethod .GET , f'comments' , params = {'page' : page , 'post_id' : post_id , 'sort' : sort ,
213+ 'type_' : listing_type .value ,
214+ 'parent_id' : parent_id ,
215+ 'community_id' : community_id ,
216+ 'community_name' : community_name ,
217+ 'user_id' : user_id ,
218+ 'user_name' : user_name ,
219+ 'saved_only' : saved_only })
213220
214221 def list_posts (self ,
215222 page : int | None = None , page_cursor : int | None = None , sort : LemmyPostSort = None ,
@@ -220,7 +227,7 @@ def list_posts(self,
220227 self ._logger .debug ("LemmyLib list_posts" )
221228
222229 return self .call_api (LemmyApiMethod .GET , f'posts' ,
223- params = {'page_cursor' : page_cursor , 'sort' : sort . value , 'type_' : listing_type . value ,
230+ params = {'page_cursor' : page_cursor , 'sort' : sort , 'type_' : listing_type ,
224231 'community_id' : community_id ,
225232 'page' : page ,
226233 'community_name' : community_name ,
0 commit comments