1212
1313
1414class LoadingApiClient :
15+ """A client that allows python apps to easily communicate with the loading forums web api.
16+
17+ Some methods can be used anonymously, while others require the client to be authenticated
18+ with user credentials.
19+
20+ :param email: users email address (**optional**)
21+ :type email: str
22+ :param password: users password (**optional**)
23+ :type password: str
24+ """
25+
1526 def __init__ (self , email = None , password = None ):
1627 self ._cookies = None
1728
@@ -64,6 +75,11 @@ def _get_threads_in_forum_category(self, category_name, page):
6475 return {"code" : 200 , "message" : "OK" , "data" : data }
6576
6677 def get_profile (self ):
78+ """Returns authenticated users profile data
79+
80+ :rtype: dict
81+ """
82+
6783 url = f"{ API_URL } /{ API_VERSION } /users/profile"
6884 headers = {
6985 "User-Agent" : USER_AGENT ,
@@ -80,6 +96,13 @@ def get_profile(self):
8096 return response .json ()
8197
8298 def search (self , query ):
99+ """Returns posts that matches the query
100+
101+ :param query: Search query
102+ :type query: str
103+ :rtype: dict
104+ """
105+
83106 url = f"{ API_URL } /{ API_VERSION } /search/"
84107 headers = {
85108 "User-Agent" : USER_AGENT ,
@@ -98,6 +121,13 @@ def search(self, query):
98121 return data
99122
100123 def get_post (self , post_id ):
124+ """Returns a specific post
125+
126+ :param post_id: unique post id
127+ :type post_id: str
128+ :rtype: dict
129+ """
130+
101131 if not post_id :
102132 return {"code" : 404 , "message" : '"post_id" is not allowed to be empty' }
103133
@@ -118,7 +148,14 @@ def get_post(self, post_id):
118148 return response .json ()
119149
120150 def get_thread (self , thread_id , page = None ):
121- """Returns post data if the id belongs to a thread start."""
151+ """Returns all posts on a specific page from a specific thread
152+
153+ :param thread_id: unique thread_id
154+ :type thread_id: str
155+ :param page: thread page (**optional**)
156+ :type page: int
157+ :rtype: dict
158+ """
122159
123160 if not thread_id :
124161 return {"code" : 404 , "message" : '"thread_id" is not allowed to be empty' }
@@ -176,18 +213,43 @@ def get_thread(self, thread_id, page=None):
176213 return successful_response
177214
178215 def get_games (self , page = None ):
216+ """Retruns threads from a specific page in the game category
217+
218+ :param page: Game forum page
219+ :type page: int
220+ :rtype: dict
221+ """
222+
179223 category_name = "games"
180224 thread_data = self ._get_threads_in_forum_category (category_name , page )
181225
182226 return thread_data
183227
184228 def get_other (self , page = None ):
229+ """Retruns threads from a specific page in the other category
230+
231+ :param page: Other forum page
232+ :type page: int
233+ :rtype: dict
234+ """
235+
185236 category_name = "other"
186237 thread_data = self ._get_threads_in_forum_category (category_name , page )
187238
188239 return thread_data
189240
190241 def get_editorials (self , page = None , post_type = None , sort = None ):
242+ """Retruns threads from a specific page in the texts category
243+
244+ :param page: Texts forum page (**optional**)
245+ :type page: int
246+ :param post_type: Articles can be of post_type: "review", "opinion", "update", "podcast", or "conversation" (**optional**)
247+ :type post_type: str
248+ :param sort: Sort the returned threads by date by the default, but if "title" is used as a parameter it's sorted by thread title instead. (**optional**)
249+ :type sort: str
250+ :rtype: dict
251+ """
252+
191253 url = f"{ API_URL } /{ API_VERSION } /posts/"
192254 headers = {
193255 "User-Agent" : USER_AGENT ,
@@ -223,6 +285,15 @@ def get_editorials(self, page=None, post_type=None, sort=None):
223285 return {"code" : 200 , "message" : "OK" , "data" : data }
224286
225287 def create_post (self , thread_id , message ):
288+ """Create new post in a thread
289+
290+ :param thread_id: Unique thread id
291+ :type thread_id: str
292+ :param message: Text that can be formatted with markdown that will be posted in the thread
293+ :type message: str
294+ :rtype: dict
295+ """
296+
226297 if not thread_id :
227298 return {"code" : 400 , "message" : '"thread_id" is not allowed to be empty' }
228299
@@ -258,6 +329,14 @@ def create_post(self, thread_id, message):
258329 return response .json ()
259330
260331 def edit_post (self , post_id , message ):
332+ """Edit existing post in a thread
333+
334+ :param post_id: Unique post id
335+ :type post_id: str
336+ :param message: New text, that can be formatted with markdown, that will replace the old message
337+ :type message: str
338+ :rtype: dict
339+ """
261340 if not message :
262341 return {"code" : 400 , "message" : '"message" is not allowed to be empty' }
263342
@@ -293,6 +372,17 @@ def edit_post(self, post_id, message):
293372 return response .json ()
294373
295374 def create_thread (self , title , message , category_name , post_type = None ):
375+ """Create new thread in one of the forum categories
376+
377+ :param title: Thread title
378+ :type title: str
379+ :param message: Thread body that can be formatted with markdown
380+ :type message: str
381+ :param category_name: Forum category. Can be either "games" or "other".
382+ :type category_name: str
383+ :param post_type: Creates a "regular" thread by the default. (**optional**)
384+ :rtype: dict
385+ """
296386 if category_name not in ["games" , "other" ]:
297387 return {"code" : 400 , "message" : "Invalid forum category" }
298388
@@ -334,6 +424,15 @@ def create_thread(self, title, message, category_name, post_type=None):
334424 return response .json ()
335425
336426 def edit_thread (self , thread_id , message ):
427+ """Edit existing thread
428+
429+ :param thread_id: Unique thread id
430+ :type thread_id: str
431+ :param message: New text, that can be formatted with markdown, that will replace the old message
432+ :type message: str
433+ :rtype: dict
434+ """
435+
337436 thread_data = self .edit_post (thread_id , message )
338437
339438 if thread_data ["code" ] == 200 :
0 commit comments