mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 10:59:00 +00:00
Merge pull request #319 from Reena-cell/develop
feature/ improve API_VERSION in settings
This commit is contained in:
commit
e47dc316ab
@ -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' + OBPv500 + '/swagger' # noqa
|
||||
|
||||
if not OAUTH_CONSUMER_KEY:
|
||||
raise ImproperlyConfigured('Missing settings for OAUTH_CONSUMER_KEY')
|
||||
|
||||
@ -17,6 +17,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from base.utils import exception_handle, error_once_only
|
||||
from django.conf import settings
|
||||
|
||||
CHOOSE = "Choose..."
|
||||
|
||||
@ -203,6 +204,7 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
template_name = "atms/update.html"
|
||||
success_url = '/atms/list'
|
||||
form_class = CreateAtmForm
|
||||
v510 = settings.API_ROOT['v510']
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.api = API(request.session.get('obp'))
|
||||
@ -374,7 +376,7 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
def atm_attributes(self, **kwargs):
|
||||
atm_attributes_url_path = "/banks/{}/atms/{}/attributes".format(self.kwargs['bank_id'], self.kwargs['atm_id'])
|
||||
try:
|
||||
atm_attributes_result = self.api.get(atm_attributes_url_path)["atm_attributes"]
|
||||
atm_attributes_result = self.api.get(atm_attributes_url_path, version=self.v510)["atm_attributes"]
|
||||
return atm_attributes_result
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error {}".format(err))
|
||||
@ -408,7 +410,7 @@ def atm_attribute_save(request):
|
||||
'value': request.POST.get('value').strip(),
|
||||
'is_active': True
|
||||
}
|
||||
result = api.post(urlpath_save, payload = payload)
|
||||
result = api.post(urlpath_save, payload = payload, version=settings.API_ROOT['v510'])
|
||||
return result
|
||||
|
||||
|
||||
@ -426,7 +428,7 @@ def atm_attribute_update(request):
|
||||
'value': request.POST.get('value').strip(),
|
||||
'is_active': True
|
||||
}
|
||||
result = api.put(urlpath_update, payload=payload)
|
||||
result = api.put(urlpath_update, payload=payload, version=settings.API_ROOT['v510'])
|
||||
return result
|
||||
|
||||
|
||||
@ -439,7 +441,7 @@ def atm_attribute_delete(request):
|
||||
|
||||
api = API(request.session.get('obp'))
|
||||
urlpath_delete = '/banks/{}/atms/{}/attributes/{}'.format(bank_id, atm_id, atm_attribute_id)
|
||||
result = api.delete(urlpath_delete)
|
||||
result = api.delete(urlpath_delete, version=settings.API_ROOT['v510'])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ def api_username(request):
|
||||
"""Returns the API username/email of the logged-in user"""
|
||||
nametodisplay = 'not authenticated'
|
||||
get_current_user_api_url = USER_CURRENT
|
||||
#Here we can not get the user from obp-api side, so we use the django auth user id here.
|
||||
#Here we can not get the user from obp-api side, so we use the django auth user id here.
|
||||
cache_key_django_user_id = request.session._session.get('_auth_user_id')
|
||||
cache_key = '{},{},{}'.format('api_username',get_current_user_api_url, cache_key_django_user_id)
|
||||
apicaches=None
|
||||
|
||||
@ -43,7 +43,7 @@ class API(object):
|
||||
self.start_session(session_data)
|
||||
self.session_data = session_data
|
||||
|
||||
def call(self, method='GET', url='', payload=None):
|
||||
def call(self, method='GET', url='', payload=None, version=settings.API_ROOT['v500']):
|
||||
"""Workhorse which actually calls the API"""
|
||||
log(logging.INFO, '{} {}'.format(method, url))
|
||||
if payload:
|
||||
@ -64,46 +64,46 @@ class API(object):
|
||||
response.execution_time = elapsed
|
||||
return response
|
||||
|
||||
def get(self, urlpath=''):
|
||||
def get(self, urlpath='', version=settings.API_ROOT['v500']):
|
||||
"""
|
||||
Gets data from the API
|
||||
|
||||
Convenience call which uses API_ROOT from settings
|
||||
"""
|
||||
url = settings.API_ROOT + urlpath
|
||||
url = version + urlpath
|
||||
response = self.handle_response(self.call('GET', url))
|
||||
if response is not None and 'code' in response:
|
||||
raise APIError(response['message'])
|
||||
else:
|
||||
else:
|
||||
return response
|
||||
|
||||
def delete(self, urlpath):
|
||||
def delete(self, urlpath, version=settings.API_ROOT['v500']):
|
||||
"""
|
||||
Deletes data from the API
|
||||
|
||||
Convenience call which uses API_ROOT from settings
|
||||
"""
|
||||
url = settings.API_ROOT + urlpath
|
||||
url = version + urlpath
|
||||
response = self.call('DELETE', url)
|
||||
return self.handle_response(response)
|
||||
|
||||
def post(self, urlpath, payload):
|
||||
def post(self, urlpath, payload, version=settings.API_ROOT['v500']):
|
||||
"""
|
||||
Posts data to given urlpath with given payload
|
||||
|
||||
Convenience call which uses API_ROOT from settings
|
||||
"""
|
||||
url = settings.API_ROOT + urlpath
|
||||
url = version + urlpath
|
||||
response = self.call('POST', url, payload)
|
||||
return self.handle_response(response)
|
||||
|
||||
def put(self, urlpath, payload):
|
||||
def put(self, urlpath, payload, version=settings.API_ROOT['v500']):
|
||||
"""
|
||||
Puts data on given urlpath with given payload
|
||||
|
||||
Convenience call which uses API_ROOT from settings
|
||||
"""
|
||||
url = settings.API_ROOT + urlpath
|
||||
url = version + urlpath
|
||||
response = self.call('PUT', url, payload)
|
||||
return self.handle_response(response)
|
||||
|
||||
@ -182,4 +182,4 @@ class API(object):
|
||||
result = self.get('/users')
|
||||
for user in result['users']:
|
||||
choices.append((user['user_id'], user['username']))
|
||||
return choices
|
||||
return choices
|
||||
Loading…
Reference in New Issue
Block a user