Skip to content

Commit

Permalink
PaginatingClientMethodFactory: Use configurable paginated content keys (
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Oct 16, 2019
1 parent 4d844f3 commit b963d28
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions hca/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,12 @@ def iterate(self, **kwargs):
items contained within; POST /search yields search result items.
"""
for page in self._get_raw_pages(**kwargs):
if page.json().get('results'):
for result in page.json()['results']:
yield result
elif page.json().get('bundle'):
for file in page.json()['bundle']['files']:
yield file
else:
for collection in page.json().get('collections', []):
yield collection
content_key = page.headers.get("X-OpenAPI-Paginated-Content-Key", "results")
results = page.json()
for key in content_key.split("."):
results = results[key]
for result in results:
yield result

def paginate(self, **kwargs):
"""Yield paginated responses one response body at a time."""
Expand Down

0 comments on commit b963d28

Please sign in to comment.