Skip to content

Commit

Permalink
Merge pull request #189 from anthonybaxter/master
Browse files Browse the repository at this point in the history
Allow the base_url of 'action/api/' to be overriden via subclassing
  • Loading branch information
wardi authored Jul 5, 2021
2 parents 77fdb69 + 8541569 commit ceb31b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ckanapi/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def is_file_like(v):
isinstance(v, tuple) and len(v) >= 2 and hasattr(v[1], 'read'))


def prepare_action(action, data_dict=None, apikey=None, files=None):
def prepare_action(action, data_dict=None, apikey=None, files=None,
base_url='action/api/'):
"""
Return action_url, data_json, http_headers
"""
Expand All @@ -87,7 +88,7 @@ def prepare_action(action, data_dict=None, apikey=None, files=None):
apikey = str(apikey)
headers['X-CKAN-API-Key'] = apikey
headers['Authorization'] = apikey
url = 'api/action/' + action
url = base_url + action
return url, data_dict, headers


Expand Down
6 changes: 5 additions & 1 deletion ckanapi/remoteckan.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class RemoteCKAN(object):
:param get_only: only use GET requests (default: False)
:param session: session to use (default: None)
"""

base_url = 'api/action/'

def __init__(self, address, apikey=None, user_agent=None, get_only=False, session=None):
self.address = address
self.apikey = apikey
Expand Down Expand Up @@ -80,7 +83,8 @@ def call_action(self, action, data_dict=None, context=None, apikey=None,
raise CKANAPIError("RemoteCKAN: files may not be sent when "
"get_only is True")
url, data, headers = prepare_action(
action, data_dict, apikey or self.apikey, files)
action, data_dict, apikey or self.apikey, files,
base_url=self.base_url)
headers['User-Agent'] = self.user_agent
url = self.address.rstrip('/') + '/' + url
requests_kwargs = requests_kwargs or {}
Expand Down

0 comments on commit ceb31b3

Please sign in to comment.