add cursor based pagination - #91
Conversation
…ginate-using-cusor
…--api-connect-cannot-paginate-using-cusor' into bug/dss14-sc-337638--api-connect-cannot-paginate-using-cusor
| @@ -34,17 +40,23 @@ def configure_paging(self, config=None, skip_key=None, | |||
| if next_page_url_base: | |||
| next_page_url_base = next_page_url_base.strip('/') | |||
| self.next_page_url_base = next_page_url_base | |||
| elif self.pagination_type == "cursor": | |||
| self.cursor_next_token_path = config.get("cursor_next_token_path", cursor_next_token_path) | |||
| self.cursor_query_param = config.get("cursor_query_param", cursor_query_param) | |||
| self.cursor_initial_token = config.get("cursor_initial_token", cursor_initial_token) | |||
| elif self.pagination_type in ["offset", "page"]: | |||
| self.skip_key = config.get("skip_key", skip_key) | |||
| logger.info("configure_paging: self.pagination_type='{}', self.next_page_key='{}', self.next_page_url_base='{}', self.skip_key='{}'".format( | |||
| self.pagination_type, self.next_page_key, self.next_page_url_base, self.skip_key | |||
| logger.info("configure_paging: self.pagination_type='{}', self.next_page_key='{}', self.next_page_url_base='{}', self.skip_key='{}', self.cursor_next_token_path='{}', self.cursor_query_param='{}', self.cursor_initial_token='{}'".format( | |||
| self.pagination_type, self.next_page_key, self.next_page_url_base, self.skip_key, self.cursor_next_token_path, self.cursor_query_param, self.cursor_initial_token | |||
| )) | |||
| if self.pagination_type == "next_page": | |||
| self.update_next_page = self.update_next_page_link | |||
| elif self.pagination_type == "offset": | |||
| self.update_next_page = self.update_next_page_offset | |||
| elif self.pagination_type == "page": | |||
| self.update_next_page = self.update_next_page_per_page | |||
| elif self.pagination_type == "cursor": | |||
| self.update_next_page = self.update_next_page_cursor | |||
| else: | |||
| self.update_next_page = self.update_next_page_default | |||
There was a problem hiding this comment.
Nit: for readability, I would split this method into smaller ones since there are only if .. elif in the implementation
There was a problem hiding this comment.
I rationalized a bit the method but I'm not sur splitting it would make it a lot clearer.
|
|
||
| if self.cursor_next_token_path and self.cursor_query_param: | ||
| self.cursor_query_param_value = extract_key_using_json_path(data, self.cursor_next_token_path) | ||
| logger.info("update_next_page_cursor:{}".format({self.cursor_query_param_value})) |
There was a problem hiding this comment.
It's consistent with the other pagination type, I would agree conceptually but it was useful when debugging the issue initially
| return ret | ||
| if self.pagination_type == "cursor": | ||
| ret = (self.cursor_query_param_value is not None) and (self.cursor_query_param_value != "") | ||
| logger.info("has_next_page:cursor_next_token_path={} cursor_query_param={} cursor_query_param_value={} -> {}".format( |
There was a problem hiding this comment.
Same, I would put debug
There was a problem hiding this comment.
same than previous
| cursor_next_token_path = endpoint.get("cursor_next_token_path") | ||
| cursor_query_param = endpoint.get("cursor_query_param") | ||
| cursor_initial_token = format_template(endpoint.get("cursor_initial_token"), **self.presets_variables) |
There was a problem hiding this comment.
Is there a reason why only intital_token supports variables and the others don't?
There was a problem hiding this comment.
I do not see how it would be useful for the others, initial token has a good chance to be stored within contextual variables.
sc-337638