otrs_connector 0.5.4 → 0.5.6
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/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/VERSION +1 -1
- data/lib/otrs.rb +70 -68
- data/lib/otrs/service.rb +2 -3
- data/otrs_connector.gemspec +4 -1
- metadata +18 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -73,6 +73,7 @@ GEM
|
|
73
73
|
rake (0.9.2.2)
|
74
74
|
rdoc (3.12)
|
75
75
|
json (~> 1.4)
|
76
|
+
require_all (1.2.1)
|
76
77
|
shoulda (3.0.1)
|
77
78
|
shoulda-context (~> 1.0.0)
|
78
79
|
shoulda-matchers (~> 1.0.0)
|
@@ -97,4 +98,5 @@ DEPENDENCIES
|
|
97
98
|
jeweler (~> 1.8.3)
|
98
99
|
rails (>= 3.0.0)
|
99
100
|
rdoc (~> 3.12)
|
101
|
+
require_all
|
100
102
|
shoulda
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.6
|
data/lib/otrs.rb
CHANGED
@@ -1,84 +1,86 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module OTRS
|
2
|
+
class OTRS
|
3
|
+
include ActiveModel::Conversion
|
4
|
+
include ActiveModel::Naming
|
5
|
+
include ActiveModel::Validations
|
6
|
+
extend ActiveModel::Callbacks
|
7
|
+
require_rel 'otrs'
|
7
8
|
|
8
|
-
|
9
|
+
define_model_callbacks :create, :update, :save
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
# @@otrs_host is the address where the OTRS server presides
|
12
|
+
# 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
|
13
|
+
@@otrs_api_url ||= "https://loalhost/otrs/json.pl"
|
14
|
+
# Username / password combo should be an actual OTRS agent defined on the OTRS server
|
15
|
+
# I have not tested this with other forms of OTRS authentication
|
16
|
+
@@otrs_user ||= 'rails'
|
17
|
+
@@otrs_pass ||= 'rails'
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def self.user
|
20
|
+
@@otrs_user
|
21
|
+
end
|
22
|
+
def self.user=(username)
|
23
|
+
@@otrs_user = username
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def self.password
|
27
|
+
@@otrs_pass
|
28
|
+
end
|
29
|
+
def self.password=(password)
|
30
|
+
@@otrs_pass = password
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
def self.api_url
|
34
|
+
@@otrs_api_url
|
35
|
+
end
|
36
|
+
def self.api_url=(url)
|
37
|
+
@@otrs_api_url = url
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def attributes
|
41
|
+
attributes = {}
|
42
|
+
self.instance_variables.each do |v|
|
43
|
+
attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
|
44
|
+
end
|
45
|
+
attributes
|
43
46
|
end
|
44
|
-
attributes
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
def self.connect(params)
|
49
|
+
require 'net/https'
|
50
|
+
base_url = self.api_url
|
51
|
+
logon = URI.encode("User=#{self.user}&Password=#{self.password}")
|
52
|
+
object = URI.encode(params[:object])
|
53
|
+
method = URI.encode(params[:method])
|
54
|
+
data = params[:data].to_json
|
55
|
+
data = URI.encode(data)
|
56
|
+
data = URI.escape(data, '=\',\\/+-&?#.;')
|
57
|
+
uri = URI.parse("#{base_url}?#{logon}&Object=#{object}&Method=#{method}&Data=#{data}")
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
60
|
+
http.use_ssl = true
|
61
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
62
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
63
|
+
response = http.request(request)
|
64
|
+
result = ActiveSupport::JSON::decode(response.body)
|
65
|
+
if result["Result"] == 'successful'
|
66
|
+
result["Data"]
|
67
|
+
else
|
68
|
+
raise "Error:#{result["Result"]} #{result["Data"]}"
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def self.object_preprocessor(object)
|
73
|
+
unless object.empty? or object.nil?
|
74
|
+
a = Hash[*object]
|
75
|
+
self.new(a.symbolize_keys)
|
76
|
+
else
|
77
|
+
raise 'NoSuchObject'
|
78
|
+
end
|
77
79
|
end
|
78
|
-
end
|
79
80
|
|
80
81
|
|
81
|
-
|
82
|
-
|
82
|
+
def connect(params)
|
83
|
+
self.class.connect(params)
|
84
|
+
end
|
83
85
|
end
|
84
86
|
end
|
data/lib/otrs/service.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
class OTRS::Service
|
2
|
-
extend OTRS
|
1
|
+
class OTRS::Service < OTRS
|
3
2
|
attr_accessor :config_items, :tickets, :cur_inci_state, :valid_id, :service_id, :cur_inci_state_type, :type,
|
4
3
|
:cur_inci_state, :create_by, :cur_inci_state_type_from_c_is, :change_time, :change_by, :create_time,
|
5
4
|
:criticality, :comment, :criticality, :name_short, :type_id, :name, :parent_id, :cur_inci_state_id,
|
@@ -23,7 +22,7 @@ class OTRS::Service# < OTRS
|
|
23
22
|
def self.find(id)
|
24
23
|
data = { 'ServiceID' => id, 'UserID' => 1 }
|
25
24
|
params = { :object => 'ServiceObject', :method => 'ServiceGet', :data => data }
|
26
|
-
self.object_preprocessor connect(params)
|
25
|
+
self.object_preprocessor self.connect(params)
|
27
26
|
end
|
28
27
|
|
29
28
|
def attributes
|
data/otrs_connector.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "otrs_connector"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.6"
|
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"]
|
@@ -56,12 +56,14 @@ Gem::Specification.new do |s|
|
|
56
56
|
|
57
57
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
58
|
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
59
|
+
s.add_runtime_dependency(%q<require_all>, [">= 0"])
|
59
60
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
60
61
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
61
62
|
s.add_development_dependency(%q<bundler>, ["~> 1.1.1"])
|
62
63
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
63
64
|
else
|
64
65
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
66
|
+
s.add_dependency(%q<require_all>, [">= 0"])
|
65
67
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
66
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
69
|
s.add_dependency(%q<bundler>, ["~> 1.1.1"])
|
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
|
|
69
71
|
end
|
70
72
|
else
|
71
73
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
74
|
+
s.add_dependency(%q<require_all>, [">= 0"])
|
72
75
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
73
76
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
74
77
|
s.add_dependency(%q<bundler>, ["~> 1.1.1"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otrs_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: require_all
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: shoulda
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
157
|
version: '0'
|
142
158
|
segments:
|
143
159
|
- 0
|
144
|
-
hash: -
|
160
|
+
hash: -2176562409639717085
|
145
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
162
|
none: false
|
147
163
|
requirements:
|