Class: OTRS::Ticket

Inherits:
OTRS
  • Object
show all
Defined in:
lib/otrs_connector/otrs/ticket.rb

Direct Known Subclasses

Article, State, TicketQueue

Defined Under Namespace

Classes: Article, State, TicketQueue, Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OTRS

api_url, api_url=, #attributes, #connect, connect, get_from_remote, object_preprocessor, password, password=, process_response, setup_connection_params, user, user=

Constructor Details

#initialize(attributes = {}) ⇒ Ticket

Returns a new instance of Ticket.



33
34
35
36
37
# File 'lib/otrs_connector/otrs/ticket.rb', line 33

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name.to_s.underscore.to_sym}=", value)
  end
end

Instance Attribute Details

#ageObject

Returns the value of attribute age.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def age
  @age
end

#archive_flagObject

Returns the value of attribute archive_flag.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def archive_flag
  @archive_flag
end

#changedObject

Returns the value of attribute changed.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def changed
  @changed
end

#create_time_unixObject

Returns the value of attribute create_time_unix.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def create_time_unix
  @create_time_unix
end

#createdObject

Returns the value of attribute created.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def created
  @created
end

#customer_idObject

Returns the value of attribute customer_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def customer_id
  @customer_id
end

#customer_user_idObject

Returns the value of attribute customer_user_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def customer_user_id
  @customer_user_id
end

#escalation_response_timeObject

Returns the value of attribute escalation_response_time.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def escalation_response_time
  @escalation_response_time
end

#escalation_solution_timeObject

Returns the value of attribute escalation_solution_time.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def escalation_solution_time
  @escalation_solution_time
end

#escalation_timeObject

Returns the value of attribute escalation_time.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def escalation_time
  @escalation_time
end

#escalation_update_timeObject

Returns the value of attribute escalation_update_time.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def escalation_update_time
  @escalation_update_time
end

#group_idObject

Returns the value of attribute group_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def group_id
  @group_id
end

#lockObject

Returns the value of attribute lock.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def lock
  @lock
end

#lock_idObject

Returns the value of attribute lock_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def lock_id
  @lock_id
end

#ownerObject

Returns the value of attribute owner.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def owner
  @owner
end

#owner_idObject

Returns the value of attribute owner_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def owner_id
  @owner_id
end

#priorityObject

Returns the value of attribute priority.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def priority
  @priority
end

#priority_idObject

Returns the value of attribute priority_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def priority_id
  @priority_id
end

#queueObject

Returns the value of attribute queue.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def queue
  @queue
end

#queue_idObject

Returns the value of attribute queue_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def queue_id
  @queue_id
end

#real_till_time_not_usedObject

Returns the value of attribute real_till_time_not_used.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def real_till_time_not_used
  @real_till_time_not_used
end

#responsibleObject

Returns the value of attribute responsible.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def responsible
  @responsible
end

#responsible_idObject

Returns the value of attribute responsible_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def responsible_id
  @responsible_id
end

#service_idObject

Returns the value of attribute service_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def service_id
  @service_id
end

#slaidObject

Returns the value of attribute slaid.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def slaid
  @slaid
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def state
  @state
end

#state_idObject

Returns the value of attribute state_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def state_id
  @state_id
end

#state_typeObject

Returns the value of attribute state_type.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def state_type
  @state_type
end

#ticket_free_key1Object

Returns the value of attribute ticket_free_key1.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key1
  @ticket_free_key1
end

#ticket_free_key10Object

Returns the value of attribute ticket_free_key10.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key10
  @ticket_free_key10
end

#ticket_free_key11Object

Returns the value of attribute ticket_free_key11.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key11
  @ticket_free_key11
end

#ticket_free_key12Object

Returns the value of attribute ticket_free_key12.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key12
  @ticket_free_key12
end

#ticket_free_key13Object

Returns the value of attribute ticket_free_key13.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key13
  @ticket_free_key13
end

#ticket_free_key14Object

Returns the value of attribute ticket_free_key14.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key14
  @ticket_free_key14
end

#ticket_free_key15Object

Returns the value of attribute ticket_free_key15.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key15
  @ticket_free_key15
end

#ticket_free_key16Object

Returns the value of attribute ticket_free_key16.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key16
  @ticket_free_key16
end

#ticket_free_key2Object

Returns the value of attribute ticket_free_key2.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key2
  @ticket_free_key2
end

#ticket_free_key3Object

Returns the value of attribute ticket_free_key3.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key3
  @ticket_free_key3
end

#ticket_free_key4Object

Returns the value of attribute ticket_free_key4.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key4
  @ticket_free_key4
end

#ticket_free_key5Object

Returns the value of attribute ticket_free_key5.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key5
  @ticket_free_key5
end

#ticket_free_key6Object

Returns the value of attribute ticket_free_key6.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key6
  @ticket_free_key6
end

#ticket_free_key7Object

Returns the value of attribute ticket_free_key7.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key7
  @ticket_free_key7
end

#ticket_free_key8Object

Returns the value of attribute ticket_free_key8.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key8
  @ticket_free_key8
end

#ticket_free_key9Object

Returns the value of attribute ticket_free_key9.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_key9
  @ticket_free_key9
end

#ticket_free_text1Object

Returns the value of attribute ticket_free_text1.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text1
  @ticket_free_text1
end

#ticket_free_text10Object

Returns the value of attribute ticket_free_text10.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text10
  @ticket_free_text10
end

#ticket_free_text11Object

Returns the value of attribute ticket_free_text11.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text11
  @ticket_free_text11
end

#ticket_free_text12Object

Returns the value of attribute ticket_free_text12.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text12
  @ticket_free_text12
end

#ticket_free_text13Object

Returns the value of attribute ticket_free_text13.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text13
  @ticket_free_text13
end

#ticket_free_text14Object

Returns the value of attribute ticket_free_text14.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text14
  @ticket_free_text14
end

#ticket_free_text15Object

Returns the value of attribute ticket_free_text15.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text15
  @ticket_free_text15
end

#ticket_free_text16Object

Returns the value of attribute ticket_free_text16.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text16
  @ticket_free_text16
end

#ticket_free_text2Object

Returns the value of attribute ticket_free_text2.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text2
  @ticket_free_text2
end

#ticket_free_text3Object

Returns the value of attribute ticket_free_text3.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text3
  @ticket_free_text3
end

#ticket_free_text4Object

Returns the value of attribute ticket_free_text4.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text4
  @ticket_free_text4
end

#ticket_free_text5Object

Returns the value of attribute ticket_free_text5.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text5
  @ticket_free_text5
end

#ticket_free_text6Object

Returns the value of attribute ticket_free_text6.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text6
  @ticket_free_text6
end

#ticket_free_text7Object

Returns the value of attribute ticket_free_text7.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text7
  @ticket_free_text7
end

#ticket_free_text8Object

Returns the value of attribute ticket_free_text8.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text8
  @ticket_free_text8
end

#ticket_free_text9Object

Returns the value of attribute ticket_free_text9.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_text9
  @ticket_free_text9
end

#ticket_free_time1Object

Returns the value of attribute ticket_free_time1.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time1
  @ticket_free_time1
end

#ticket_free_time2Object

Returns the value of attribute ticket_free_time2.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time2
  @ticket_free_time2
end

#ticket_free_time3Object

Returns the value of attribute ticket_free_time3.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time3
  @ticket_free_time3
end

#ticket_free_time4Object

Returns the value of attribute ticket_free_time4.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time4
  @ticket_free_time4
end

#ticket_free_time5Object

Returns the value of attribute ticket_free_time5.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time5
  @ticket_free_time5
end

#ticket_free_time6Object

Returns the value of attribute ticket_free_time6.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_free_time6
  @ticket_free_time6
end

#ticket_idObject

Returns the value of attribute ticket_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_id
  @ticket_id
end

#ticket_numberObject

Returns the value of attribute ticket_number.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def ticket_number
  @ticket_number
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def title
  @title
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def type
  @type
end

#type_idObject

Returns the value of attribute type_id.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def type_id
  @type_id
end

#unlock_timeoutObject

Returns the value of attribute unlock_timeout.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def unlock_timeout
  @unlock_timeout
end

#until_timeObject

Returns the value of attribute until_time.



7
8
9
# File 'lib/otrs_connector/otrs/ticket.rb', line 7

def until_time
  @until_time
end

Class Method Details

.find(id) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/otrs_connector/otrs/ticket.rb', line 106

def self.find(id)
  data = { 'TicketID' => id, 'UserID' => 1 }
  params = { :object => 'TicketObject', :method => 'TicketGet', :data => data }
  object = self.object_preprocessor(connect(params))
  object.run_callbacks :find do
    object
  end
