otrs_connector 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.2.0
@@ -172,25 +172,30 @@ class OTRS::Change::WorkOrder < OTRS
172
172
  end
173
173
 
174
174
  def update_attributes(attributes)
175
- tmp = {}
176
- attributes.each do |key,value|
177
- tmp[key.to_s.camelize] = value #Copies ruby style keys to camel case for OTRS
178
- end
179
- tmp['WorkOrderID'] = @work_order_id
180
- data = tmp
181
- params = { :object => 'WorkOrderObject', :method => 'WorkOrderUpdate', :data => data }
182
- a = connect(params)
183
- if a.first.nil?
184
- nil
185
- else
186
- return self
175
+ run_callbacks :update do
176
+ tmp = {}
177
+ attributes.each do |key,value|
178
+ tmp[key.to_s.camelize] = value #Copies ruby style keys to camel case for OTRS
179
+ end
180
+ tmp['WorkOrderID'] = @work_order_id
181
+ data = tmp
182
+ params = { :object => 'WorkOrderObject', :method => 'WorkOrderUpdate', :data => data }
183
+ a = connect(params)
184
+ if a.first.nil?
185
+ nil
186
+ else
187
+ return self
188
+ end
187
189
  end
188
190
  end
189
191
 
190
192
  def self.find(id)
191
193
  data = { 'WorkOrderID' => id, 'UserID' => 1 }
192
194
  params = { :object => 'WorkOrderObject', :method => 'WorkOrderGet', :data => data }
193
- self.object_preprocessor connect(params)
195
+ object = self.object_preprocessor connect(params)
196
+ object.run_callbacks :find do
197
+ object
198
+ end
194
199
  end
195
200
 
196
201
  def destroy
@@ -74,7 +74,9 @@ class OTRS::Change < OTRS
74
74
  end
75
75
 
76
76
  def save
77
- self.create(self.attributes)
77
+ run_callbacks :save do
78
+ self.create(self.attributes)
79
+ end
78
80
  end
79
81
 
80
82
  def create(attributes)
@@ -98,7 +100,10 @@ class OTRS::Change < OTRS
98
100
  def self.find(id)
99
101
  data = { 'ChangeID' => id, 'UserID' => 1 }
100
102
  params = { :object => 'ChangeObject', :method => 'ChangeGet', :data => data }
101
- self.object_preprocessor connect(params)
103
+ object = self.object_preprocessor connect(params)
104
+ object.run_callbacks :find do
105
+ object
106
+ end
102
107
  end
103
108
 
104
109
 
@@ -31,7 +31,9 @@ class OTRS::ConfigItem < OTRS
31
31
  end
32
32
 
33
33
  def save
34
- self.create
34
+ run_callbacks :save do
35
+ self.create
36
+ end
35
37
  end
36
38
 
37
39
  def create
@@ -78,14 +80,20 @@ class OTRS::ConfigItem < OTRS
78
80
  def self.find(id)
79
81
  data = { 'ConfigItemID' => id, 'XMLDataGet' => 1 }
80
82
  params = { :object => 'ConfigItemObjectCustom', :method => 'VersionGet', :data => data }
81
- self.object_preprocessor (connect(params).first)
83
+ object = self.object_preprocessor (connect(params).first)
84
+ object.run_callbacks :find do
85
+ object
86
+ end
82
87
  end
83
88
 
84
89
  # Find by Version ID
85
90
  def self.find_version(id)
86
91
  data = { 'VersionID' => id, 'XMLDataGet' => 1 }
87
92
  params = { :object => 'ConfigItemObject', :method => 'VersionGet', :data => data }
88
- return self.object_preprocessor (connect(params).first)
93
+ object = self.object_preprocessor (connect(params).first)
94
+ object.run_callbacks :find do
95
+ object
96
+ end
89
97
  end
90
98
 
91
99
  def self.where(attributes)
@@ -166,32 +174,34 @@ class OTRS::ConfigItem < OTRS
166
174
  end
167
175
 
168
176
  def update_attributes(updated_attributes)
169
- self.attributes.each do |key,value|
170
- if updated_attributes[key].nil?
171
- updated_attributes[key] = value
177
+ run_callbacks :update do
178
+ self.attributes.each do |key,value|
179
+ if updated_attributes[key].nil?
180
+ updated_attributes[key] = value
181
+ end
172
182
  end
