Skip to content

Commit 700c5f1

Browse files
OKTA-672843 Add optional parameter to api_response.next() to include response object as a third tuple value. (#379)
1 parent 4f823b4 commit 700c5f1

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Okta Python SDK Changelog
22

3+
## 2.9.4
4+
* Add optional parameter to api_response.next() to include response object as a third tuple value.
5+
36
## 2.9.3
47
* Add missing properties to applicationsettingsapplication per the reference docs: https://developer.okta.com/docs/reference/api/apps/#settings-4
58
* Add signed_nonce factor type per the reference docs: https://developer.okta.com/docs/reference/api/factors/#factor-type

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,27 @@ loop = asyncio.get_event_loop()
923923
loop.run_until_complete(main())
924924
```
925925

926+
If you require access to the response headers during a pagination operation, set the `includeResponse` parameter to `True` in the call to the `next` method; this returns the response as a third tuple value. See the following example:
927+
928+
```python
929+
from okta.client import Client as OktaClient
930+
import asyncio
931+
932+
async def main():
933+
client = OktaClient()
934+
users, resp, err = await client.list_users()
935+
while True:
936+
for user in users:
937+
print(user.profile.login)
938+
if resp.has_next():
939+
users, err, response = await resp.next(True) # Specify True to receive the response object as the third part of the tuple for further analysis
940+
else:
941+
break
942+
943+
loop = asyncio.get_event_loop()
944+
loop.run_until_complete(main())
945+
```
946+
926947
## Logging
927948

928949
> Feature appears in version 1.5.0

okta/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.9.3'
1+
__version__ = '2.9.4'

okta/api_response.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def has_next(self):
123123
"""
124124
return self._next is not None
125125

126-
async def next(self):
126+
async def next(self, includeResponse=False):
127127
"""
128128
Generator iterating function. Retrieves the next page of results
129129
from the API.
@@ -134,17 +134,23 @@ async def next(self):
134134
# if not self.has_next():
135135
# return (None, None) #This causes errors with our async testing
136136
MODELS_NOT_TO_CAMEL_CASE = [User, Group, UserSchema, GroupSchema]
137-
next_page, error = await self.get_next().__anext__()
137+
next_page, error, next_response = await self.get_next().__anext__()
138138
if error:
139139
return (None, error)
140140
if self._type is not None:
141141
result = []
142142
for item in next_page:
143143
result.append(self._type(item) if self._type in MODELS_NOT_TO_CAMEL_CASE
144144
else self._type(APIClient.form_response_body(item)))
145-
return (result, None)
145+
if includeResponse:
146+
return (result, None, next_response)
147+
else:
148+
return (result, None)
146149

147-
return (next_page, error)
150+
if includeResponse:
151+
return (next_page, error, next_response)
152+
else:
153+
return (next_page, error)
148154

149155
async def get_next(self):
150156
"""
@@ -162,19 +168,19 @@ async def get_next(self):
162168
if error:
163169
# Return None if error and set next to none
164170
self._next = None
165-
yield (None, error)
171+
yield (None, error, None)
166172

167173
req, res_details, resp_body, error = await \
168174
self._request_executor.fire_request(next_request)
169175
if error:
170176
# Return None if error and set next to none
171177
self._next = None
172-
yield (None, error)
178+
yield (None, error, None)
173179

174180
if next_request:
175181
# create new response and update generator values
176182
next_response = OktaAPIResponse(
177183
self._request_executor, req, res_details, resp_body)
178184
self._next = next_response._next
179185
# yield next page
180-
yield (next_response.get_body(), None)
186+
yield (next_response.get_body(), None, next_response)

0 commit comments

Comments
 (0)