Skip to content

Commit 2f72deb

Browse files
committed
Added Service Desk REST API module.
Updated docs.
1 parent 0617300 commit 2f72deb

File tree

4 files changed

+182
-1
lines changed

4 files changed

+182
-1
lines changed

atlassian/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from .portfolio import Portfolio
66
from .bamboo import Bamboo
77
from .crowd import Crowd
8+
from .service_desk import ServiceDesk
89

9-
__all__ = ['Confluence', 'Jira', 'Bitbucket', 'Portfolio', 'Bamboo', 'Stash', 'Crowd']
10+
__all__ = ['Confluence', 'Jira', 'Bitbucket', 'Portfolio', 'Bamboo', 'Stash', 'Crowd', 'ServiceDesk']

atlassian/service_desk.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# coding: utf8
2+
import logging
3+
from .rest_client import AtlassianRestAPI
4+
5+
log = logging.getLogger(__name__)
6+
7+
8+
class ServiceDesk(AtlassianRestAPI):
9+
def get_info(self):
10+
""" Get info about Service Desk app """
11+
return self.get('/rest/servicedeskapi/info')
12+
13+
def create_customer(self, full_name, email):
14+
"""
15+
Creating customer user
16+
17+
:param full_name: str
18+
:param email: str
19+
:return: New customer
20+
"""
21+
log.warning('Creating customer...')
22+
data = {'fullName': full_name, 'email': email}
23+
headers = {'Content-Type': 'application/json',
24+
'Accept': 'application/json',
25+
'X-ExperimentalApi': 'opt-in'
26+
}
27+
return self.post('/rest/servicedeskapi/customer', headers=headers, data=data)
28+
29+
def get_customer_request(self, issue_id_or_key):
30+
"""
31+
Get single request
32+
33+
:param issue_id_or_key: str
34+
:return: Customer request
35+
"""
36+
return self.get('/rest/servicedeskapi/request/{}'.format(issue_id_or_key))
37+
38+
def get_my_customer_requests(self):
39+
""" Returning requests where you are the assignee """
40+
requests = self.get('/rest/servicedeskapi/request')
41+
requests_values = requests.get('values')
42+
return requests_values
43+
44+
def create_customer_request(self, service_desk_id, request_type_id, values_dict):
45+
"""
46+
Creating customer request
47+
48+
:param service_desk_id: str
49+
:param request_type_id: str
50+
:param values_dict: str
51+
:return: New request
52+
"""
53+
log.warning('Creating request...')
54+
data = {"serviceDeskId": service_desk_id,
55+
"requestTypeId": request_type_id,
56+
"requestFieldValues": values_dict
57+
}
58+
return self.post('/rest/servicedeskapi/request', data=data)
59+
60+
def get_customer_request_status(self, issue_id_or_key):
61+
"""
62+
Get customer request status name
63+
64+
:param issue_id_or_key: str
65+
:return: Status name
66+
"""
67+
request = self.get('/rest/servicedeskapi/request/{}/status'.format(issue_id_or_key)).get('values')
68+
status = request[0].get('status')
69+
return status
70+
71+
def perform_transition(self, issue_id_or_key, transition_id, comment=None):
72+
"""
73+
Perform a customer transition for a given request and transition ID.
74+
An optional comment can be included to provide a reason for the transition.
75+
76+
:param issue_id_or_key: str
77+
:param transition_id: str
78+
:param comment: OPTIONAL: str
79+
:return: None
80+
"""
81+
log.warning('Performing transition...')
82+
headers = {'Content-Type': 'application/json',
83+
'Accept': 'application/json',
84+
'X-ExperimentalApi': 'opt-in'
85+
}
86+
data = {'id': transition_id, 'additionalComment': {'body': comment}}
87+
url = '/rest/servicedeskapi/request/{}/transition'.format(issue_id_or_key)
88+
return self.post(url, headers=headers, data=data)
89+
90+
def create_request_comment(self, issue_id_or_key, body, public=True):
91+
"""
92+
Creating request comment
93+
94+
:param issue_id_or_key: str
95+
:param body: str
96+
:param public: OPTIONAL: bool (default is True)
97+
:return: New comment
98+
"""
99+
log.warning('Creating comment...')
100+
data = {"body": body, "public": public}
101+
return self.post('/rest/servicedeskapi/request/{}/comment'.format(issue_id_or_key), data=data)
102+
103+
def get_request_comments(self, issue_id_or_key):
104+
"""
105+
Get all comments in issue
106+
107+
:param issue_id_or_key: str
108+
:return: Issue comments
109+
"""
110+
return self.get('/rest/servicedeskapi/request/{}/comment'.format(issue_id_or_key))
111+
112+
def get_request_comment_by_id(self, issue_id_or_key, comment_id):
113+
"""
114+
Get single comment by ID
115+
116+
:param issue_id_or_key: str
117+
:param comment_id: str
118+
:return: Single comment
119+
"""
120+
return self.get('/rest/servicedeskapi/request/{0}/comment/{1}'.format(issue_id_or_key, comment_id))

docs/index.rst

+6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ Add a connection:
3737
username='admin',
3838
password='admin')
3939
40+
service_desk = ServiceDesk(
41+
url='http://localhost:8080',
42+
username='admin',
43+
password='admin')
44+
4045
.. toctree::
4146
:maxdept:2
4247

4348
jira
4449
confluence
4550
bitbucket
51+
service_desk
4652

4753
.. |Build Status| image:: https://travis-ci.org/AstroMatt/atlassian-python-api.svg?branch=master
4854
:target: https://pypi.python.org/pypi/atlassian-python-api

docs/service_desk.rst

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Jira Service Desk module
2+
========================
3+
4+
Get info about Service Desk
5+
---------------------------
6+
7+
.. code-block:: python
8+
9+
sd.get_info()
10+
11+
Create customer
12+
---------------
13+
14+
**EXPERIMENTAL** (may change without notice)
15+
16+
.. code-block:: python
17+
18+
sd.create_customer(full_name, email)
19+
20+
The Request actions
21+
-------------------
22+
23+
.. code-block:: python
24+
25+
# Create customer request
26+
sd.create_customer_request(service_desk_id, request_type_id, values_dict)
27+
28+
# Get customer request by ID
29+
sd.get_customer_request(issue_id_or_key)
30+
31+
# Get customer requests
32+
sd.get_my_customer_requests()
33+
34+
# Get customer request status
35+
sd.get_customer_request_status(issue_id_or_key)
36+
37+
# Create comment. Optional argument public (True or False), default is True
38+
sd.create_request_comment(issue_id_or_key, body, public=True)
39+
40+
# Get request comments
41+
sd.get_request_comments(issue_id_or_key)
42+
43+
# Get request comment
44+
sd.get_request_comment_by_id(issue_id_or_key, comment_id)
45+
46+
Transitions
47+
-----------
48+
49+
**EXPERIMENTAL** (may change without notice)
50+
51+
.. code-block:: python
52+
53+
# Perform transition. Optional argument comment (string), default is None
54+
sd.perform_transition(issue_id_or_key, transition_id, comment=None)

0 commit comments

Comments
 (0)