Skip to content

Commit

Permalink
Add bulk_delete_comments endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ping committed May 16, 2017
1 parent fd0a950 commit 365dadb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions instagram_private_api/endpoints/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,29 @@ def delete_comment(self, media_id, comment_id):
res = self._call_api(endpoint, params=params)
return res

def bulk_delete_comments(self, media_id, comment_ids):
"""
Bulk delete comment
:param media_id: Media id
:param comment_ids: List of comment ids
:return:
.. code-block:: javascript
{"status": "ok"}
"""
if not isinstance(comment_ids, list):
comment_ids = [comment_ids]
endpoint = 'media/%(media_id)s/comment/bulk_delete/' % {
'media_id': media_id}
params = {
'comment_ids_to_delete': ','.join(
[str(comment_id) for comment_id in comment_ids])
}
params.update(self.authenticated_params)
res = self._call_api(endpoint, params=params)
return res

def media_likers(self, media_id, **kwargs):
"""
Get users who have liked a post
Expand Down
19 changes: 19 additions & 0 deletions tests/private/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def init_all(cls, api):
'name': 'test_delete_comment_mock',
'test': MediaTests('test_delete_comment_mock', api)
},
{
'name': 'test_bulk_delete_comments_mock',
'test': MediaTests('test_bulk_delete_comments_mock', api)
},
{
'name': 'test_save_photo',
'test': MediaTests('test_save_photo', api, media_id='1206573574980690068_1497851591')
Expand Down Expand Up @@ -470,3 +474,18 @@ def test_media_seen2_mock(self, call_api):
self.api.media_seen(reels_params)
call_api.assert_called_with(
'media/seen/', params=params, version='v2')

@compat_mock.patch('instagram_private_api.Client._call_api')
def test_bulk_delete_comments_mock(self, call_api):
call_api.return_value = {'status': 'ok'}
media_id = '123_123'
comment_ids = ['123456', '7890123']
params = {
'comment_ids_to_delete': ','.join(comment_ids)
}
params.update(self.api.authenticated_params)
self.api.bulk_delete_comments(media_id, comment_ids)
call_api.assert_called_with(
'media/%(media_id)s/comment/bulk_delete/'
% {'media_id': media_id},
params=params)

0 comments on commit 365dadb

Please sign in to comment.