fix api call

This commit is contained in:
Matthias 2022-04-26 01:32:31 +02:00
parent e7357726ca
commit 1603bf4e60
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -504,10 +504,10 @@ class APICallMixin:
@property @property
def api_headers(self): def api_headers(self):
return { headers = {'Content-Type': 'application/json'}
self.API_TOKEN: self.get_setting(self.API_TOKEN_SETTING), if getattr(self, 'API_TOKEN_SETTING'):
'Content-Type': 'application/json' headers[self.API_TOKEN] = self.get_setting(self.API_TOKEN_SETTING)
} return headers
def api_build_url_args(self, arguments): def api_build_url_args(self, arguments):
groups = [] groups = []
@ -515,16 +515,21 @@ class APICallMixin:
groups.append(f'{key}={",".join([str(a) for a in val])}') groups.append(f'{key}={",".join([str(a) for a in val])}')
return f'?{"&".join(groups)}' return f'?{"&".join(groups)}'
def api_call(self, endpoint, method: str = 'GET', url_args=None, data=None, headers=None, simple_response: bool = True): def api_call(self, endpoint, method: str = 'GET', url_args=None, data=None, headers=None, simple_response: bool = True, endpoint_is_url: bool = False):
if url_args: if url_args:
endpoint += self.api_build_url_args(url_args) endpoint += self.api_build_url_args(url_args)
if headers is None: if headers is None:
headers = self.api_headers headers = self.api_headers
if endpoint_is_url:
url = endpoint
else:
url = f'{self.api_url}/{endpoint}'
# build kwargs for call # build kwargs for call
kwargs = { kwargs = {
'url': f'{self.api_url}/{endpoint}', 'url': url,
'headers': headers, 'headers': headers,
} }
if data: if data: