Skip to content

Commit 8278d3c

Browse files
authored
Merge pull request #20 from RPCMoritz/master
Add pagination via kwargs for queries which respect maximum-results
2 parents 8ef0aa1 + 17af0ab commit 8278d3c

2 files changed

Lines changed: 25 additions & 24 deletions

File tree

crowd_api/__init__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import json
99
import random
1010
import string
11-
import logging
1211

1312

1413
class CrowdAPI:
@@ -85,8 +84,8 @@ def get_user_groups(self, **kwargs):
8584
if "username" not in kwargs:
8685
raise ValueError("Must pass username")
8786

88-
req = self.api_get("/user/group/direct?username={}&max-results={}".format(
89-
kwargs['username'], kwargs.get('max_results', 1000)))
87+
req = self.api_get("/user/group/direct?username={}&max-results={}&start-index={}".format(
88+
kwargs['username'], kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
9089
if req.status_code == 200:
9190
for group in req.json()['groups']:
9291
groups.append(group['name'])
@@ -103,8 +102,8 @@ def get_group_users(self, **kwargs):
103102
if "groupname" not in kwargs:
104103
raise ValueError("Must pass username")
105104

106-
req = self.api_get("/group/user/direct?groupname={}&max-results={}".format(
107-
kwargs['groupname'], kwargs.get('max_results', 1000)))
105+
req = self.api_get("/group/user/direct?groupname={}&max-results={}}&start-index={}".format(
106+
kwargs['groupname'], kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
108107
if req.status_code == 200:
109108
for user in req.json()['users']:
110109
users.append(user['name'])
@@ -173,7 +172,8 @@ def get_all_groups(self, **kwargs):
173172
groups = []
174173

175174
req = self.api_get(
176-
"/search?entity-type=group&max-results={}".format(kwargs.get('max_results', 1000)))
175+
"/search?entity-type=group&max-results={}&start-index={}".format(
176+
kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
177177

178178
if req.status_code == 200:
179179
for group in req.json()['groups']:
@@ -192,7 +192,8 @@ def search_group(self, **kwargs):
192192
raise ValueError("You need to define a certian restriction")
193193

194194
req = self.api_get(
195-
"/search?entity-type=group&restriction={}&max-results={}".format(kwargs['restriction'], kwargs.get('max_results', 1000)))
195+
"/search?entity-type=group&restriction={}&max-results={}&start-index={}".format(
196+
kwargs['restriction'], kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
196197

197198
if req.status_code == 200:
198199
for group in req.json()['groups']:
@@ -208,7 +209,8 @@ def get_all_users(self, **kwargs):
208209
users = []
209210

210211
req = self.api_get(
211-
"/search?entity-type=user&max-results={}".format(kwargs.get('max_results', 1000)))
212+
"/search?entity-type=user&max-results={}&start-index={}".format(
213+
kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
212214
if req.status_code == 200:
213215
for user in req.json()['users']:
214216
users.append(user['name'])
@@ -223,10 +225,11 @@ def search_user(self, **kwargs):
223225
users = []
224226

225227
if 'restriction' not in kwargs:
226-
raise ValueError("You need to define a certian restriction")
228+
raise ValueError("You need to define a certain restriction")
227229

228230
req = self.api_get(
229-
"/search?entity-type=user&restriction={}&max-results={}".format(kwargs['restriction'], kwargs.get('max_results', 1000)))
231+
"/search?entity-type=user&restriction={}&max-results={}&start-index={}".format(
232+
kwargs['restriction'], kwargs.get('max_results', 1000), kwargs.get('start_index', 0)))
230233
if req.status_code == 200:
231234
for user in req.json()['users']:
232235
users.append(user['name'])
@@ -237,7 +240,6 @@ def search_user(self, **kwargs):
237240
else:
238241
return {"status": False, "code": req.status_code, "reason": req.content}
239242

240-
241243
def set_user_attribute(self, **kwargs):
242244
if "username" not in kwargs:
243245
raise ValueError("Must pass username")
@@ -279,7 +281,6 @@ def set_user_activity(self, **kwargs):
279281
else:
280282
return {"status": False, "code": req.status_code, "reason": req.content}
281283

282-
283284
def create_user(self, **kwargs):
284285
user = {}
285286

setup.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from distutils.core import setup
22

3-
version = '0.0.8'
3+
version = '0.0.9'
44

55
setup(
6-
name = 'crowd-api',
7-
packages = ['crowd_api'],
8-
version = version,
9-
description = 'Python library for Atlassian Crowd',
10-
author = 'Matteo Cerutti',
11-
author_email = 'matteo.cerutti@hotmail.co.uk',
12-
url = 'https://github.com/m4ce/crowd-api-python',
13-
download_url = 'https://github.com/m4ce/crowd-api-python/tarball/%s' % (version,),
14-
keywords = ['crowd'],
15-
classifiers = [],
16-
install_requires = ["requests"]
6+
name='crowd-api',
7+
packages=['crowd_api'],
8+
version=version,
9+
description='Python library for Atlassian Crowd',
10+
author='Matteo Cerutti',
11+
author_email='matteo.cerutti@hotmail.co.uk',
12+
url='https://github.com/m4ce/crowd-api-python',
13+
download_url='https://github.com/m4ce/crowd-api-python/tarball/%s' % (version,),
14+
keywords=['crowd'],
15+
classifiers=[],
16+
install_requires=["requests"]
1717
)

0 commit comments

Comments
 (0)