ip21 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/ip21.gemspec +4 -1
- data/lib/ip21.rb +44 -14
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b56f02bb8919d8869c39d3b98248fbd2befad1160c76195fe1280da011af15b9
|
4
|
+
data.tar.gz: cac1e5bf0dabe81118c1245a93f70d503cec9eb1a631e497ee6d6a01c853b108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d616968d8a324319d6a426e3ee8e318a8b9cb9784166d20a46babf530fe676e6e3b399d144a07bdca36bf0f63ae98ab5ba72df861311ff501c67e264d510807
|
7
|
+
data.tar.gz: b5a2a166c73a875aa8deec5b3375d93cafd38bd28b73b6b9a6ac8efd5d7095e93346ab44d50847e3dce981fb6ce7fed9268ac979ee112f2bb313e68b8ce48c8b
|
data/README.md
CHANGED
data/ip21.gemspec
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = 'ip21'
|
3
5
|
s.summary = 'Aspentech IP21 Adapter for Ruby'
|
4
6
|
s.description = 'Aspentech IP21 Adapter for executing queries using SQLPlus' \
|
5
7
|
'WebService or REST API'
|
6
|
-
s.version = '0.0.
|
8
|
+
s.version = '0.0.7'
|
7
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
8
10
|
s.author = 'Rhuan Barreto'
|
9
11
|
s.email = 'rhuan@rhuan.com.br'
|
10
12
|
s.homepage = 'http://rubygems.org/gems/ip21'
|
11
13
|
s.platform = Gem::Platform::RUBY
|
12
14
|
s.license = 'MIT'
|
15
|
+
s.add_dependency 'activesupport', '~>6.0.1'
|
13
16
|
s.add_dependency 'ruby-ntlm', '~>0.0'
|
14
17
|
s.add_dependency 'rubyntlm', '~>0.6'
|
15
18
|
s.add_dependency 'savon', '~>2.12'
|
data/lib/ip21.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Aspentech IP21 Adapter for executing queries using SQLPlus
|
2
4
|
#
|
3
5
|
# This library uses Windows Authentication for connecting to SQLPlus
|
@@ -25,6 +27,8 @@ class IP21
|
|
25
27
|
# the IP21 Database
|
26
28
|
# @param [Boolean] soap Set this parameter to true for connecting to SQLPlus
|
27
29
|
# using the SOAP Web Service
|
30
|
+
# @param [Boolean] debug Set this parameter to true for enabling debug
|
31
|
+
# information
|
28
32
|
def initialize(
|
29
33
|
auth: {
|
30
34
|
account: 'john.doe',
|
@@ -33,7 +37,8 @@ class IP21
|
|
33
37
|
},
|
34
38
|
sqlplus_address: '127.0.0.1',
|
35
39
|
ip21_address: '127.0.0.1',
|
36
|
-
soap: false
|
40
|
+
soap: false,
|
41
|
+
debug: false
|
37
42
|
)
|
38
43
|
@account = auth[:account]
|
39
44
|
@domain = auth[:domain]
|
@@ -41,6 +46,7 @@ class IP21
|
|
41
46
|
@sqlplus_address = sqlplus_address
|
42
47
|
@ip21_address = ip21_address
|
43
48
|
@soap = soap
|
49
|
+
@debug = debug
|
44
50
|
end
|
45
51
|
|
46
52
|
# Executes a direct query againt the database
|
@@ -49,8 +55,8 @@ class IP21
|
|
49
55
|
# @param [Integer] limit The maximum number of rows that the query will output
|
50
56
|
#
|
51
57
|
# @return [Hash] Response from the query
|
52
|
-
def query(sql, limit = 100)
|
53
|
-
@soap ? soap(sql) : rest(sql, limit)
|
58
|
+
def query(sql, limit = 100, type = 'SQL')
|
59
|
+
@soap ? soap(sql) : rest(sql, limit, type)
|
54
60
|
end
|
55
61
|
|
56
62
|
private
|
@@ -66,16 +72,30 @@ class IP21
|
|
66
72
|
client.call(:execute_sql, message: { command: sql }).body
|
67
73
|
end
|
68
74
|
|
69
|
-
def rest(sql, limit)
|
75
|
+
def rest(sql, limit, type)
|
76
|
+
response = rest_request(
|
77
|
+
rest_address(type), query_body(sql, limit, type)
|
78
|
+
)
|
79
|
+
parse_rest(response)
|
80
|
+
end
|
81
|
+
|
82
|
+
def rest_request(url, body)
|
70
83
|
require 'net/http'
|
71
84
|
require 'ntlm/http'
|
72
|
-
uri = URI(
|
85
|
+
uri = URI(url)
|
73
86
|
http = Net::HTTP.new(uri.host)
|
74
87
|
request = Net::HTTP::Post.new(uri)
|
75
|
-
request.body =
|
88
|
+
request.body = body
|
76
89
|
request.ntlm_auth(@account, @domain, @password)
|
77
90
|
response = http.request(request)
|
78
|
-
|
91
|
+
debug_info(url, request.body, response) if @debug
|
92
|
+
response
|
93
|
+
end
|
94
|
+
|
95
|
+
def debug_info(address, body, response)
|
96
|
+
puts "Request: #{address}"
|
97
|
+
puts "Body: #{body}"
|
98
|
+
puts "Response: #{response.body}"
|
79
99
|
end
|
80
100
|
|
81
101
|
def parse_rest(response)
|
@@ -94,14 +114,24 @@ class IP21
|
|
94
114
|
"http://#{@sqlplus_address}/SQLplusWebService/SQLplusWebService.asmx?WSDL"
|
95
115
|
end
|
96
116
|
|
97
|
-
def rest_address
|
98
|
-
"http://#{@sqlplus_address}/ProcessData/AtProcessDataREST.dll
|
117
|
+
def rest_address(type)
|
118
|
+
"http://#{@sqlplus_address}/ProcessData/AtProcessDataREST.dll/#{type}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def query_body(sql, limit, type)
|
122
|
+
case type
|
123
|
+
when 'SQL'
|
124
|
+
"<SQL c=\"DRIVER={AspenTech SQLplus};HOST=#{@ip21_address};Port=10014;" \
|
125
|
+
"CHARINT=N;CHARFLOAT=N;CHARTIME=N;CONVERTERRORS=N;\" m=\"#{limit}\" " \
|
126
|
+
"to=\"30\" s=\"#{select?(sql) ? 1 : 0}\"><![CDATA[#{sql}]]></SQL>"
|
127
|
+
when 'KPI'
|
128
|
+
require 'active_support'
|
129
|
+
require 'active_support/core_ext/object/to_query'
|
130
|
+
sql.to_query
|
131
|
+
end
|
99
132
|
end
|
100
133
|
|
101
|
-
def
|
102
|
-
|
103
|
-
'PORT=10014;CHARISNULL=Y;CHARINT=N;CHARFLOAT=N;CHARTIME=N;' \
|
104
|
-
"CONVERTERRORS=N;ROWID=Y;TIMEOUT=10\" m=\"#{limit}\">" \
|
105
|
-
"<![CDATA[#{sql}]]></SQL>"
|
134
|
+
def select?(query)
|
135
|
+
/^select/i.match?(query)
|
106
136
|
end
|
107
137
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip21
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhuan Barreto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: ruby-ntlm
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|