183
+ updated_attributes[:XMLData] = self.class.to_otrs_xml(updated_attributes)
184
+ xml_attributes = self.attributes.except(:Name,:DeplStateID,:InciStateID,:DefinitionID,
185
+ :CreateTime,:ChangeBy,:ChangeTime,:Class,:ClassID,:ConfigItemID,:CreateBy,:CreateTime,
186
+ :CurDeplState,:CurDeplStateID,:CurDeplStateType,:CurInciState,:CurInciStateID,:CurInciStateType,
187
+ :DeplState,:DeplStateType,:InciState,:InciStateType,:LastVersionID,:Number,:VersionID)
188
+ xml_attributes.each do |key,value|
189
+ updated_attributes = updated_attributes.except(key)
190
+ end
191
+ data = updated_attributes
192
+ params = { :object => 'ConfigItemObject', :method => 'VersionAdd', :data => data }
193
+ a = self.class.connect(params)
194
+ new_version_id = a.first
195
+ data2 = { 'VersionID' => new_version_id }
196
+ params2 = { :object => 'ConfigItemObject', :method => 'VersionConfigItemIDGet', :data => data2 }
197
+ b = self.class.connect(params2)
198
+ config_item = self.class.find(b.first)
199
+ attributes = config_item.attributes
200
+ attributes.each do |key,value|
201
+ instance_variable_set "@#{key.to_s}", value
202
+ end
203
+ config_item
173
204
  end
174
- updated_attributes[:XMLData] = self.class.to_otrs_xml(updated_attributes)
175
- xml_attributes = self.attributes.except(:Name,:DeplStateID,:InciStateID,:DefinitionID,
176
- :CreateTime,:ChangeBy,:ChangeTime,:Class,:ClassID,:ConfigItemID,:CreateBy,:CreateTime,
177
- :CurDeplState,:CurDeplStateID,:CurDeplStateType,:CurInciState,:CurInciStateID,:CurInciStateType,
178
- :DeplState,:DeplStateType,:InciState,:InciStateType,:LastVersionID,:Number,:VersionID)
179
- xml_attributes.each do |key,value|
180
- updated_attributes = updated_attributes.except(key)
181
- end
182
- data = updated_attributes
183
- params = { :object => 'ConfigItemObject', :method => 'VersionAdd', :data => data }
184
- a = self.class.connect(params)
185
- new_version_id = a.first
186
- data2 = { 'VersionID' => new_version_id }
187
- params2 = { :object => 'ConfigItemObject', :method => 'VersionConfigItemIDGet', :data => data2 }
188
- b = self.class.connect(params2)
189
- config_item = self.class.find(b.first)
190
- attributes = config_item.attributes
191
- attributes.each do |key,value|
192
- instance_variable_set "@#{key.to_s}", value
193
- end
194
- config_item
195
205
  end
196
206
 
197
207
 
@@ -17,11 +17,16 @@ class OTRS::Service < OTRS
17
17
  def self.find(id)
18
18
  data = { 'ServiceID' => id, 'UserID' => 1 }
19
19
  params = { :object => 'ServiceObject', :method => 'ServiceGet', :data => data }
20
- self.object_preprocessor self.connect(params)
20
+ object = self.object_preprocessor self.connect(params)
21
+ object.run_callbacks :find do
22
+ object
23
+ end
21
24
  end
22
25
 
23
26
  def save
24
- self.create(self.attributes)
27
+ run_callbacks :save do
28
+ self.create(self.attributes)
29
+ end
25
30
  end
26
31
 
27
32
  def create(attributes)
@@ -43,7 +43,9 @@ class OTRS::Ticket < OTRS
43
43
  end
44
44
 
45
45
  def save
46
- self.create(self.attributes)
46
+ run_callbacks :save do
47
+ self.create(self.attributes)
48
+ end
47
49
  end
48
50
 
49
51
  def create(attributes)
@@ -104,7 +106,10 @@ class OTRS::Ticket < OTRS
104
106
  def self.find(id)
105
107
  data = { 'TicketID' => id, 'UserID' => 1 }
106
108
  params = { :object => 'TicketObject', :method => 'TicketGet', :data => data }
107
- self.object_preprocessor(connect(params))
109
+ object = self.object_preprocessor(connect(params))
110
+ object.run_callbacks :find do
111
+ object
112
+ end
108
113
  end
109
114
 
110
115
 
@@ -10,7 +10,7 @@ class OTRS
10
10
  extend ActiveModel::Callbacks
11
11
 
12
12
  # Create callbacks on before/after create/save/update
13
- define_model_callbacks :create, :update, :save
13
+ define_model_callbacks :update, :save, :find
14
14
 
15
15
  # api_url is the base URL used to connect to the json api of OTRS, this will be the custom json.pl as the standard doesn't include ITSM module
16
16
  @@otrs_api_url ||= "https://loalhost/otrs/json.pl"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "otrs_connector"
8
- s.version = "1.1.3"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Goff"]
12
- s.date = "2012-06-14"
12
+ s.date = "2012-06-29"
13
13
  s.description = "Connect your RAILS app to OTRS/ITSM"
14
14
  s.email = "cpuguy83@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: otrs_connector
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.3
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Goff
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-06-14 00:00:00 Z
13
+ date: 2012-06-29 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -137,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- hash: 1264632322226746058
140
+ hash: -3402661767078162952
141
141
  segments:
142
142
  - 0
143
143
  version: "0"