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

Return None when no operator found

parent 19cea5ff
......@@ -107,15 +107,21 @@ class TopDeskClient:
if r.status_code == 200:
return Operator.from_dict(r.json())
else:
r.raise_for_status()
return None
def _get_operator_by_username(name):
url = self.urls.get_operators()
operators = [Operator.from_dict(x) for x in
self.get(url,
params={'topdesk_login_name': name})]
r = self.get(url,
params={'topdesk_login_name': name},
return_response=True)
if r.status_code == 204:
return None
else:
r.raise_for_status()
f = filter(lambda x: x.user_name.lower() == name,
operators)
[Operator.from_dict(x) for x in r.json()])
try:
return next(f)
except StopIteration:
......
Markdown is supported
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