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



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/softlayer/Ticket.rb', line 155

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.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/softlayer/Ticket.rb', line 78

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.



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/softlayer/Ticket.rb', line 100

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.

Additionally you may provide options related to the request itself:

  • :object_mask (string) - The object mask of properties you wish to receive for the items returned.

    If not provided, the result will use the default object mask
    


126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/softlayer/Ticket.rb', line 126

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

  ticket_service = softlayer_client[:Ticket].object_with_id(ticket_id)
  ticket_service = ticket_service.object_mask(default_object_mask.to_sl_object_mask)
  ticket_service = ticket_service.object_mask(options[:object_mask]) if options[:object_mask]

  ticket_data    = ticket_service.getObject()

  return Ticket.new(softlayer_client, ticket_data)
end

Instance Method Details

#has_updates?Boolean

Returns true if the ticket has “unread” updates

Returns:

  • (Boolean)


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

def has_updates?
  self['newUpdatesFlag']
end

#last_edited_atObject

:attr_reader: last_edited_at The date the ticket was last updated.



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

sl_attr :last_edited_at, 'lastEditDate'

#lastEditDateObject

:attr_reader: The date the ticket was last updated.

DEPRECATION WARNING: This attribute is deprecated in favor of last_edited_at and will be removed in the next major release.



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

sl_attr :lastEditDate

#server_admin_ticket?Boolean

Returns true if the ticket is a server admin ticket

Returns:

  • (Boolean)


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

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.



56
57
58
# File 'lib/softlayer/Ticket.rb', line 56

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.



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/softlayer/Ticket.rb', line 63

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.



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

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