Skip to content

Commit

Permalink
Merge pull request #6 from digitalocean/pagination-fix
Browse files Browse the repository at this point in the history
Work around for #4
  • Loading branch information
Zach Moody committed Aug 29, 2017
2 parents 6591f0d + a13096e commit d6cca57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions pynetbox/lib/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,26 @@ def make_request(url):
else:
raise RequestError(req)

req = make_request(self.url)
if req.get('results') is not None:
ret = req['results']
if req['next']:
next_url = "{}{}limit={}&offset={}".format(
self.url,
'&' if self.url[-1] != '/' else '?',
req['count'],
len(req['results'])
)
req = make_request(next_url)
ret.extend(req['results'])
return ret
else:
return req
def req_all(url):
req = make_request(url)
if req.get('results') is not None:
ret = req['results']
first_run = True
while req['next']:
next_url = "{}{}limit={}&offset={}".format(
self.url,
'&' if self.url[-1] != '/' else '?',
req['count'],
len(req['results'])
) if first_run else req['next']
req = make_request(next_url)
first_run = False
ret.extend(req['results'])
return ret
else:
return req

return req_all(self.url)

def put(self, data):
"""Makes PUT request.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='pynetbox',
version='2.0.4',
version='2.0.5',
description='NetBox API client library',
url='https://github.com/digitalocean/pynetbox',
author='Zach Moody',
Expand Down

0 comments on commit d6cca57

Please sign in to comment.