Skip to content

Commit 578cf8d

Browse files
committed
add support for private feeds
1 parent 2929f58 commit 578cf8d

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ activities = [
5454
]
5555
user_feed_1.add_activities(activities)
5656

57+
# Add an activity and push it to other feeds too using the `to` field
58+
activity = {
59+
"actor_id":"1",
60+
"verb":"like",
61+
"object_id":"3",
62+
"to":["user:44", "user:45"]
63+
];
64+
user_feed_1.add_activity(activity);
65+
5766
# Generating tokens for client side usage
5867
token = user_feed_1.token
5968
# Javascript client side feed initialization

‎stream/feed.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ def follow(self, target_feed):
9292
9393
:param target_feed: the feed to follow, ie flat:3
9494
'''
95-
validate_feed(target_feed)
9695
url = self.feed_url + 'follows/'
96+
data = {
97+
'target': target_feed,
98+
'target_token': self.client.feed(target_feed).token
99+
}
97100
response = self.client.post(
98-
url, data=dict(target=target_feed), authorization=self.authorization)
101+
url, data=data, authorization=self.authorization)
99102
return response
100103

101104
def parse_follow_data(self, response):

‎stream/tests.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ def test_follow(self):
132132
activity_id_found = activity['id'] if activity is not None else None
133133
self.assertEqual(activity_id_found, activity_id)
134134

135+
def test_follow_private(self):
136+
feed = client.feed('secret:py1')
137+
actor_id = random.randint(10, 100000)
138+
activity_data = {'actor': actor_id, 'verb': 'tweet', 'object': 1}
139+
activity_id = feed.add_activity(activity_data)['id']
140+
self.aggregated2.follow('secret:py1')
141+
time.sleep(10)
142+
activities = self.aggregated2.get(limit=3)['results']
143+
activity = self._get_first_aggregated_activity(activities)
144+
activity_id_found = activity['id'] if activity is not None else None
145+
self.assertEqual(activity_id_found, activity_id)
146+
135147
def test_flat_follow(self):
136148
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1}
137149
activity_id = self.user1.add_activity(activity_data)['id']
@@ -259,7 +271,7 @@ def assertClearlyNotEqual(self, a, b):
259271
difference = abs(a-b)
260272
if difference < datetime.timedelta(milliseconds=1):
261273
raise ValueError('the dates are too close')
262-
274+
263275
def test_uniqueness(self):
264276
'''
265277
In order for things to be considere unique they need:
@@ -273,7 +285,7 @@ def test_uniqueness(self):
273285
activities = self.user1.get(limit=2)['results']
274286
self.assertDatetimeAlmostEqual(activities[0]['time'], utcnow)
275287
self.assertClearlyNotEqual(activities[1]['time'], utcnow)
276-
288+
277289
def test_uniqueness_topic(self):
278290
'''
279291
In order for things to be considere unique they need:
@@ -293,7 +305,7 @@ def test_uniqueness_topic(self):
293305
response = self.flat3.get(limit=3)
294306
activity_tweets = [a.get('tweet') for a in response['results']]
295307
self.assertEqual(activity_tweets.count(tweet), 1)
296-
308+
297309
def test_uniqueness_foreign_id(self):
298310
now = datetime.datetime.now(tzlocal())
299311
utcnow = (now - now.utcoffset()).replace(tzinfo=None)
@@ -307,7 +319,7 @@ def test_uniqueness_foreign_id(self):
307319
self.assertEqual(activities[0]['foreign_id'], 'tweet:11')
308320
self.assertDatetimeAlmostEqual(activities[0]['time'], utcnow)
309321
self.assertNotEqual(activities[1]['foreign_id'], 'tweet:11')
310-
322+
311323
def test_missing_actor(self):
312324
activity_data = {'verb': 'tweet', 'object':
313325
1, 'debug_example_undefined': 'test'}
@@ -324,7 +336,7 @@ def test_wrong_feed_spec(self):
324336
'tfq2sdqpj9g446sbv653x3aqmgn33hsn8uzdc9jpskaw8mj6vsnhzswuwptuj9su'
325337
)
326338
self.assertRaises(ValueError, lambda: self.c.feed('user1'))
327-
339+
328340
def test_serialization(self):
329341
today = datetime.date.today()
330342
now = datetime.datetime.now()

0 commit comments

Comments
 (0)