some more cleanup

This commit is contained in:
NichtJens
2021-06-01 09:34:39 +02:00
parent f36e2534c4
commit b479455428

View File

@ -7,15 +7,15 @@ from .authmixin import AuthMixin, AuthError, HEADER_JSON
def authenticated(func): def authenticated(func):
@functools.wraps(func) @functools.wraps(func)
def authenticated_call(*args, **kwargs): def authenticated_call(client, *args, **kwargs):
if not issubclass(type(args[0]), HttpClient): if not isinstance(client, HttpClient):
raise AttributeError("First argument must be an instance of HttpClient") raise AttributeError("First argument must be an instance of HttpClient")
if "headers" in kwargs: if "headers" in kwargs:
kwargs["headers"] = kwargs["headers"].copy() kwargs["headers"] = kwargs["headers"].copy()
else: else:
kwargs["headers"] = {} kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = args[0].token kwargs["headers"]["Authorization"] = client.token
return func(*args, **kwargs) return func(client, *args, **kwargs)
return authenticated_call return authenticated_call
@ -51,8 +51,7 @@ class HttpClient(AuthMixin):
@authenticated @authenticated
def post_request(self, url, payload=None, headers=None, timeout=10): def post_request(self, url, payload=None, headers=None, timeout=10):
response = requests.post(url, json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json() return requests.post(url, json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()
return response
def _login(self, payload=None, headers=None, timeout=10): def _login(self, payload=None, headers=None, timeout=10):
return requests.post(self.address + "/users/login", json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json() return requests.post(self.address + "/users/login", json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()