Commit b8e62754 authored by Jo Sama's avatar Jo Sama 😱
Browse files

Add create_operator()

parent 23155895
......@@ -41,6 +41,7 @@ class TopDeskClient:
url,
headers=None,
params=None,
return_response=False,
**kwargs):
logger.debug('Calling %s %s with params=%r',
method_name,
......@@ -54,8 +55,12 @@ class TopDeskClient:
params=params if params is not None else {},
**kwargs)
logger.debug('GOT HTTP %d: %r', r.status_code, r.content)
r.raise_for_status()
return r.json()
if return_response:
return r
else:
r.raise_for_status()
return r.json()
def post(self, url, **kwargs):
return self.call('POST', url, **kwargs)
......@@ -70,6 +75,12 @@ class TopDeskClient:
url = self.urls.get_operator(identity)
return Operator.from_dict(self.get(url))
def create_operator(self, operator):
url = self.urls.get_operators()
self.post(url,
return_response=True,
data=operator.json(by_alias=True))
def list_operators(self):
for x in self.get(self.urls.get_operators()):
yield Operator.from_dict(x)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment