Class: Sirportly::Ticket

Inherits:
DataObject show all
Defined in:
lib/sirportly/data_objects/ticket.rb

Instance Attribute Summary

Attributes inherited from DataObject

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DataObject

all, find, #initialize, #inspect, #method_missing

Constructor Details

This class inherits a constructor from Sirportly::DataObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sirportly::DataObject

Class Method Details

.create(client, params = {}) ⇒ Object

Creates a new ticket and returns a ticket object



64
65
66
67
68
69
70
# File 'lib/sirportly/data_objects/ticket.rb', line 64

def self.create(client, params = {})
  if req = client.request('tickets/submit', format_params(params))
    self.new(client, req)
  else
    false
  end
end

.filter(client, filter, options = {}) ⇒ Object

Returns tickets which match the passed filter



82
83
84
85
86
87
88
89
90
# File 'lib/sirportly/data_objects/ticket.rb', line 82

def self.filter(client, filter, options = {})
  filter = filter.id if filter.is_a?(Sirportly::Filter)
  options[:user] = options[:user].id if options[:user].is_a?(Sirportly::User)
  if req = client.request('tickets/filter', options.merge({:filter => filter}))
    DataSet.new(client, req, self)
  else
    false
  end
end

.search(client, query, page = 1) ⇒ Object

Returns a DataSet containing tickets matching the passed query and page number.



73
74
75
76
77
78
79
# File 'lib/sirportly/data_objects/ticket.rb', line 73

def self.search(client, query, page = 1)
  if req = client.request('tickets/search', :query => query, :page => page)
    DataSet.new(client, req, self)
  else
    false
  end
end

Instance Method Details

#add_attachment(params = {}) ⇒ Object

Allows you to upload attachments to existing ticket updates. Accepts a hash of parameters needed to create the attachment.



41
42
43
44
45
46
47
# File 'lib/sirportly/data_objects/ticket.rb', line 41

def add_attachment(params = {})
  if req = client.request('tickets/add_attachment', format_params(params))
    true
  else
    false
  end
end

#add_follow_up(params = {}) ⇒ Object

Adds a follow up to the ticket



50
51
52
53
54
55
56
# File 'lib/sirportly/data_objects/ticket.rb', line 50

def add_follow_up(params = {})
  if req = client.request('tickets/followup', format_params(params))
    true
  else
    false
  end
end

#destroyObject

Permanently removes the ticket



59
60
61
# File 'lib/sirportly/data_objects/ticket.rb', line 59

def destroy
  client.request('tickets/permanently_delete', {:ticket => @attributes['reference']})
end

#post_update(params = {}) ⇒ Object

Posts a new update to the ticket. Accepts a hash of parameters needed to create the update.



30
31
32
33
34
35
36
37
38
# File 'lib/sirportly/data_objects/ticket.rb', line 30

def post_update(params = {})
  if req = client.request('tickets/post_update', format_params(params))
    update = TicketUpdate.new(@client, req)
    (@attributes['updates'] ||= []) << update
    update
  else
    false
  end
end

#run_macro(name_or_id) ⇒ Object

Executes a macro on the ticket. Accepts the name of ID of the macro you wish to execute as a string or an integer.



10
11
12
13
14
15
16
17
# File 'lib/sirportly/data_objects/ticket.rb', line 10

def run_macro(name_or_id)
  if req = client.request('tickets/macro', :ticket => @attributes['reference'], :macro => name_or_id.to_s)
    set_attributes(req)
    true
  else
    false
  end
end

#update(params) ⇒ Object

Updates ticket parameters. Accepts a hash with the parameters which you wish to update.



20
21
22
23
24
25
26
27
# File 'lib/sirportly/data_objects/ticket.rb', line 20

def update(params)      
  if req = client.request('tickets/update', format_params(params))
    set_attributes(req)
    true
  else
    false
  end
end