44from imgur .models .account import Account
55from imgur .models .comment import Comment
66from helpers .error import ImgurClientError
7+ from helpers .format import build_comment_tree
78from imgur .models .gallery_album import GalleryAlbum
89from imgur .models .gallery_image import GalleryImage
910from imgur .models .account_settings import AccountSettings
@@ -92,7 +93,9 @@ def make_request(self, method, route, data=None):
9293 else :
9394 response = method_to_call (url , headers = header , data = data )
9495
95- # TODO: Add rate-limit checks
96+ # Rate-limit check
97+ if response .status_code == 429 :
98+ raise ImgurClientError ('Rate-limit exceeded!' )
9699
97100 try :
98101 response_data = response .json ()
@@ -232,6 +235,7 @@ def get_account_images_count(self, username, page=0):
232235 self .validate_user_context (username )
233236 return self .make_request ('GET' , 'account/%s/images/ids/%d' % (username , page ))
234237
238+ # Album-related endpoints
235239 def get_album (self , album_id ):
236240 album = self .make_request ('GET' , 'album/%s' % album_id )
237241 return Album (album )
@@ -279,4 +283,35 @@ def album_remove_images(self, album_id, ids):
279283 if isinstance (ids , list ):
280284 ids = ',' .join (ids )
281285
282- return self .make_request ('DELETE' , 'album/%s/remove_images' % album_id , {'ids' : ids })
286+ return self .make_request ('DELETE' , 'album/%s/remove_images' % album_id , {'ids' : ids })
287+
288+ # Comment-related endpoints
289+ def get_comment (self , comment_id ):
290+ comment = self .make_request ('GET' , 'comment/%d' % comment_id )
291+ return Comment (comment )
292+
293+ def delete_comment (self , comment_id ):
294+ self .logged_in ()
295+ return self .make_request ('DELETE' , 'comment/%d' % comment_id )
296+
297+ def get_comment_replies (self , comment_id ):
298+ replies = self .make_request ('GET' , 'comment/%d/replies' % comment_id )
299+ replies ['children' ] = build_comment_tree (replies ['children' ])
300+
301+ return replies
302+
303+ def post_comment_reply (self , comment_id , image_id , comment ):
304+ data = {
305+ 'image_id' : image_id ,
306+ 'comment' : comment
307+ }
308+
309+ return self .make_request ('POST' , 'comment/%d' % comment_id , data )
310+
311+ def comment_vote (self , comment_id , vote , toggle = True ):
312+ toggle_behavior = 1 if toggle else 0
313+
314+ return self .make_request ('POST' , 'comment/%d/vote/%s?toggle=%d' % (comment_id , vote , toggle_behavior ))
315+
316+ def comment_report (self , comment_id ):
317+ return self .make_request ('POST' , 'comment/%d/report' % comment_id )
0 commit comments