@@ -152,7 +152,7 @@ def get(
152
152
params = {}
153
153
154
154
# we use the presence of version to determine if we are REST or not
155
- if "version" not in params .keys () and self .version :
155
+ if "version" not in params .keys () and self .version and not exclude_version :
156
156
params ["version" ] = version or self .version
157
157
158
158
# Python Bools are True/False, JS Bools are true/false
@@ -212,40 +212,24 @@ def get_rest_pages(self, path: str, params: dict = {}) -> List:
212
212
This collects the "data" list from the first reponse and then appends the
213
213
any further "data" lists if a next link is found in the links field.
214
214
"""
215
+ first_page_response = self .get (path , params )
216
+ page_data = first_page_response .json ()
217
+ return_data = page_data ["data" ]
215
218
216
- # this is a raw primative but a higher level module might want something that does an
217
- # arbitrary path + origin=foo + limit=100 url construction instead before being sent here
218
-
219
- limit = params ["limit" ]
220
-
221
- data = list ()
222
-
223
- page = self .get (path , params ).json ()
224
-
225
- data .extend (page ["data" ])
226
-
227
- while "next" in page ["links" ].keys ():
219
+ while page_data .get ("links" , {}).get ("next" ):
228
220
logger .debug (
229
- f"GET_REST_PAGES: Another link exists: { page ['links' ]['next' ]} "
221
+ f"GET_REST_PAGES: Another link exists: { page_data ['links' ]['next' ]} "
230
222
)
223
+ next_url = page_data .get ("links" , {}).get ("next" )
231
224
232
- next_url = urllib .parse .urlsplit (page ["links" ]["next" ])
233
- query = urllib .parse .parse_qs (next_url .query )
234
-
235
- for k , v in query .items ():
236
- params [k ] = v
237
-
238
- params ["limit" ] = limit
239
-
240
- page = self .get (next_url .path , params ).json ()
241
-
242
- data .extend (page ["data" ])
243
-
225
+ # The next url comes back fully formed (i.e. with all the params already set, so no need to do it here)
226
+ next_page_response = self .get (next_url , {}, exclude_version = True )
227
+ page_data = next_page_response .json ()
228
+ return_data .extend (page_data ["data" ])
244
229
logger .debug (
245
- f"GET_REST_PAGES: Added another { len (page ['data' ])} items to the response"
230
+ f"GET_REST_PAGES: Added another { len (page_data ['data' ])} items to the response"
246
231
)
247
-
248
- return data
232
+ return return_data
249
233
250
234
# alias for backwards compatibility where V3 was the old name
251
235
get_v3_pages = get_rest_pages
0 commit comments