ip21 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ip21.gemspec +5 -4
- data/lib/ip21.rb +74 -38
- metadata +22 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f2db67d22993c9740ac8eca2abc8296ec6f36cd149b8905fc40d319b66d870c
|
4
|
+
data.tar.gz: 6151fcb02cabf463af378e1e52361ec13447e46318eeb890d697b9ce65e04b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb98cc8f0a206c3df5c07b137033db87c8aa54245d074a18e6bf3185f9a21a4691e6c581e8f452198905796c603a5175a57ade0546b2d67292fa6c95730a0e5d
|
7
|
+
data.tar.gz: 97da1c4e0f49802501936c8d5a93351a9f3430d0c040cb06f099ef863bfaf09df85dc50a97639b9d76d08b256815f93240ad98b1a9d795733ac9ea235ab0e49a
|
data/ip21.gemspec
CHANGED
@@ -4,16 +4,17 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'ip21'
|
5
5
|
s.summary = 'Aspentech IP21 Adapter for Ruby'
|
6
6
|
s.description = 'Aspentech IP21 Adapter for executing queries using SQLPlus' \
|
7
|
-
'
|
8
|
-
s.version = '1.
|
7
|
+
' REST API'
|
8
|
+
s.version = '1.2.0'
|
9
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
10
10
|
s.author = 'Rhuan Barreto'
|
11
11
|
s.email = 'rhuan@rhuan.com.br'
|
12
12
|
s.homepage = 'http://rubygems.org/gems/ip21'
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
14
|
s.license = 'MIT'
|
15
|
-
s.add_dependency 'activesupport', '~>6.0
|
16
|
-
s.add_dependency '
|
15
|
+
s.add_dependency 'activesupport', '~> 6.1.0'
|
16
|
+
s.add_dependency 'ruby-ntlm', '~>0.0.4'
|
17
|
+
s.add_dependency 'httpi', '~>2.4'
|
17
18
|
s.files = Dir.glob('{docs,bin,lib,spec,templates,benchmarks}/**/*') +
|
18
19
|
['LICENSE', 'README.md', '.yardopts', __FILE__]
|
19
20
|
s.require_path = 'lib'
|
data/lib/ip21.rb
CHANGED
@@ -45,7 +45,7 @@ class IP21
|
|
45
45
|
@debug = debug
|
46
46
|
end
|
47
47
|
|
48
|
-
# Executes a direct query
|
48
|
+
# Executes a direct query against the database
|
49
49
|
#
|
50
50
|
# @param [String] sql The query to be executed
|
51
51
|
# @param [Integer] limit The maximum number of rows that the query will output
|
@@ -73,30 +73,31 @@ class IP21
|
|
73
73
|
# - 1: Record as String
|
74
74
|
# @option opts [Integer] retrieval_type The retrieval type of the query.
|
75
75
|
# Possible values are:
|
76
|
-
# 0 - Actual
|
77
|
-
# 1 - Interpolated
|
78
|
-
# 2 - Best Fit
|
79
|
-
# 3 - Manual
|
80
|
-
# 10 - Not Good
|
81
|
-
# 11 - Good
|
82
|
-
# 12 - Average
|
83
|
-
# 13 - Maximum
|
84
|
-
# 14 - Minimum
|
85
|
-
# 15 - Range
|
86
|
-
# 16 - Sum
|
87
|
-
# 17 - Standard Deviation
|
88
|
-
# 18 - Variance
|
89
|
-
# 19 - Good Only
|
90
|
-
# 20 - Suspect Only
|
91
|
-
# 21 - First
|
92
|
-
# 22 - Last
|
93
|
-
# @option opts [Integer] outsiders Whether or not to include
|
94
|
-
#
|
95
|
-
#
|
76
|
+
# - 0 - Actual
|
77
|
+
# - 1 - Interpolated
|
78
|
+
# - 2 - Best Fit
|
79
|
+
# - 3 - Manual
|
80
|
+
# - 10 - Not Good
|
81
|
+
# - 11 - Good
|
82
|
+
# - 12 - Average
|
83
|
+
# - 13 - Maximum
|
84
|
+
# - 14 - Minimum
|
85
|
+
# - 15 - Range
|
86
|
+
# - 16 - Sum
|
87
|
+
# - 17 - Standard Deviation
|
88
|
+
# - 18 - Variance
|
89
|
+
# - 19 - Good Only
|
90
|
+
# - 20 - Suspect Only
|
91
|
+
# - 21 - First
|
92
|
+
# - 22 - Last
|
93
|
+
# @option opts [Integer] outsiders Whether or not to include the closest
|
94
|
+
# values outside the date/time range
|
95
|
+
# - 0 - False
|
96
|
+
# - 1 - True
|
96
97
|
#
|
97
98
|
# @return [Hash] Response from IP21
|
98
99
|
def history(tag, start_time, end_time, opts = {
|
99
|
-
limit: 1000, outsiders:
|
100
|
+
limit: 1000, outsiders: 0, history_format: 0, retrieval_type: 0
|
100
101
|
})
|
101
102
|
parse_rest(
|
102
103
|
rest_request(
|
@@ -112,37 +113,54 @@ class IP21
|
|
112
113
|
|
113
114
|
private
|
114
115
|
|
116
|
+
# Execute the request
|
117
|
+
#
|
118
|
+
# @param [String] type The request type to be passed to rest_address function
|
119
|
+
# @param [String] body The request body
|
115
120
|
def rest_request(type, body)
|
116
|
-
require '
|
117
|
-
|
118
|
-
|
119
|
-
http = Net::HTTP.new(uri.host)
|
120
|
-
request = Net::HTTP::Post.new(uri)
|
121
|
+
require 'httpi'
|
122
|
+
HTTPI.log = @debug
|
123
|
+
request = HTTPI::Request.new(rest_address(type))
|
121
124
|
request.body = body
|
122
|
-
request.
|
123
|
-
response =
|
124
|
-
debug_info(
|
125
|
+
request.auth.ntlm(@account, @password, @domain)
|
126
|
+
response = HTTPI.post(request)
|
127
|
+
debug_info(request.url, request.body, response) if @debug
|
125
128
|
response
|
126
129
|
end
|
127
130
|
|
131
|
+
# Generates request debug info
|
132
|
+
#
|
133
|
+
# @param [String] address The request address
|
134
|
+
# @param [String] body The request body
|
135
|
+
# @param [String] response The request response
|
128
136
|
def debug_info(address, body, response)
|
129
137
|
puts "Request: #{address}"
|
130
138
|
puts "Body: #{body}"
|
131
139
|
puts "Response: #{response.body}"
|
132
140
|
end
|
133
141
|
|
142
|
+
# Parse the API response displaying errors if needed
|
143
|
+
#
|
144
|
+
# @param [Object] response The request response
|
145
|
+
#
|
146
|
+
# @return [Hash] Response or error from the API
|
134
147
|
def parse_rest(response)
|
135
|
-
if response.code ==
|
148
|
+
if response.code == 200
|
136
149
|
require 'json'
|
137
150
|
JSON.parse(response.body)
|
138
151
|
else
|
139
152
|
{
|
140
153
|
status: response.code,
|
141
|
-
message: "Error on IP21: #{response.
|
154
|
+
message: "Error on IP21: #{response.body}"
|
142
155
|
}
|
143
156
|
end
|
144
157
|
end
|
145
158
|
|
159
|
+
# Generate the URL for accessing IP21 based on type
|
160
|
+
#
|
161
|
+
# @param [String] type The type of the request.
|
162
|
+
#
|
163
|
+
# @return [String] Address to access request
|
146
164
|
def rest_address(type)
|
147
165
|
"http://#{@sqlplus_address}/ProcessData/AtProcessDataREST.dll/#{type}"
|
148
166
|
end
|
@@ -163,12 +181,30 @@ class IP21
|
|
163
181
|
}.to_query
|
164
182
|
end
|
165
183
|
|
166
|
-
def history_query_body(
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
184
|
+
def history_query_body(tags, start_time, end_time, opts)
|
185
|
+
opts[:limit] ||= 1000
|
186
|
+
opts[:outsiders] ||= 0
|
187
|
+
opts[:history_format] ||= 0
|
188
|
+
opts[:retrieval_type] ||= 0
|
189
|
+
body = if tags.is_a?(String)
|
190
|
+
tag_request(tags, start_time, end_time, opts)
|
191
|
+
else
|
192
|
+
tags.map { |tag| tag_request(tag, start_time, end_time, opts) }.join
|
193
|
+
end
|
194
|
+
'<Q appId="20" f="D" allQuotes="1">' + body + '</Q>'
|
195
|
+
end
|
196
|
+
|
197
|
+
def tag_request(tag, start_time, end_time, opts)
|
198
|
+
'<Tag>' \
|
199
|
+
"<N><![CDATA[#{tag}]]></N>" \
|
200
|
+
"<D><![CDATA[#{@ip21_address}]]></D>" \
|
201
|
+
"<HF>#{opts[:history_format]}</HF>" \
|
202
|
+
"<St>#{start_time}</St>" \
|
203
|
+
"<Et>#{end_time}</Et>" \
|
204
|
+
"<RT>#{opts[:retrieval_type]}</RT>" \
|
205
|
+
"<X>#{opts[:limit]}</X>" \
|
206
|
+
"<O>#{opts[:outsiders]}</O>" \
|
207
|
+
'</Tag>'
|
172
208
|
end
|
173
209
|
|
174
210
|
def select?(query)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip21
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rhuan Barreto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,30 +16,43 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.0
|
19
|
+
version: 6.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.0
|
26
|
+
version: 6.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ruby-ntlm
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.0.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
|
42
|
-
|
40
|
+
version: 0.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpi
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.4'
|
55
|
+
description: Aspentech IP21 Adapter for executing queries using SQLPlus REST API
|
43
56
|
email: rhuan@rhuan.com.br
|
44
57
|
executables: []
|
45
58
|
extensions: []
|