Skip to content

Commit f1af63c

Browse files
committed
[sc-101330] Add relative URL to pagination
1 parent ff7cf35 commit f1af63c

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

python-connectors/api-connect_dataset/connector.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@
152152
"defaultValue": null,
153153
"visibilityCondition": "model.pagination_type=='next_page'"
154154
},
155+
{
156+
"name": "is_next_page_url_relative",
157+
"label": " ",
158+
"description": "Next page URL is relative",
159+
"type": "BOOLEAN",
160+
"defaultValue": false,
161+
"visibilityCondition": "model.pagination_type=='next_page'"
162+
},
163+
{
164+
"name": "next_page_url_base",
165+
"label": "Base URL to next page",
166+
"description": "https://mysite.com/bla/",
167+
"type": "STRING",
168+
"defaultValue": null,
169+
"visibilityCondition": "model.pagination_type=='next_page' && (model.is_next_page_url_relative==true)"
170+
},
155171
{
156172
"name": "top_key",
157173
"label": "Key limiting elements per page",

python-lib/dku_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_endpoint_parameters(configuration):
2424
"timeout",
2525
"requests_per_minute",
2626
"pagination_type",
27-
"next_page_url_key",
27+
"next_page_url_key", "is_next_page_url_relative", "next_page_url_base",
2828
"top_key", "skip_key", "maximum_number_rows"
2929
]
3030
parameters = {endpoint_parameter: configuration.get(endpoint_parameter) for endpoint_parameter in endpoint_parameters if configuration.get(endpoint_parameter) is not None}

python-lib/pagination.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Pagination(object):
99

1010
def __init__(self, config=None, skip_key=None, limit_key=None, total_key=None, next_page_key=None):
1111
self.next_page_key = None
12+
self.next_page_url_base = None
1213
self.skip_key = None
1314
self.limit_key = None
1415
self.total_key = None
@@ -26,13 +27,16 @@ def __init__(self, config=None, skip_key=None, limit_key=None, total_key=None, n
2627
self.params_must_be_blanked = False
2728
self.data_is_list = None
2829

29-
def configure_paging(self, config=None, skip_key=None, limit_key=None, total_key=None, next_page_key=None, url=None, pagination_type="na"):
30+
def configure_paging(self, config=None, skip_key=None, limit_key=None, total_key=None, next_page_key=None, next_page_url_base=None, url=None, pagination_type="na"):
3031
config = {} if config is None else config
3132
self.limit_key = config.get("limit_key", limit_key)
3233
self.pagination_type = config.get("pagination_type", pagination_type)
3334
if self.pagination_type == "next_page":
3435
self.next_page_key = config.get("next_page_key", next_page_key)
3536
self.next_page_key = None if self.next_page_key == '' else self.next_page_key
37+
if next_page_url_base:
38+
next_page_url_base = next_page_url_base.strip('/')
39+
self.next_page_url_base = next_page_url_base
3640
elif self.pagination_type in ["offset", "page"]:
3741
self.skip_key = config.get("skip_key", skip_key)
3842

@@ -81,7 +85,11 @@ def update_next_page(self, data, response_links=None):
8185
else:
8286
batch_size = 1
8387
if self.next_page_key:
84-
self.next_page_url = extract_key_using_json_path(data, self.next_page_key)
88+
next_page_path = extract_key_using_json_path(data, self.next_page_key)
89+
if self.next_page_url_base and next_page_path:
90+
self.next_page_url = "/".join([self.next_page_url_base, next_page_path])
91+
else:
92+
self.next_page_url = next_page_path
8593
if self.skip_key:
8694
self.skip = data.get(self.skip_key)
8795
if self.limit_key:

python-lib/rest_api_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ def __init__(self, credential, endpoint, custom_key_values={}):
6161
self.requests_kwargs.update({"params": self.params})
6262
self.pagination = Pagination()
6363
next_page_url_key = endpoint.get("next_page_url_key", "")
64+
is_next_page_url_relative = endpoint.get("is_next_page_url_relative", False)
65+
next_page_url_base = endpoint.get("next_page_url_base", None) if is_next_page_url_relative else None
6466
top_key = endpoint.get("top_key")
6567
skip_key = endpoint.get("skip_key")
6668
pagination_type = endpoint.get("pagination_type", "na")
6769
self.pagination.configure_paging(
6870
skip_key=skip_key,
6971
limit_key=top_key,
7072
next_page_key=next_page_url_key,
73+
next_page_url_base=next_page_url_base,
7174
url=self.endpoint_url,
7275
pagination_type=pagination_type
7376
)

0 commit comments

Comments
 (0)