otrs_connector 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/otrs.rb +74 -76
- data/otrs_connector.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.11
|
data/lib/otrs.rb
CHANGED
@@ -5,88 +5,86 @@ require 'otrs/otrs_general_catalog'
|
|
5
5
|
require 'otrs/link'
|
6
6
|
require 'otrs/relation'
|
7
7
|
require 'otrs/ticket'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
extend ActiveModel::Callbacks
|
14
|
-
|
15
|
-
define_model_callbacks :create, :update, :save
|
8
|
+
class OTRS
|
9
|
+
include ActiveModel::Conversion
|
10
|
+
include ActiveModel::Naming
|
11
|
+
include ActiveModel::Validations
|
12
|
+
extend ActiveModel::Callbacks
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
attributes
|
14
|
+
define_model_callbacks :create, :update, :save
|
15
|
+
|
16
|
+
# @@otrs_host is the address where the OTRS server presides
|
17
|
+
# 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
|
18
|
+
@@otrs_api_url ||= "https://loalhost/otrs/json.pl"
|
19
|
+
# Username / password combo should be an actual OTRS agent defined on the OTRS server
|
20
|
+
# I have not tested this with other forms of OTRS authentication
|
21
|
+
@@otrs_user ||= 'rails'
|
22
|
+
@@otrs_pass ||= 'rails'
|
23
|
+
|
24
|
+
def self.user
|
25
|
+
@@otrs_user
|
26
|
+
end
|
27
|
+
def self.user=(username)
|
28
|
+
@@otrs_user = username
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.password
|
32
|
+
@@otrs_pass
|
33
|
+
end
|
34
|
+
def self.password=(password)
|
35
|
+
@@otrs_pass = password
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.api_url
|
39
|
+
@@otrs_api_url
|
40
|
+
end
|
41
|
+
def self.api_url=(url)
|
42
|
+
@@otrs_api_url = url
|
43
|
+
end
|
44
|
+
|
45
|
+
def attributes
|
46
|
+
attributes = {}
|
47
|
+
self.instance_variables.each do |v|
|
48
|
+
attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
|
52
49
|
end
|
50
|
+
attributes
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.connect(params)
|
54
|
+
require 'net/https'
|
55
|
+
base_url = self.api_url
|
56
|
+
logon = URI.encode("User=#{self.user}&Password=#{self.password}")
|
57
|
+
object = URI.encode(params[:object])
|
58
|
+
method = URI.encode(params[:method])
|
59
|
+
data = params[:data].to_json
|
60
|
+
data = URI.encode(data)
|
61
|
+
data = URI.escape(data, '=\',\\/+-&?#.;')
|
62
|
+
uri = URI.parse("#{base_url}?#{logon}&Object=#{object}&Method=#{method}&Data=#{data}")
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
66
|
-
http.use_ssl = true
|
67
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
68
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
69
|
-
response = http.request(request)
|
70
|
-
result = ActiveSupport::JSON::decode(response.body)
|
71
|
-
if result["Result"] == 'successful'
|
72
|
-
result["Data"]
|
73
|
-
else
|
74
|
-
raise "Error:#{result["Result"]} #{result["Data"]}"
|
75
|
-
end
|
64
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
65
|
+
http.use_ssl = true
|
66
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
67
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
68
|
+
response = http.request(request)
|
69
|
+
result = ActiveSupport::JSON::decode(response.body)
|
70
|
+
if result["Result"] == 'successful'
|
71
|
+
result["Data"]
|
72
|
+
else
|
73
|
+
raise "Error:#{result["Result"]} #{result["Data"]}"
|
76
74
|
end
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
77
|
+
def self.object_preprocessor(object)
|
78
|
+
unless object.empty? or object.nil?
|
79
|
+
a = Hash[*object]
|
80
|
+
self.new(a.symbolize_keys)
|
81
|
+
else
|
82
|
+
raise 'NoSuchObject'
|
85
83
|
end
|
84
|
+
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
86
|
+
|
87
|
+
def connect(params)
|
88
|
+
self.class.connect(params)
|
91
89
|
end
|
92
90
|
end
|
data/otrs_connector.gemspec
CHANGED
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.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash:
|
160
|
+
hash: 2712132028202847241
|
161
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
162
|
none: false
|
163
163
|
requirements:
|