|
| 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)) |
0 commit comments