mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2877 from matmair/matmair/issue2681
API Mixin cleanup
This commit is contained in:
commit
01ce571a75
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user