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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/otrs.rb +74 -76
  3. data/otrs_connector.gemspec +1 -1
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.10
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
- module OTRS
9
- class OTRS
10
- include ActiveModel::Conversion
11
- include ActiveModel::Naming
12
- include ActiveModel::Validations
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
- # @@otrs_host is the address where the OTRS server presides
18
- # 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
19
- @@otrs_api_url ||= "https://loalhost/otrs/json.pl"
20
- # Username / password combo should be an actual OTRS agent defined on the OTRS server
21
- # I have not tested this with other forms of OTRS authentication
22
- @@otrs_user ||= 'rails'
23
- @@otrs_pass ||= 'rails'
24
-
25
- def self.user
26
- @@otrs_user
27
- end
28
- def self.user=(username)
29
- @@otrs_user = username
30
- end
31
-
32
- def self.password
33
- @@otrs_pass
34
- end
35
- def self.password=(password)
36
- @@otrs_pass = password
37
- end
38
-
39
- def self.api_url
40
- @@otrs_api_url
41
- end
42
- def self.api_url=(url)
43
- @@otrs_api_url = url
44
- end
45
-
46
- def attributes
47
- attributes = {}
48
- self.instance_variables.each do |v|
49
- attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
50
- end
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
- def self.connect(params)
55
- require 'net/https'
56
- base_url = self.api_url
57
- logon = URI.encode("User=#{self.user}&Password=#{self.password}")
58
- object = URI.encode(params[:object])
59
- method = URI.encode(params[:method])
60
- data = params[:data].to_json
61
- data = URI.encode(data)
62
- data = URI.escape(data, '=\',\\/+-&?#.;')
63
- uri = URI.parse("#{base_url}?#{logon}&Object=#{object}&Method=#{method}&Data=#{data}")
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
- def self.object_preprocessor(object)
79
- unless object.empty? or object.nil?
80
- a = Hash[*object]
81
- self.new(a.symbolize_keys)
82
- else
83
- raise 'NoSuchObject'
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
- def connect(params)
89
- self.class.connect(params)
90
- end
86
+
87
+ def connect(params)
88
+ self.class.connect(params)
91
89
  end
92
90
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "otrs_connector"
8
- s.version = "0.5.10"
8
+ s.version = "0.5.11"
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"]
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.10
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: 1497926877747312368
160
+ hash: 2712132028202847241
161
161
  required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  none: false
163
163
  requirements: