Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
it-bott-integrasjoner
topdesk-client
Commits
72b6d1b2
Commit
72b6d1b2
authored
Sep 12, 2019
by
Jo Sama
😱
Browse files
Better interface for get_(person|operator)
parent
049ce76a
Changes
1
Hide whitespace changes
Inline
Side-by-side
topdesk_client/client.py
View file @
72b6d1b2
...
...
@@ -88,23 +88,25 @@ class TopDeskClient:
def
patch
(
self
,
url
,
**
kwargs
):
return
self
.
call
(
'PATCH'
,
url
,
**
kwargs
)
def
get_operator
(
self
,
identity
=
None
,
username
=
None
):
if
identity
:
url
=
self
.
urls
.
get_operator
(
identity
)
return
Operator
.
from_dict
(
self
.
get
(
url
))
elif
username
:
def
get_operator
(
self
,
identity
):
if
isinstance
(
identity
,
Operator
):
url
=
self
.
urls
.
get_operator
(
identity
.
id
)
r
=
self
.
get
(
url
,
return_response
=
True
)
if
r
.
status_code
==
200
:
return
Operator
.
from_dict
(
r
.
json
())
else
:
return
None
else
:
url
=
self
.
urls
.
get_operators
()
operators
=
[
Operator
.
from_dict
(
x
)
for
x
in
self
.
get
(
url
,
params
=
{
'topdesk_login_name'
:
username
})]
f
=
filter
(
lambda
x
:
x
.
user_name
.
lower
()
==
username
,
params
=
{
'topdesk_login_name'
:
identity
})]
f
=
filter
(
lambda
x
:
x
.
user_name
.
lower
()
==
identity
,
operators
)
try
:
return
next
(
f
)
except
StopIteration
:
return
None
else
:
raise
ValueError
(
'identity or username must be set'
)
def
create_operator
(
self
,
operator
):
url
=
self
.
urls
.
get_operators
()
...
...
@@ -129,8 +131,24 @@ class TopDeskClient:
yield
Operator
.
from_dict
(
x
)
def
get_person
(
self
,
identity
):
url
=
self
.
urls
.
get_person
(
identity
)
return
Person
.
from_dict
(
self
.
get
(
url
))
if
isinstance
(
identity
,
Person
):
url
=
self
.
urls
.
get_person
(
identity
.
id
)
r
=
self
.
get
(
url
,
return_response
=
True
)
if
r
.
status_code
==
200
:
return
Person
.
from_dict
(
r
.
json
())
else
:
return
None
else
:
url
=
self
.
urls
.
get_persons
()
persons
=
[
Person
.
from_dict
(
x
)
for
x
in
self
.
get
(
url
,
params
=
{
'ssp_login_name'
:
identity
})]
f
=
filter
(
lambda
x
:
x
.
user_name
.
lower
()
==
identity
,
persons
)
try
:
return
next
(
f
)
except
StopIteration
:
return
None
def
create_person
(
self
,
person
):
url
=
self
.
urls
.
get_persons
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment