Skip to content

Commit 4d3afaa

Browse files
committed
feat(here-now): add limit and offset configuration options
Add `limit` (default `1000`) and `offset` parameters for `here_now` to fetch presence in portions.
1 parent f5be446 commit 4d3afaa

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pubnub/endpoints/presence/here_now.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_group
2929

3030
self._include_state = include_state
3131
self._include_uuids = include_uuids
32+
self._offset = None
33+
self._limit = 1000
3234

3335
def channels(self, channels: Union[str, List[str]]) -> 'HereNow':
3436
utils.extend_list(self._channels, channels)
@@ -46,8 +48,16 @@ def include_uuids(self, include_uuids) -> 'HereNow':
4648
self._include_uuids = include_uuids
4749
return self
4850

51+
def limit(self, limit: int) -> 'HereNow':
52+
self._limit = limit
53+
return self
54+
55+
def offset(self, offset: int) -> 'HereNow':
56+
self._offset = offset
57+
return self
58+
4959
def custom_params(self):
50-
params = {}
60+
params = { 'limit': self._limit }
5161

5262
if len(self._channel_groups) > 0:
5363
params['channel-group'] = utils.join_items_and_encode(self._channel_groups)
@@ -58,6 +68,9 @@ def custom_params(self):
5868
if not self._include_uuids:
5969
params['disable_uuids'] = "1"
6070

71+
if self._offset is not None:
72+
params['offset'] = self._offset
73+
6174
return params
6275

6376
def build_path(self):

tests/functional/test_here_now.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ def test_here_now(self):
3030

3131
self.assertEqual(self.here_now.build_params_callback()({}), {
3232
'pnsdk': sdk_name,
33-
'uuid': self.pubnub.uuid
33+
'uuid': self.pubnub.uuid,
34+
'limit': 1000,
3435
})
3536

3637
def test_here_now_groups(self):
37-
self.here_now.channel_groups("gr1")
38+
self.here_now.channel_groups("gr1").limit(10000)
3839

3940
self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH
4041
% (pnconf.subscribe_key, ","))
4142

4243
self.assertEqual(self.here_now.build_params_callback()({}), {
4344
'channel-group': 'gr1',
4445
'pnsdk': sdk_name,
45-
'uuid': self.pubnub.uuid
46+
'uuid': self.pubnub.uuid,
47+
'limit': 10000,
4648
})
4749

4850
def test_here_now_with_options(self):
49-
self.here_now.channels(["ch1"]).channel_groups("gr1").include_state(True).include_uuids(False)
51+
self.here_now.channels(["ch1"]).channel_groups("gr1").include_state(True).include_uuids(False).offset(3)
5052

5153
self.assertEqual(self.here_now.build_path(), HereNow.HERE_NOW_PATH
5254
% (pnconf.subscribe_key, "ch1"))
@@ -56,5 +58,7 @@ def test_here_now_with_options(self):
5658
'state': '1',
5759
'disable_uuids': '1',
5860
'pnsdk': sdk_name,
59-
'uuid': self.pubnub.uuid
61+
'uuid': self.pubnub.uuid,
62+
'limit': 1000,
63+
'offset': 3,
6064
})

0 commit comments

Comments
 (0)