Class: SoftLayer::Ticket

Inherits:
ModelBase show all
Defined in:
lib/softlayer/Ticket.rb

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelBase

#[], #has_sl_property?, #initialize, #refresh_details, sl_attr, #to_ary

Constructor Details

This class inherits a constructor from SoftLayer::ModelBase

Class Method Details

.create_standard_ticket(options = {}) ⇒ Object

Create and submit a new support Ticket to SoftLayer.

The options parameter should contain:

:client - The client used to connect to the API

If no client is given, then the routine will try to use Client.default_client If no client can be found the routine will raise an error.

The options should also contain:

  • :title (String) - The user provided title for the ticket.

  • :body (String) - The content of the ticket

  • :subject_id (Int) - The id of a subject to use for the ticket. A list of ticket subjects can be returned by SoftLayer::Ticket.ticket_subjects

  • :assigned_user_id (Int) - The id of a user to whom the ticket should be assigned



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/softlayer/Ticket.rb', line 146

def self.create_standard_ticket(options = {})
  softlayer_client = options[:client] || SoftLayer::Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  title = options[:title]
  body = options[:body]
  subject_id = options[:subject_id]
  assigned_user_id = options[:assigned_user_id]

  if(nil == assigned_user_id)
    current_user = softlayer_client[:Account].object_mask("id").getCurrentUser()
    assigned_user_id = current_user['id']
  end

  new_ticket = {
    'subjectId' => subject_id,
    'contents' => body,
    'assignedUserId' => assigned_user_id,
    'title' => title
  }

  ticket_data = softlayer_client[:Ticket].createStandardTicket(new_ticket, body)
  return new(softlayer_client, ticket_data)
end

.default_object_maskObject

Returns the default object mask,as a hash, that is used when retrieving ticket information from the SoftLayer server.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/softlayer/Ticket.rb', line 70

def self.default_object_mask
    {
      "mask" => [
        'id',							# This is an internal ticket ID, not the one usually seen in the portal
        'serviceProvider',
        'serviceProviderResourceId', 	# This is the ticket ID usually seen in the portal
        'title',
        'subject',
        {'assignedUser' => ['username', 'firstName', 'lastName'] },
        'status.id',
        'createDate',
        'lastEditDate',
        'newUpdatesFlag',             # This comes in from the server as a Boolean value
        'awaitingUserResponseFlag',   # This comes in from the server as a Boolean value
        'serverAdministrationFlag',   # This comes in from the server as an integer :-(
      ]
    }.to_sl_object_mask
end

.ticket_subjects(client = nil) ⇒ Object

Queries the SoftLayer API to retrieve a list of the valid ticket subjects.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/softlayer/Ticket.rb', line 92

def self.ticket_subjects(client = nil)
	@ticket_subjects ||= nil

	if !@ticket_subjects
      softlayer_client = client || Client.default_client
      raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

		@ticket_subjects = softlayer_client[:Ticket_Subject].getAllObjects();
	end

	@ticket_subjects
end

.ticket_with_id(ticket_id, options = {}) ⇒ Object

Find the ticket with the given ID and return it

Options should contain:

:client - the client in which to search for the ticket

If a client is not provided then the routine will search Client::default_client If Client::default_client is also nil the routine will raise an error.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/softlayer/Ticket.rb', line 115

def self.ticket_with_id(ticket_id, options = {})
  softlayer_client = options[:client] || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  if options.has_key?(:object_mask)
    object_mask = options[:object_mask]
  else
    object_mask = default_object_mask.to_sl_object_mask
  end

  ticket_data = softlayer_client[:Ticket].object_with_id(ticket_id).object_mask(object_mask).getObject()

  return new(softlayer_client, ticket_data)
end

Instance Method Details

#has_updates?Boolean

Returns true if the ticket has “unread” updates

Returns:

  • (Boolean)


27
28
29
# File 'lib/softlayer/Ticket.rb', line 27

def has_updates?
  self['newUpdatesFlag']
end

#lastEditDateObject

:attr_reader: The date the ticket was last updated.



23
# File 'lib/softlayer/Ticket.rb', line 23

sl_attr :lastEditDate

#server_admin_ticket?Boolean

Returns true if the ticket is a server admin ticket

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/softlayer/Ticket.rb', line 33

def server_admin_ticket?
  # note that serverAdministrationFlag comes from the server as an Integer (0, or 1)
  self['serverAdministrationFlag'] != 0
end

#serviceObject

Override of service from ModelBase. Returns the SoftLayer_Ticket service set up to talk to the ticket with my ID.



48
49
50
# File 'lib/softlayer/Ticket.rb', line 48

def service
  return softlayer_client[:Ticket].object_with_id(self.id)
end

#softlayer_properties(object_mask = nil) ⇒ Object

Override from model base. Requests new details about the ticket from the server.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/softlayer/Ticket.rb', line 55

def softlayer_properties(object_mask = nil)
    my_service = self.service

    if(object_mask)
      my_service = service.object_mask(object_mask)
    else
      my_service = service.object_mask(self.class.default_object_mask.to_sl_object_mask)
    end

    my_service.getObject()
end

#subjectObject

:attr_reader: The ticket system maintains a fixed set of subjects for tickets that are used to ensure tickets make it to the right folks quickly



18
# File 'lib/softlayer/Ticket.rb', line 18

sl_attr :subject

#titleObject

:attr_reader: The title is an identifying string set when the ticket is created



13
# File 'lib/softlayer/Ticket.rb', line 13

sl_attr :title

#update(body = nil) ⇒ Object

Add an update to this ticket.



41
42
43
# File 'lib/softlayer/Ticket.rb', line 41

def update(body = nil)
	self.service.edit(self.softlayer_hash, body)
end