otrs_proxy 0.0.2
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/.gitignore +11 -0
- data/Gemfile +4 -0
- data/README +36 -0
- data/Rakefile +1 -0
- data/json.pl.example +311 -0
- data/lib/otrs_connector/otrs/change/state.rb +25 -0
- data/lib/otrs_connector/otrs/change/work_order.rb +66 -0
- data/lib/otrs_connector/otrs/change.rb +74 -0
- data/lib/otrs_connector/otrs/config_item/definition.rb +25 -0
- data/lib/otrs_connector/otrs/config_item.rb +189 -0
- data/lib/otrs_connector/otrs/general_catalog.rb +15 -0
- data/lib/otrs_connector/otrs/group.rb +34 -0
- data/lib/otrs_connector/otrs/link.rb +62 -0
- data/lib/otrs_connector/otrs/service.rb +78 -0
- data/lib/otrs_connector/otrs/ticket/article.rb +43 -0
- data/lib/otrs_connector/otrs/ticket/state.rb +29 -0
- data/lib/otrs_connector/otrs/ticket/ticket_queue.rb +29 -0
- data/lib/otrs_connector/otrs/ticket/type.rb +29 -0
- data/lib/otrs_connector/otrs/ticket.rb +148 -0
- data/lib/otrs_connector/otrs/user.rb +34 -0
- data/lib/otrs_connector/otrs.rb +107 -0
- data/lib/otrs_connector/version.rb +3 -0
- data/lib/otrs_connector.rb +17 -0
- data/otrs_connector.gemspec +26 -0
- data/script/console +14 -0
- metadata +149 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module OtrsConnector
|
2
|
+
class OTRS::User < OTRS
|
3
|
+
|
4
|
+
def self.find(id)
|
5
|
+
data = { 'UserID' => id }
|
6
|
+
params = { :object => 'UserObject', :method => 'GetUserData', :data => data }
|
7
|
+
a = Hash[*connect(params)]
|
8
|
+
if a.empty? == false
|
9
|
+
self.new(a.symbolize_keys)
|
10
|
+
else
|
11
|
+
raise "ERROR::NoSuchID #{id}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.where(attributes, only_ids = false)
|
16
|
+
tmp = {}
|
17
|
+
attributes.each do |key,value|
|
18
|
+
tmp[key.to_s.camelize.to_sym] = value
|
19
|
+
end
|
20
|
+
attributes = tmp
|
21
|
+
data = attributes.merge({'Valid' => 'valid'})
|
22
|
+
params = { :object => 'UserObject', :method => 'UserSearch', :data => data }
|
23
|
+
a = connect(params)
|
24
|
+
a = Hash[*a]
|
25
|
+
return a.keys if only_ids
|
26
|
+
results = []
|
27
|
+
a.each do |key, value|
|
28
|
+
results << find(key)
|
29
|
+
end
|
30
|
+
results
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module OtrsConnector
|
2
|
+
class OTRS < ActiveRecord::Base
|
3
|
+
# include ActiveModel::Conversion
|
4
|
+
# include ActiveModel::Naming
|
5
|
+
# include ActiveModel::Validations
|
6
|
+
|
7
|
+
def self.user
|
8
|
+
$otrs_user
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.password
|
12
|
+
$otrs_pass
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.host
|
16
|
+
$otrs_host
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.api_url
|
20
|
+
$otrs_api_url
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
$configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.connect(params)
|
28
|
+
base_url = self.api_url
|
29
|
+
logon = URI.encode("User=#{self.user}&Password=#{self.password}")
|
30
|
+
object = URI.encode(params[:object])
|
31
|
+
method = URI.encode(params[:method])
|
32
|
+
data = params[:data].to_json
|
33
|
+
data = URI.encode(data)
|
34
|
+
data = URI.escape(data, '=\',\\/+-&?#.;')
|
35
|
+
uri = URI.parse("#{base_url}?#{logon}&Object=#{object}&Method=#{method}&Data=#{data}")
|
36
|
+
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
http.use_ssl = false
|
39
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
40
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
41
|
+
response = http.request(request)
|
42
|
+
|
43
|
+
result = ActiveSupport::JSON::decode(response.body)
|
44
|
+
|
45
|
+
return result["Data"] if result["Result"] == 'successful'
|
46
|
+
|
47
|
+
if result['Message'].blank?
|
48
|
+
result["Data"]
|
49
|
+
else
|
50
|
+
raise "Error:#{result["Result"]} #{result["Message"]}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def connect(params)
|
55
|
+
self.class.connect(params)
|
56
|
+
end
|
57
|
+
|
58
|
+
# start model methods
|
59
|
+
|
60
|
+
def self.set_accessor(key)
|
61
|
+
attr_accessor key.to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
def persisted?
|
65
|
+
false
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(attributes = {})
|
69
|
+
attributes.each do |name, value|
|
70
|
+
self.class.set_accessor(name.to_s.underscore)
|
71
|
+
send("#{name.to_s.underscore.to_sym}=", value)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def attributes
|
76
|
+
attributes = {}
|
77
|
+
self.instance_variables.each do |v|
|
78
|
+
attributes[v.to_s.gsub('@','').to_sym] = self.instance_variable_get(v)
|
79
|
+
end
|
80
|
+
attributes
|
81
|
+
end
|
82
|
+
|
83
|
+
class << self
|
84
|
+
def table_name
|
85
|
+
self.name.tableize
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.columns
|
90
|
+
@columns ||= [];
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.column(name, sql_type = nil, default = nil, null = true)
|
94
|
+
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
|
95
|
+
end
|
96
|
+
|
97
|
+
def save(validate = true)
|
98
|
+
self.create(self.attributes)
|
99
|
+
end
|
100
|
+
|
101
|
+
# def save
|
102
|
+
# self.create(self.attributes)
|
103
|
+
# end
|
104
|
+
|
105
|
+
# end model methods
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
module OtrsConnector
|
4
|
+
def initialize_for_app(host, path, user, pass, configuration = {})
|
5
|
+
$otrs_host = host
|
6
|
+
$otrs_api_url = "http://#{$otrs_host}#{path}"
|
7
|
+
$otrs_user = user
|
8
|
+
$otrs_pass = pass
|
9
|
+
$configuration = configuration
|
10
|
+
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'otrs_connector', '*.rb')).each {|f| require f }
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'otrs_connector', 'otrs', '*.rb')).each {|f| require f }
|
13
|
+
Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'otrs_connector', 'otrs', '**', '*.rb')).each {|f| require f }
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function :initialize_for_app
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "otrs_connector/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "otrs_proxy"
|
7
|
+
s.version = OtrsConnector::VERSION
|
8
|
+
s.authors = ["Arion"]
|
9
|
+
s.email = ["mearion@gmail.com"]
|
10
|
+
s.homepage = "http://mearion.me"
|
11
|
+
s.summary = %q{Simple gem to work with otrs}
|
12
|
+
s.description = %q{Simple gem to work with otrs}
|
13
|
+
|
14
|
+
s.rubyforge_project = "otrs_connector"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_runtime_dependency "activesupport", '~> 2.3.14'
|
25
|
+
s.add_runtime_dependency "activerecord", '~> 2.3.14'
|
26
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "pry"
|
3
|
+
|
4
|
+
%w(rubygems active_model active_support json pry).each do |lib|
|
5
|
+
require lib
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.expand_path("../../lib/otrs_connector", __FILE__)
|
9
|
+
|
10
|
+
OtrsConnector.initialize_for_app('otrs.aist.net.ru', '/otrs/json_api.pl', 'API_USER', 'fullrjynhjkm')
|
11
|
+
|
12
|
+
binding.pry
|
13
|
+
|
14
|
+
# client.call("Dispatch", "TicketObject", "TicketSearch")
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: otrs_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Arion
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
name: rake
|
33
|
+
type: :development
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
requirement: *id002
|
46
|
+
name: rspec
|
47
|
+
type: :development
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 31
|
56
|
+
segments:
|
57
|
+
- 2
|
58
|
+
- 3
|
59
|
+
- 14
|
60
|
+
version: 2.3.14
|
61
|
+
requirement: *id003
|
62
|
+
name: activesupport
|
63
|
+
type: :runtime
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 31
|
72
|
+
segments:
|
73
|
+
- 2
|
74
|
+
- 3
|
75
|
+
- 14
|
76
|
+
version: 2.3.14
|
77
|
+
requirement: *id004
|
78
|
+
name: activerecord
|
79
|
+
type: :runtime
|
80
|
+
description: Simple gem to work with otrs
|
81
|
+
email:
|
82
|
+
- mearion@gmail.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files: []
|
88
|
+
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- README
|
93
|
+
- Rakefile
|
94
|
+
- json.pl.example
|
95
|
+
- lib/otrs_connector.rb
|
96
|
+
- lib/otrs_connector/otrs.rb
|
97
|
+
- lib/otrs_connector/otrs/change.rb
|
98
|
+
- lib/otrs_connector/otrs/change/state.rb
|
99
|
+
- lib/otrs_connector/otrs/change/work_order.rb
|
100
|
+
- lib/otrs_connector/otrs/config_item.rb
|
101
|
+
- lib/otrs_connector/otrs/config_item/definition.rb
|
102
|
+
- lib/otrs_connector/otrs/general_catalog.rb
|
103
|
+
- lib/otrs_connector/otrs/group.rb
|
104
|
+
- lib/otrs_connector/otrs/link.rb
|
105
|
+
- lib/otrs_connector/otrs/service.rb
|
106
|
+
- lib/otrs_connector/otrs/ticket.rb
|
107
|
+
- lib/otrs_connector/otrs/ticket/article.rb
|
108
|
+
- lib/otrs_connector/otrs/ticket/state.rb
|
109
|
+
- lib/otrs_connector/otrs/ticket/ticket_queue.rb
|
110
|
+
- lib/otrs_connector/otrs/ticket/type.rb
|
111
|
+
- lib/otrs_connector/otrs/user.rb
|
112
|
+
- lib/otrs_connector/version.rb
|
113
|
+
- otrs_connector.gemspec
|
114
|
+
- script/console
|
115
|
+
homepage: http://mearion.me
|
116
|
+
licenses: []
|
117
|
+
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
requirements: []
|
142
|
+
|
143
|
+
rubyforge_project: otrs_connector
|
144
|
+
rubygems_version: 1.8.10
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: Simple gem to work with otrs
|
148
|
+
test_files: []
|
149
|
+
|