end

.free_text_fields(id) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/otrs_connector/otrs/ticket.rb', line 129

def self.free_text_fields(id)
  data = {:UserID => 1, :Type => 'TicketFreeText' + id.to_s}
  params = { :object => 'TicketObject', :method => 'TicketFreeTextGet', :data => data }
  a = self.connect(params).first.symbolize_keys
  #b = []
  #a.each do |key,value|
  #  b << [value,key]
  #end
  #return b
end

.ticket_number_lookup(ticket_id) ⇒ Object



39
40
41
42
43
# File 'lib/otrs_connector/otrs/ticket.rb', line 39

def self.ticket_number_lookup(ticket_id)
  data = { 'TicketID' => ticket_id, 'UserID' => 1 }
  params = { :object => 'TicketObject', :method => 'TicketNumberLookup', :data => data }
  connect(params).first
end

.where(attributes) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/otrs_connector/otrs/ticket.rb', line 116

def self.where(attributes)
  attributes['UserID'] = 1
  attributes['Result'] = 'ARRAY'
  data = attributes
  params = { :object => 'TicketObjectCustom', :method => 'TicketSearch', :data => data }
  a = connect(params)
  results = self.superclass::Relation.new
  a.each do |ticket|
    results << self.object_preprocessor(ticket)  #Add find results to array
  end
  results
end

Instance Method Details

#create(attributes) ⇒ Object



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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/otrs_connector/otrs/ticket.rb', line 51

def create(attributes)
  attributes[:type] ||= 'Incident'
  attributes[:state] ||= 'new'
  attributes[:queue] ||= 'Service Desk'
  attributes[:lock] ||= 'unlock'
  attributes[:priority] ||= '3 normal'
  attributes[:user_id] ||= '1'
  attributes[:owner_id] ||= attributes[:user_id]
  tmp = {}
  attributes.each do |key,value|
    if key == :user_id
      tmp[:UserID] = value
    end
    if key == :owner_id
      tmp[:OwnerID] = value
    end
    if key == :customer_id
      tmp[:CustomerID] = value
    end
    if key != :user_id or key != :owner_id or key != :customer_id
      tmp[key.to_s.camelize.to_sym] = value
    end

  end
  attributes = tmp
  data = attributes
  params = { :object => 'TicketObject', :method => 'TicketCreate', :data => data }
  a = connect(params)
  ticket_id = a.first
  article = OTRS::Ticket::Article.new(
    :ticket_id => ticket_id, 
    :body => attributes[:Body], 
    :email => attributes[:Email], 
    :title => attributes[:Title])
  if article.save
    ticket = self.class.find(ticket_id)
    attributes = ticket.attributes
    attributes.each do |key,value|
      instance_variable_set "@#{key.to_s}", value
    end
    ticket
  else
    ticket.destroy
    raise 'Could not create ticket'
  end
end

#destroyObject



98
99
100
101
102
103
104
# File 'lib/otrs_connector/otrs/ticket.rb', line 98

def destroy
  id = @ticket_id
  data = { 'TicketID' => id, 'UserID' => 1 }
  params = { :object => 'TicketObject', :method => 'TicketDelete', :data => data }
  connect(params)
  "Ticket ID: #{id} deleted"
end

#idObject



25
26
27
# File 'lib/otrs_connector/otrs/ticket.rb', line 25

def id
  self.ticket_id
end

#nameObject



147
148
149
# File 'lib/otrs_connector/otrs/ticket.rb', line 147

def name
  self.title
end

#persisted?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/otrs_connector/otrs/ticket.rb', line 29

def persisted?
  false
end

#saveObject



45
46
47
48
49
# File 'lib/otrs_connector/otrs/ticket.rb', line 45

def save
  run_callbacks :save do
    self.create(self.attributes)
  end
end

#set_free_text_field(id, key, value) ⇒ Object



140
141
142
143
144
145
# File 'lib/otrs_connector/otrs/ticket.rb', line 140

def set_free_text_field(id, key, value)
  data = { :UserID => 1, :Counter => id, :Key => key, :Value => value, :TicketID => self.id }
  params = { :object => 'TicketObject', :method => 'TicketFreeTextSet', :data => data }
  a = self.connect(params)
  if a.first == 1 then return true else return false end
end