Skip to content

Commit d8d162a

Browse files
authored
Merge pull request #27 from dataiku/feature/sc-101330-add-base-url-to-next-record-url
Feature/sc 101330 add base url to next record url
2 parents ff7cf35 + 614c818 commit d8d162a

7 files changed

Lines changed: 53 additions & 4 deletions

File tree

custom-recipes/api-connect/recipe.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@
193193
"defaultValue": null,
194194
"visibilityCondition": "model.pagination_type=='next_page'"
195195
},
196+
{
197+
"name": "is_next_page_url_relative",
198+
"label": " ",
199+
"description": "Next page URL is relative",
200+
"type": "BOOLEAN",
201+
"defaultValue": false,
202+
"visibilityCondition": "model.pagination_type=='next_page'"
203+
},
204+
{
205+
"name": "next_page_url_base",
206+
"label": "Base URL to next page",
207+
"description": "https://mysite.com/bla/",
208+
"type": "STRING",
209+
"defaultValue": null,
210+
"visibilityCondition": "model.pagination_type=='next_page' && (model.is_next_page_url_relative==true)"
211+
},
196212
{
197213
"name": "top_key",
198214
"label": "Key limiting elements per page",

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "api-connect",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"meta": {
55
"label": "API Connect",
66
"description": "Retrieve data from any REST API",

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ 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
66+
next_page_url_base = format_template(next_page_url_base, **self.presets_variables)
6467
top_key = endpoint.get("top_key")
6568
skip_key = endpoint.get("skip_key")
6669
pagination_type = endpoint.get("pagination_type", "na")
6770
self.pagination.configure_paging(
6871
skip_key=skip_key,
6972
limit_key=top_key,
7073
next_page_key=next_page_url_key,
74+
next_page_url_base=next_page_url_base,
7175
url=self.endpoint_url,
7276
pagination_type=pagination_type
7377
)

tests/python/integration/test_scenario.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ def test_run_api_connect_redirection(user_dss_clients):
3434
def test_run_api_connect_check_sc_84465(user_dss_clients):
3535
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="CHECKSC84465")
3636

37+
3738
def test_run_api_connect_ntlm_authentication(user_dss_clients):
3839
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="NTLMAUTHENTICATION")
40+
41+
42+
def test_run_api_connect_relative_url_pagination(user_dss_clients):
43+
dss_scenario.run(user_dss_clients, project_key=TEST_PROJECT_KEY, scenario_id="RELATIVEURLPAGINATION")

0 commit comments

Comments
 (0)