feature/ remove API_VERSION from code base

This commit is contained in:
Reena Aheer 2023-04-11 11:06:05 +02:00
parent 3d3e6ca06a
commit 1b06e7f875
2 changed files with 37 additions and 18 deletions

View File

@ -259,8 +259,6 @@ API_HOST = 'http://127.0.0.1:8080'
API_EXPLORER_HOST = 'http://127.0.0.1:8082'
# Only override this if you have a separate portal instance
API_PORTAL = API_HOST
API_BASE_PATH = '/obp/v'
API_VERSION = '5.1.0'
# URL to API Tester
API_TESTER_URL = 'https://www.example.com'
@ -317,11 +315,16 @@ except ImportError:
pass
# EVERYTHING BELOW HERE WILL *NOT* BE OVERWRITTEN BY LOCALSETTINGS!
# DO NOT TRY TO DO SO YOU WILL BE IGNORED!
OBPv500 = API_HOST + '/obp/v5.0.0'
OBPv510 = API_HOST + '/obp/v5.1.0'
# Settings here might use parts overwritten in local settings
API_ROOT = API_HOST + API_BASE_PATH + API_VERSION
API_ROOT = {
"v500": OBPv500,
"v510": OBPv510
}
# For some reason, swagger is not available at the latest API version
API_URL_SWAGGER = API_HOST + '/obp/v1.4.0/resource-docs/v' + API_VERSION + '/swagger' # noqa
API_URL_SWAGGER = API_HOST + '/obp/v1.4.0/resource-docs/v' + OBPv510 + '/swagger' # noqa
if not OAUTH_CONSUMER_KEY:
raise ImproperlyConfigured('Missing settings for OAUTH_CONSUMER_KEY')

View File

@ -70,12 +70,14 @@ class API(object):
Convenience call which uses API_ROOT from settings
"""
url = settings.API_ROOT + urlpath
url = settings.API_ROOT["v500"] + urlpath
response = self.handle_response(self.call('GET', url))
if response is not None and 'code' in response:
raise APIError(response['message'])
else:
return response
url = settings.API_ROOT["v510"] + urlpath
response = self.handle_response(self.call('GET', url))
if response is not None and 'code' in response:
raise APIError(response['message'])
return response
def delete(self, urlpath):
"""
@ -83,9 +85,14 @@ class API(object):
Convenience call which uses API_ROOT from settings
"""
url = settings.API_ROOT + urlpath
response = self.call('DELETE', url)
return self.handle_response(response)
url = settings.API_ROOT["v500"] + urlpath
response = self.handle_response(self.call('DELETE', url))
if response is not None and 'code' in response:
url = settings.API_ROOT["v510"] + urlpath
response = self.handle_response(self.call('DELETE', url))
if response is not None and 'code' in response:
raise APIError(response['message'])
return response
def post(self, urlpath, payload):
"""
@ -93,19 +100,28 @@ class API(object):
Convenience call which uses API_ROOT from settings
"""
url = settings.API_ROOT + urlpath
response = self.call('POST', url, payload)
return self.handle_response(response)
url = settings.API_ROOT["v500"] + urlpath
response = self.handle_response(self.call('POST', url, payload))
if response is not None and 'code' in response:
url = settings.API_ROOT["v510"] + urlpath
response = self.handle_response(self.call('POST', url, payload))
if response is not None and 'code' in response:
raise APIError(response['message'])
return response
def put(self, urlpath, payload):
"""
Puts data on given urlpath with given payload
Convenience call which uses API_ROOT from settings
"""
url = settings.API_ROOT + urlpath
response = self.call('PUT', url, payload)
return self.handle_response(response)
url = settings.API_ROOT["v500"] + urlpath
response = self.handle_response(self.call('PUT', url, payload))
if response is not None and 'code' in response:
url = settings.API_ROOT["v510"] + urlpath
response = self.handle_response(self.call('PUT', url, payload))
if response is not None and 'code' in response:
raise APIError(response['message'])
return response
def handle_response_error(self, prefix, error):
if 'Invalid or expired access token' in error: