Skip to content

Commit a305c14

Browse files
author
Steve Dorazio
committed
Fixing User.all() to return all users, not just the first page
1 parent c10f953 commit a305c14

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

intercom/intercom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _create_or_update_user(cls, method, **kwargs):
110110
return user_dict
111111

112112
@classmethod
113-
def get_users(cls):
113+
def get_users(cls, **kwargs):
114114
""" Return a dict for the user represented by the specified email
115115
or user_id.
116116
@@ -121,7 +121,7 @@ def get_users(cls):
121121
3
122122
123123
"""
124-
user_dict = Intercom._call('GET', Intercom.api_endpoint + 'users')
124+
user_dict = Intercom._call('GET', Intercom.api_endpoint + 'users', params=kwargs)
125125
return user_dict
126126

127127
@classmethod

intercom/user.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,15 @@ def all(cls):
141141
u'first.user@example.com'
142142
143143
"""
144-
resp = Intercom.get_users()
145-
return [cls(u) for u in resp['users']]
144+
page = 1
145+
total_pages = 1
146+
users = []
147+
while page <= total_pages:
148+
resp = Intercom.get_users(page=page)
149+
page += 1
150+
total_pages = resp['total_pages']
151+
users.extend([cls(u) for u in resp['users']])
152+
return users
146153

147154
def save(self):
148155
""" Creates or updates a User.

0 commit comments

Comments
 (0)