Skip to content

Commit 968fa51

Browse files
committed
added support for removing by foreign id
1 parent 5be4396 commit 968fa51

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎stream/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__copyright__ = 'Copyright 2012, Thierry Schellenbach'
55
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
66
__license__ = 'BSD'
7-
__version__ = '0.3.0'
7+
__version__ = '0.3.1'
88
__maintainer__ = 'Thierry Schellenbach'
99
__email__ = 'thierryschellenbach@gmail.com'
1010
__status__ = 'Production'

‎stream/feed.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ def add_activities(self, activity_list):
5454
self.feed_url, data=data, authorization=self.authorization)
5555
return result
5656

57-
def remove_activity(self, activity_id):
57+
def remove_activity(self, activity_id=None, foreign_id=None):
5858
'''
5959
Removes an activity from the feed
6060
6161
:param activity_id: the activity id to remove from this feed
6262
(note this will also remove the activity from feeds which follow this feed)
63+
:param foreign_id: the foreign id you provided when adding the activity
6364
'''
64-
url = self.feed_url + '%s/' % activity_id
65-
result = self.client.delete(url, authorization=self.authorization)
65+
identifier = activity_id or foreign_id
66+
if not identifier:
67+
raise ValueError('please either provide activity_id or foreign_id')
68+
url = self.feed_url + '%s/' % identifier
69+
params = dict()
70+
if foreign_id is not None:
71+
params['foreign_id'] = '1'
72+
result = self.client.delete(url, authorization=self.authorization, params=params)
6673
return result
6774

6875
def follow(self, target_feed):

‎stream/tests.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def test_remove_activity(self):
6868
activities = self.user1.get(limit=1)['results']
6969
self.assertNotEqual(activities[0]['id'], activity_id)
7070

71+
def test_remove_activity_by_foreign_id(self):
72+
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:10'}
73+
activity_id = self.user1.add_activity(activity_data)['id']
74+
self.user1.remove_activity(foreign_id='tweet:10')
75+
activities = self.user1.get(limit=1)['results']
76+
self.assertNotEqual(activities[0]['id'], activity_id)
77+
7178
def test_add_activities(self):
7279
activity_data = [
7380
{'actor': 1, 'verb': 'tweet', 'object': 1},

0 commit comments

Comments
 (0)