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):
@functools.wraps(func)
def authenticated_call(*args, **kwargs):
if not issubclass(type(args[0]), HttpClient):
def authenticated_call(client, *args, **kwargs):
if not isinstance(client, HttpClient):
raise AttributeError("First argument must be an instance of HttpClient")
if "headers" in kwargs:
kwargs["headers"] = kwargs["headers"].copy()
else:
kwargs["headers"] = {}
kwargs["headers"]["Authorization"] = args[0].token
return func(*args, **kwargs)
kwargs["headers"]["Authorization"] = client.token
return func(client, *args, **kwargs)
return authenticated_call
@ -51,8 +51,7 @@ class HttpClient(AuthMixin):
@authenticated
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 response
return requests.post(url, json=payload, headers=headers, timeout=timeout, verify=self._verify_certificate).json()
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()