otrs_connector 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/otrs_connector/otrs.rb +26 -6
- data/otrs_connector.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/otrs_connector/otrs.rb
CHANGED
@@ -50,14 +50,15 @@ class OTRS
|
|
50
50
|
end
|
51
51
|
|
52
52
|
# Handles communication with OTRS
|
53
|
-
|
53
|
+
|
54
|
+
def self.setup_connection_params(params)
|
54
55
|
if self.api_url =~ /^https/
|
55
56
|
require 'net/https'
|
56
57
|
else
|
57
58
|
require 'net/http'
|
58
59
|
end
|
59
|
-
base_url = self.api_url
|
60
60
|
|
61
|
+
base_url = self.api_url
|
61
62
|
# Build request URL
|
62
63
|
logon = URI.encode("User=#{self.user}&Password=#{self.password}")
|
63
64
|
object = URI.encode(params[:object])
|
@@ -66,23 +67,42 @@ class OTRS
|
|
66
67
|
data = URI.encode(data)
|
67
68
|
# Had some issues with certain characters not being escaped properly and causing JSON issues
|
68
69
|
data = URI.escape(data, '=\',\\/+-&?#.;')
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
URI.parse("#{base_url}?#{logon}&Object=#{object}&Method=#{method}&Data=#{data}")
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.get_from_remote(uri, read_timeout=60)
|
72
74
|
http = Net::HTTP.new(uri.host, uri.port)
|
75
|
+
http.read_timeout = read_timeout
|
73
76
|
if self.api_url =~ /^https/
|
74
77
|
http.use_ssl = true
|
75
78
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
76
79
|
end
|
77
80
|
request = Net::HTTP::Get.new(uri.request_uri)
|
78
81
|
response = http.request(request)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.process_response(response)
|
79
85
|
result = ActiveSupport::JSON::decode(response.body)
|
80
86
|
if result["Result"] == 'successful'
|
81
|
-
result["Data"]
|
87
|
+
return result["Data"]
|
82
88
|
else
|
83
89
|
raise "Error:#{result["Result"]} #{result["Data"]}"
|
84
90
|
end
|
85
91
|
end
|
92
|
+
|
93
|
+
|
94
|
+
def self.connect(params)
|
95
|
+
uri = self.setup_connection_params(params)
|
96
|
+
|
97
|
+
# Connect to OTRS
|
98
|
+
begin
|
99
|
+
response = self.get_from_remote(uri)
|
100
|
+
rescue Timeout::Error
|
101
|
+
response = self.get_from_remote(uri,120)
|
102
|
+
return self.process_response(response)
|
103
|
+
end
|
104
|
+
return self.process_response(response)
|
105
|
+
end
|
86
106
|
|
87
107
|
# Base method for processing objects returned by OTRS into Ruby objects
|
88
108
|
# This works in most cases, but not all, namely with OTRS::ConfigItem due to extra attributes
|
data/otrs_connector.gemspec
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: otrs_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Goff
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
hash:
|
129
|
+
hash: -2300522192988681376
|
130
130
|
segments:
|
131
131
|
- 0
|
132
132
|
version: "0"
|