data_collector 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ab3a14bc19fd6570cc8061cd39077cbc238816d547385a1babb93f2174dbb8
4
- data.tar.gz: 3293a317720d0f72581bad60621572c4fca4caa06fc29f12cbaac9eee6e3e559
3
+ metadata.gz: 9ada83aba097793e130f92865b86f6fbf9b8e43e23b73e788f8683397d3cf7d3
4
+ data.tar.gz: 03706e1fc9f239ef7f265b826916b08f98af250bb537214acfef9aa71d5bb1f1
5
5
  SHA512:
6
- metadata.gz: 2fae16f848aaf7153d9fdce64cfcf2059a2712155fcdb28f0f46cb70d18419f15745ee90fb87b7d0d81dfcf9ebd48badb5aea201ef8d7108a3b2eea9f3479610
7
- data.tar.gz: c224c1440dfc879fed651cb1984d363315c1cb45e9f1ee594171d2c5a846f50f167c415a1a83994d509f1757752cb90fa0eba659a3d48c2afdd5cf21fe1c1b28
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
- - 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:
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
@@ -49,4 +49,5 @@ Gem::Specification.new do |spec|
49
49
  spec.add_development_dependency 'bundler', '~> 2.3'
50
50
  spec.add_development_dependency 'minitest', '~> 5.16'
51
51
  spec.add_development_dependency 'rake', '~> 13.0'
52
+ spec.add_development_dependency 'webmock', '~> 3.18'
52
53
  end
@@ -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
- if options.keys.include?(:user) && options.keys.include?(:password)
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
- else
71
- @logger.warn ("User or Password parameter not found")
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
- http_response = http.get(escape_uri(uri))
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
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.12.0"
3
+ VERSION = "0.13.0"
4
4
  end
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.12.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: 2022-08-01 00:00:00.000000000 Z
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.4
243
+ rubygems_version: 3.1.6
230
244
  signing_key:
231
245
  specification_version: 4
232
246
  summary: ETL helper library