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
7ad56e70
Commit
7ad56e70
authored
Oct 30, 2019
by
Jonas Braathen
Browse files
Add method for listing operator groups
parent
5d386029
Changes
2
Hide whitespace changes
Inline
Side-by-side
topdesk_client/client.py
View file @
7ad56e70
...
...
@@ -5,7 +5,7 @@ import uuid
from
typing
import
Optional
,
List
,
Iterator
from
urllib.parse
import
urljoin
,
urlparse
from
.models
import
(
Branch
,
BranchReference
,
Operator
,
Person
,
from
.models
import
(
Branch
,
BranchReference
,
Operator
,
OperatorGroup
,
Person
,
Department
,
DepartmentRef
,
BudgetHolder
,
BudgetHolderRef
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -21,6 +21,9 @@ class Endpoints:
def
list_branches
(
self
):
return
self
.
_prepend_base_url
(
'branches/'
)
def
list_operatorgroups
(
self
):
return
self
.
_prepend_base_url
(
'operatorgroups'
)
def
get_branch
(
self
,
branch_id
):
return
urljoin
(
self
.
_prepend_base_url
(
'branches/id/'
),
branch_id
)
...
...
@@ -102,6 +105,25 @@ class TopDeskClient:
def
patch
(
self
,
url
,
**
kwargs
):
return
self
.
call
(
'PATCH'
,
url
,
**
kwargs
)
def
depaginate
(
self
,
url
,
page_size
=
100
):
offset
=
0
while
True
:
params
=
{
'page_size'
:
page_size
,
'start'
:
offset
,
}
page
=
self
.
get
(
url
,
params
=
params
,
return_response
=
True
)
if
page
.
status_code
==
204
:
break
data
=
page
.
json
()
for
item
in
data
:
yield
item
num
=
len
(
data
)
if
num
<
page_size
:
break
if
num
==
page_size
:
offset
+=
num
def
include_fields
(
self
,
params
:
dict
,
fields
:
Optional
[
List
[
str
]]
=
None
)
->
None
:
if
not
fields
:
return
...
...
@@ -215,6 +237,11 @@ class TopDeskClient:
for
x
in
self
.
get
(
self
.
urls
.
get_operators
()):
yield
Operator
.
from_dict
(
x
)
def
list_operatorgroups
(
self
):
url
=
self
.
urls
.
list_operatorgroups
()
for
x
in
self
.
depaginate
(
url
):
yield
OperatorGroup
.
from_dict
(
x
)
def
get_person
(
self
,
identity
):
if
isinstance
(
identity
,
Person
):
url
=
self
.
urls
.
get_person
(
identity
.
id
)
...
...
topdesk_client/models.py
View file @
7ad56e70
...
...
@@ -190,6 +190,17 @@ class Operator(BaseModel):
return
super
(
Operator
,
self
).
dict
(
*
args
,
**
kwargs
)
class
OperatorGroup
(
BaseModel
):
id
:
str
groupName
:
str
# TODO: add the other 40 fields if needed
class
Config
:
fields
=
{
'name'
:
{
'alias'
:
'groupName'
},
}
class
ExternalLink
(
BaseModel
):
id
:
str
type
:
str
...
...
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