forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathticket.py
More file actions
81 lines (62 loc) · 2.54 KB
/
ticket.py
File metadata and controls
81 lines (62 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
SoftLayer.ticket
~~~~~~~~~~~~~~~~
Ticket Manager/helpers
:license: MIT, see LICENSE for more details.
"""
from SoftLayer import utils
class TicketManager(utils.IdentifierMixin, object):
"""Manages support Tickets.
:param SoftLayer.API.Client client: an API client instance
"""
def __init__(self, client):
self.client = client
self.account = self.client['Account']
self.ticket = self.client['Ticket']
def list_tickets(self, open_status=True, closed_status=True):
"""List all tickets.
:param boolean open_status: include open tickets
:param boolean closed_status: include closed tickets
"""
mask = ('id, title, assignedUser[firstName, lastName],'
'createDate,lastEditDate,accountId,status')
call = 'getTickets'
if not all([open_status, closed_status]):
if open_status:
call = 'getOpenTickets'
elif closed_status:
call = 'getClosedTickets'
return self.client.call('Account', call, mask=mask)
def list_subjects(self):
"""List all tickets."""
return self.client['Ticket_Subject'].getAllObjects()
def get_ticket(self, ticket_id):
"""Get details about a ticket.
:param integer id: the ticket ID
:returns: A dictionary containing a large amount of information about
the specified ticket.
"""
mask = ('id, title, assignedUser[firstName, lastName],status,'
'createDate,lastEditDate,updates[entry,editor],updateCount')
return self.ticket.getObject(id=ticket_id, mask=mask)
def create_ticket(self, title=None, body=None, subject=None):
"""Create a new ticket.
:param string title: title for the new ticket
:param string body: body for the new ticket
:param integer subject: id of the subject to be assigned to the ticket
"""
current_user = self.account.getCurrentUser()
new_ticket = {
'subjectId': subject,
'contents': body,
'assignedUserId': current_user['id'],
'title': title,
}
created_ticket = self.ticket.createStandardTicket(new_ticket, body)
return created_ticket
def update_ticket(self, ticket_id=None, body=None):
"""Update a ticket.
:param integer ticket_id: the id of the ticket to update
:param string body: entry to update in the ticket
"""
return self.ticket.addUpdate({'entry': body}, id=ticket_id)