data_collector 0.12.0 → 0.13.0
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.
- checksums.yaml +4 -4
- data/README.md +17 -13
- data/data_collector.gemspec +1 -0
- data/lib/data_collector/input.rb +21 -4
- data/lib/data_collector/output.rb +26 -1
- data/lib/data_collector/rules_ng.rb +5 -0
- data/lib/data_collector/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ada83aba097793e130f92865b86f6fbf9b8e43e23b73e788f8683397d3cf7d3
|
4
|
+
data.tar.gz: 03706e1fc9f239ef7f265b826916b08f98af250bb537214acfef9aa71d5bb1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ccbf0850f4e259996eba02f86bd20ac4355020ef2df429b185adea71c9619c6c6a784d967b2e78e131c65f54d7a9369b88f5379fbf2d0f36e112d969b948841
|
7
|
+
data.tar.gz: d6379863103a592300727dea957ce63b5bd51bdf46d3f0f5b1cdd28402172aa8258188ec770892203b20e2688da801458eee20bc026f1c60be094d653259b815
|
data/README.md
CHANGED
@@ -99,18 +99,18 @@ filter data from a hash using [JSONPath](http://goessner.net/articles/JsonPath/i
|
|
99
99
|
|
100
100
|
#### rules (depricated)
|
101
101
|
See newer rules_ng object
|
102
|
-
Allows you to define a simple lambda structure to run against a JSONPath filter
|
103
|
-
|
104
|
-
A rule is made up of a Hash the key is the map key field its value is a Hash with a JSONPath filter and options to apply a convert method on the filtered results
|
105
|
-
Available convert methods are: time, map, each, call, suffix, text
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
102
|
+
~~Allows you to define a simple lambda structure to run against a JSONPath filter~~
|
103
|
+
|
104
|
+
~~A rule is made up of a Hash the key is the map key field its value is a Hash with a JSONPath filter and options to apply a convert method on the filtered results.~~
|
105
|
+
~~Available convert methods are: time, map, each, call, suffix, text~~
|
106
|
+
~~- time: parses a given time/date string into a Time object~~
|
107
|
+
~~- map: applies a mapping to a filter~~
|
108
|
+
~~- suffix: adds a suffix to a result~~
|
109
|
+
~~- call: executes a lambda on the filter~~
|
110
|
+
~~- each: runs a lambda on each row of a filter~~
|
111
|
+
~~- text: passthrough method. Returns value unchanged~~
|
112
|
+
|
113
|
+
~~example:~~
|
114
114
|
```ruby
|
115
115
|
my_rules = {
|
116
116
|
'identifier' => {"filter" => '$..id'},
|
@@ -204,7 +204,11 @@ Here you find different rule combination that are possible
|
|
204
204
|
|
205
205
|
Here is an example on how to call last RULESET "rs_hash_with_json_filter_and_option".
|
206
206
|
|
207
|
-
***rules_ng.run*** can have 4 parameters. First 3 are mandatory. The last one ***options*** can hold data static to a rule set.
|
207
|
+
***rules_ng.run*** can have 4 parameters. First 3 are mandatory. The last one ***options*** can hold data static to a rule set or engine directives.
|
208
|
+
|
209
|
+
List of engine directives:
|
210
|
+
- _no_array_with_one_element: defaults to false. if the result is an array with 1 element just return the element.
|
211
|
+
|
208
212
|
|
209
213
|
```ruby
|
210
214
|
include DataCollector::Core
|
data/data_collector.gemspec
CHANGED
data/lib/data_collector/input.rb
CHANGED
@@ -61,17 +61,33 @@ module DataCollector
|
|
61
61
|
|
62
62
|
def from_https(uri, options = {})
|
63
63
|
data = nil
|
64
|
+
HTTP.default_options = HTTP::Options.new(features: { logging: { logger: @logger } })
|
64
65
|
http = HTTP
|
65
66
|
|
66
|
-
|
67
|
+
#http.use(logging: {logger: @logger})
|
68
|
+
|
69
|
+
if options.key?(:user) && options.key?(:password)
|
70
|
+
@logger.debug "Set Basic_auth"
|
67
71
|
user = options[:user]
|
68
72
|
password = options[:password]
|
69
73
|
http = HTTP.basic_auth(user: user, pass: password)
|
70
|
-
|
71
|
-
@logger.
|
74
|
+
elsif options.key?(:bearer_token)
|
75
|
+
@logger.debug "Set authorization bearer token"
|
76
|
+
bearer = options[:bearer_token]
|
77
|
+
bearer = "Bearer #{bearer}" unless bearer =~ /^Bearer /i
|
78
|
+
http = HTTP.auth(bearer)
|
72
79
|
end
|
73
80
|
|
74
|
-
|
81
|
+
if options.key?(:verify_ssl) && uri.scheme.eql?('https')
|
82
|
+
@logger.warn "Disabling SSL verification. "
|
83
|
+
#shouldn't use this but we all do ...
|
84
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
85
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
86
|
+
|
87
|
+
http_response = http.get(escape_uri(uri), ssl_context: ctx)
|
88
|
+
else
|
89
|
+
http_response = http.get(escape_uri(uri))
|
90
|
+
end
|
75
91
|
|
76
92
|
case http_response.code
|
77
93
|
when 200
|
@@ -167,6 +183,7 @@ module DataCollector
|
|
167
183
|
file_type = if headers.include?('Content-Type')
|
168
184
|
headers['Content-Type'].split(';').first
|
169
185
|
else
|
186
|
+
@logger.debug "No Header content-type available"
|
170
187
|
MIME::Types.of(filename_from(headers)).first.content_type
|
171
188
|
end
|
172
189
|
|
@@ -82,6 +82,11 @@ module DataCollector
|
|
82
82
|
@data
|
83
83
|
end
|
84
84
|
|
85
|
+
def crush
|
86
|
+
data = @data
|
87
|
+
@data = deep_compact(data)
|
88
|
+
end
|
89
|
+
|
85
90
|
def clear
|
86
91
|
@data = {}
|
87
92
|
#GC.start(full_mark: true, immediate_sweep: true)
|
@@ -216,7 +221,27 @@ module DataCollector
|
|
216
221
|
out
|
217
222
|
end
|
218
223
|
|
219
|
-
|
224
|
+
def deep_compact( data )
|
225
|
+
if data.is_a?(Hash)
|
226
|
+
#puts " - Hash - #{data}"
|
227
|
+
data.compact!
|
228
|
+
data.each { |k, v| data[k] = deep_compact(v) }
|
229
|
+
data.compact!
|
230
|
+
data
|
231
|
+
elsif data.is_a?(Array)
|
232
|
+
#puts " - Array - #{data}"
|
233
|
+
data.each { |v| deep_compact(v) }
|
234
|
+
data.empty? ? nil : data
|
235
|
+
#puts " - Array size- #{data.size}"
|
236
|
+
data.size == 1 ? data[0] : data
|
237
|
+
elsif data.is_a?(String)
|
238
|
+
#puts " - String - #{data}"
|
239
|
+
data.blank? ? nil : data
|
240
|
+
else
|
241
|
+
data
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
220
245
|
private
|
221
246
|
|
222
247
|
def tar_file(tar_file_name)
|
@@ -97,6 +97,11 @@ module DataCollector
|
|
97
97
|
output_data = output_data.first
|
98
98
|
end
|
99
99
|
|
100
|
+
if options.key?('_no_array_with_one_element') && options['_no_array_with_one_element'] &&
|
101
|
+
output_data.is_a?(Array) && output_data.size == 1
|
102
|
+
output_data = output_data.first
|
103
|
+
end
|
104
|
+
|
100
105
|
output_data
|
101
106
|
end
|
102
107
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '13.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '3.18'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '3.18'
|
181
195
|
description: INPUT, FILTER, OUTPUT data with RULES and code
|
182
196
|
email:
|
183
197
|
- mehmet@celik.be
|
@@ -226,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
240
|
- !ruby/object:Gem::Version
|
227
241
|
version: '0'
|
228
242
|
requirements: []
|
229
|
-
rubygems_version: 3.1.
|
243
|
+
rubygems_version: 3.1.6
|
230
244
|
signing_key:
|
231
245
|
specification_version: 4
|
232
246
|
summary: ETL helper library
|