Commit 19cea5ff authored by Jo Sama's avatar Jo Sama 😱
Browse files

Make get_operator() work if no operator id

parent 19644768
......@@ -101,25 +101,33 @@ class TopDeskClient:
params['$fields'] = ','.join(fields)
def get_operator(self, identity):
if isinstance(identity, Operator):
url = self.urls.get_operator(
def _get_operator_by_id(ident):
url = self.urls.get_operator(ident)
r = self.get(url, return_response=True)
if r.status_code == 200:
return Operator.from_dict(r.json())
return None
def _get_operator_by_username(name):
url = self.urls.get_operators()
operators = [Operator.from_dict(x) for x in
params={'topdesk_login_name': identity})]
f = filter(lambda x: x.user_name.lower() == identity,
params={'topdesk_login_name': name})]
f = filter(lambda x: x.user_name.lower() == name,
return next(f)
except StopIteration:
return None
if isinstance(identity, Operator) and
return _get_operator_by_id(
elif isinstance(identity, Operator):
return _get_operator_by_username(identity.user_name)
return _get_operator_by_username(identity)
def create_operator(self, operator):
url = self.urls.get_operators()
# TODO: Remove password setting when proper auth arrives
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