Skip to content

Commit 28ad59a

Browse files
committed
added support for limit and offset based pagination
1 parent 9b19f7f commit 28ad59a

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ result = user_feed_1.get(limit=5, id_lt="e561de8f-00f1-11e4-b400-0cc47a024be0")
3535
# Create a new activity
3636
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:1'}
3737
activity_response = user_feed_1.add_activity(activity_data)
38+
# Create a bit more complex activity
39+
activity_data = {'actor': 1, 'verb': 'run', 'object': 1, 'foreign_id': 'run:1',
40+
'course': {'name': 'Golden Gate park', 'distance': 10},
41+
'participants': ['Thierry', 'Tommaso'],
42+
'started_at': datetime.datetime.now()
43+
};
44+
user_feed_1.add_activity(activity_data)
3845

3946
# Remove an activity by its id
4047
user_feed_1.remove("e561de8f-00f1-11e4-b400-0cc47a024be0")

‎stream/feed.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,21 @@ def parse_follow_data(self, response):
107107
'results': response['results']
108108
}
109109

110-
def followers(self, limit=100, page=1):
110+
def followers(self, offset=0, limit=25):
111111
params = {
112112
'limit': limit,
113-
'page': page
113+
'offset': offset
114114
}
115115
url = self.feed_url + 'followers/'
116116
response = self.client.get(
117117
url, params=params, authorization=self.authorization)
118118
return self.parse_follow_data(response)
119119

120-
def following(self, limit=100, page=1, feeds=None):
120+
def following(self, offset=0, limit=25, feeds=None):
121121
feeds = feeds is not None and ','.join(feeds) or ''
122122
params = {
123+
'offset': offset,
123124
'limit': limit,
124-
'page': page,
125125
'filter': feeds
126126
}
127127
url = self.feed_url + 'follows/'

‎stream/tests.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ def test_get_followings(self):
187187
social = client.feed('user:psocial')
188188
social.follow('user:apy')
189189
social.follow('user:bpy')
190-
followings = social.following(limit=1, page=2)
190+
social.follow('user:cpy')
191+
followings = social.following(offset=0, limit=2)
191192
self.assertEqual(followings['count'], 2)
192193
self.assertEqual(followings['results'][0]['feed_id'], 'user:psocial')
193194
self.assertEqual(followings['results'][0]['target_id'], 'user:apy')
195+
followings = social.following(offset=1, limit=2)
196+
self.assertEqual(followings['count'], 2)
197+
self.assertEqual(followings['results'][0]['feed_id'], 'user:psocial')
198+
self.assertEqual(followings['results'][0]['target_id'], 'user:bpy')
194199

195200
def test_empty_followers(self):
196201
asocial = client.feed('user:asocialpython')
@@ -202,16 +207,21 @@ def test_get_followers(self):
202207
social = client.feed('user:psocial')
203208
client.feed('user:spammy1').follow('user:psocial')
204209
client.feed('user:spammy2').follow('user:psocial')
205-
followers = social.followers(limit=1, page=2)
210+
client.feed('user:spammy3').follow('user:psocial')
211+
followers = social.followers(offset=0, limit=2)
206212
self.assertEqual(followers['count'], 2)
207213
self.assertEqual(followers['results'][0]['feed_id'], 'user:spammy1')
208214
self.assertEqual(followers['results'][0]['target_id'], 'user:psocial')
215+
followers = social.followers(offset=1, limit=2)
216+
self.assertEqual(followers['count'], 2)
217+
self.assertEqual(followers['results'][0]['feed_id'], 'user:spammy2')
218+
self.assertEqual(followers['results'][0]['target_id'], 'user:psocial')
209219

210220
def test_empty_do_i_follow(self):
211221
social = client.feed('user:psocial')
212222
social.follow('user:apy')
213223
social.follow('user:bpy')
214-
followings = social.following(feeds=['user:cpy'])
224+
followings = social.following(feeds=['user:missingpy'])
215225
self.assertEqual(followings['count'], 0)
216226
self.assertEqual(followings['results'], [])
217227

0 commit comments

Comments
 (0)