otrs_connector 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'rails', ">= 3.0.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", "~> 1.1.1"
14
+ gem "jeweler", "~> 1.8.3"
15
+ #gem "rcov", ">= 0"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.3)
5
+ actionpack (= 3.2.3)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.1)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.3)
18
+ activesupport (= 3.2.3)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.3)
21
+ activemodel (= 3.2.3)
22
+ activesupport (= 3.2.3)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.3)
26
+ activemodel (= 3.2.3)
27
+ activesupport (= 3.2.3)
28
+ activesupport (3.2.3)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ erubis (2.7.0)
34
+ git (1.2.5)
35
+ hike (1.2.1)
36
+ i18n (0.6.0)
37
+ jeweler (1.8.3)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ rdoc
42
+ journey (1.0.3)
43
+ json (1.6.6)
44
+ mail (2.4.4)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.18)
49
+ multi_json (1.3.2)
50
+ polyglot (0.3.3)
51
+ rack (1.4.1)
52
+ rack-cache (1.2)
53
+ rack (>= 0.4)
54
+ rack-ssl (1.3.2)
55
+ rack
56
+ rack-test (0.6.1)
57
+ rack (>= 1.0)
58
+ rails (3.2.3)
59
+ actionmailer (= 3.2.3)
60
+ actionpack (= 3.2.3)
61
+ activerecord (= 3.2.3)
62
+ activeresource (= 3.2.3)
63
+ activesupport (= 3.2.3)
64
+ bundler (~> 1.0)
65
+ railties (= 3.2.3)
66
+ railties (3.2.3)
67
+ actionpack (= 3.2.3)
68
+ activesupport (= 3.2.3)
69
+ rack-ssl (~> 1.3.2)
70
+ rake (>= 0.8.7)
71
+ rdoc (~> 3.4)
72
+ thor (~> 0.14.6)
73
+ rake (0.9.2.2)
74
+ rdoc (3.12)
75
+ json (~> 1.4)
76
+ shoulda (3.0.1)
77
+ shoulda-context (~> 1.0.0)
78
+ shoulda-matchers (~> 1.0.0)
79
+ shoulda-context (1.0.0)
80
+ shoulda-matchers (1.0.0)
81
+ sprockets (2.1.2)
82
+ hike (~> 1.2)
83
+ rack (~> 1.0)
84
+ tilt (~> 1.1, != 1.3.0)
85
+ thor (0.14.6)
86
+ tilt (1.3.3)
87
+ treetop (1.4.10)
88
+ polyglot
89
+ polyglot (>= 0.3.1)
90
+ tzinfo (0.3.33)
91
+
92
+ PLATFORMS
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ bundler (~> 1.1.1)
97
+ jeweler (~> 1.8.3)
98
+ rails (>= 3.0.0)
99
+ rdoc (~> 3.12)
100
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Brian Goff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = otrs_connector
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to otrs_connector
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Brian Goff. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "otrs_connector"
18
+ gem.homepage = "http://github.com/cpuguy83/otrs_connector"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Connects OTRS API to create tikets, manipulate CI's, etc.}
21
+ gem.description = %Q{Connect your RAILS app to OTRS/ITSM}
22
+ gem.email = "cpuguy83@gmail.com"
23
+ gem.authors = ["Brian Goff"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ #require 'rcov/rcovtask'
36
+ #Rcov::RcovTask.new do |test|
37
+ # test.libs << 'test'
38
+ # test.pattern = 'test/**/test_*.rb'
39
+ # test.verbose = true
40
+ # test.rcov_opts << '--exclude "gems/*"'
41
+ #end
42
+
43
+ #task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "otrs_connector #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,46 @@
1
+ class OTRS::Change::State < OTRS::Change
2
+ @@class = 'ITSM::ChangeManagement::Change::State'
3
+
4
+ def self.set_accessor(key)
5
+ attr_accessor key.to_sym
6
+ end
7
+
8
+ def persisted?
9
+ false
10
+ end
11
+
12
+ def attributes
13
+ attributes = {}
14
+ self.instance_variables.each do |v|
15
+ attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
16
+ end
17
+ attributes
18
+ end
19
+
20
+ def initialize(attributes = {})
21
+ attributes.each do |name, value|
22
+ self.class.set_accessor(name.to_s.underscore)
23
+ send("#{name.to_s.underscore.to_sym}=", value)
24
+ end
25
+ end
26
+
27
+ def self.all
28
+ data = { 'Class' => @@class, 'UserID' => 1 }
29
+ params = { :object => 'StateMachineObject', :method => 'StateList', :data => data }
30
+ a = connect(params).flatten
31
+ b = self.superclass.superclass::Relation.new
32
+ a.each do |c|
33
+ tmp = {}
34
+ c.each do |key,value|
35
+ case key
36
+ when "Key" then tmp[:id] = value
37
+ when "Value" then tmp[:name] = value
38
+ end
39
+ end
40
+ c = tmp
41
+ b << new(c)
42
+ end
43
+ b
44
+ end
45
+
46
+ end
@@ -0,0 +1,251 @@
1
+ class OTRS::Change::WorkOrder < OTRS::Change
2
+
3
+ attr_accessor :work_order_free_key15,
4
+ :accounted_time,
5
+ :work_order_title,
6
+ :instruction_plain,
7
+ :work_order_free_text24,
8
+ :work_order_free_key24,
9
+ :work_order_free_text18,
10
+ :planned_start_time,
11
+ :work_order_free_key7,
12
+ :work_order_free_text2,
13
+ :work_order_free_text22,
14
+ :work_order_free_key33,
15
+ :planned_end_time,
16
+ :work_order_free_key18,
17
+ :work_order_free_key9,
18
+ :work_order_free_text14,
19
+ :work_order_agent_id,
20
+ :work_order_free_text21,
21
+ :work_order_free_text11,
22
+ :work_order_free_text38,
23
+ :create_time,
24
+ :work_order_free_key32,
25
+ :work_order_free_text19,
26
+ :work_order_free_text29,
27
+ :report_plain,
28
+ :work_order_free_key25,
29
+ :work_order_free_text1,
30
+ :work_order_free_key39,
31
+ :work_order_free_text28,
32
+ :work_order_state_id,
33
+ :work_order_free_text27,
34
+ :work_order_free_text37,
35
+ :work_order_free_key14,
36
+ :work_order_free_key31,
37
+ :work_order_free_key36,
38
+ :work_order_free_key43,
39
+ :work_order_free_text40,
40
+ :work_order_free_key19,
41
+ :work_order_free_key1,
42
+ :planned_effort,
43
+ :actual_end_time,
44
+ :work_order_free_text49,
45
+ :work_order_free_key50,
46
+ :work_order_free_key2,
47
+ :instruction,
48
+ :work_order_free_text30,
49
+ :create_by,
50
+ :work_order_state,
51
+ :work_order_free_key21,
52
+ :work_order_free_text8,
53
+ :work_order_free_text47,
54
+ :change_time,
55
+ :work_order_free_key5,
56
+ :work_order_free_text4,
57
+ :work_order_free_key16,
58
+ :work_order_free_text39,
59
+ :work_order_free_text3,
60
+ :work_order_free_key28,
61
+ :work_order_free_text15,
62
+ :work_order_free_key29,
63
+ :work_order_free_text13,
64
+ :work_order_free_key6,
65
+ :work_order_free_text7,
66
+ :work_order_free_text25,
67
+ :work_order_free_text12,
68
+ :work_order_free_text26,
69
+ :work_order_free_key22,
70
+ :work_order_free_text46,
71
+ :work_order_free_key37,
72
+ :actual_start_time,
73
+ :work_order_free_key44,
74
+ :work_order_free_text41,
75
+ :work_order_type_id,
76
+ :work_order_free_key40,
77
+ :work_order_free_key10,
78
+ :work_order_free_text44,
79
+ :change_id,
80
+ :work_order_free_text5,
81
+ :work_order_free_key23,
82
+ :work_order_free_key12,
83
+ :work_order_free_text16,
84
+ :work_order_free_text43,
85
+ :change_by,
86
+ :work_order_state_signal,
87
+ :work_order_free_key27,
88
+ :work_order_free_key17,
89
+ :work_order_free_text42,
90
+ :work_order_free_text34,
91
+ :work_order_free_key47,
92
+ :work_order_free_key35,
93
+ :work_order_free_key4,
94
+ :work_order_id,
95
+ :work_order_free_text6,
96
+ :work_order_free_text48,
97
+ :work_order_free_key41,
98
+ :work_order_free_key30,
99
+ :work_order_free_key26,
100
+ :report,
101
+ :work_order_free_key42,
102
+ :work_order_free_key49,
103
+ :work_order_free_text10,
104
+ :work_order_free_text9,
105
+ :work_order_free_key45,
106
+ :work_order_number,
107
+ :work_order_free_text33,
108
+ :work_order_free_text17,
109
+ :work_order_free_text45,
110
+ :work_order_free_text35,
111
+ :work_order_free_text50,
112
+ :work_order_free_key46,
113
+ :work_order_free_key34,
114
+ :work_order_free_text32,
115
+ :work_order_free_key20,
116
+ :work_order_free_key48,
117
+ :work_order_free_text20,
118
+ :work_order_free_text31,
119
+ :work_order_free_text36,
120
+ :work_order_free_key3,
121
+ :work_order_free_key11,
122
+ :work_order_type,
123
+ :work_order_free_text23,
124
+ :work_order_free_key8,
125
+ :work_order_free_key38,
126
+ :work_order_free_key13
127
+
128
+
129
+
130
+ #def self.set_accessor(key)
131
+ # attr_accessor key.to_sym
132
+ #end
133
+
134
+ def persisted?
135
+ false
136
+ end
137
+
138
+ def initialize(attributes = {})
139
+ attributes.each do |name, value|
140
+ #self.class.set_accessor(name.to_s.underscore)
141
+ send("#{name.to_s.underscore.to_sym}=", value)
142
+ end
143
+ end
144
+
145
+ def attributes
146
+ attributes = {}
147
+ self.instance_variables.each do |v|
148
+ attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
149
+ end
150
+ attributes
151
+ end
152
+
153
+ def save
154
+ self.create(self.attributes)
155
+ end
156
+
157
+ def create(attributes)
158
+ tmp = {}
159
+ attributes.each do |key,value|
160
+ tmp[key.to_s.camelize.to_sym] = value
161
+ end
162
+ attributes = tmp
163
+ attributes[:UserID] = '1'
164
+ attributes[:ChangeID] = attributes[:ChangeId]
165
+ attributes.delete(:ChangeId)
166
+ data = attributes
167
+ params = { :object => 'WorkOrderObject', :method => 'WorkOrderAdd', :data => data }
168
+ a = connect(params)
169
+ id = a.first
170
+ if id.nil?
171
+ nil
172
+ else
173
+ b = self.class.find(id)
174
+ attributes = b.attributes
175
+ attributes.each do |key,value|
176
+ instance_variable_set "@#{key.to_s}", value
177
+ end
178
+ b
179
+ end
180
+ end
181
+
182
+ def update_attributes(attributes)
183
+ tmp = {}
184
+ attributes.each do |key,value|
185
+ tmp[key.to_s.camelize] = value #Copies ruby style keys to camel case for OTRS
186
+ end
187
+ tmp['WorkOrderID'] = @work_order_id
188
+ data = tmp
189
+ params = { :object => 'WorkOrderObject', :method => 'WorkOrderUpdate', :data => data }
190
+ a = connect(params)
191
+ if a.first.nil?
192
+ nil
193
+ else
194
+ return self
195
+ end
196
+ end
197
+
198
+ def self.find(id)
199
+ data = { 'WorkOrderID' => id, 'UserID' => 1 }
200
+ params = { :object => 'WorkOrderObject', :method => 'WorkOrderGet', :data => data }
201
+ self.object_preprocessor connect(params)
202
+ end
203
+
204
+ def destroy
205
+ id = @change_id
206
+ if self.class.find(id)
207
+ data = { 'ChangeID' => id, 'UserID' => 1 }
208
+ params = { :object => 'WorkOrderObject', :method => 'WorkOrderDelete', :data => data }
209
+ connect(params)
210
+ "WorkOrderID #{id} deleted"
211
+ else
212
+ raise "NoSuchWorkOrderID #{id}"
213
+ end
214
+ end
215
+
216
+ def self.where(attributes)
217
+ tmp = {}
218
+ attributes.each do |key,value|
219
+ tmp[key.to_s.camelize] = value #Copies ruby style keys to camel case for OTRS
220
+ end
221
+ data = tmp
222
+ params = { :object => 'WorkOrderObjectCustom', :method => 'WorkOrderSearch', :data => data }
223
+ a = connect(params).flatten
224
+ results = self.superclass::Relation.new
225
+ a.each do |c|
226
+ results << self.new(c)
227
+ end
228
+ results
229
+ end
230
+
231
+ def change
232
+ self.class.superclass::Change.find(self.change_id)
233
+ end
234
+
235
+ def name
236
+ self.work_order_title
237
+ end
238
+
239
+ def title
240
+ self.work_order_title
241
+ end
242
+
243
+ def id
244
+ self.work_order_id
245
+ end
246
+
247
+ def status
248
+ self.work_order_status
249
+ end
250
+
251
+ end