data_collector 0.35.0 → 0.38.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: 1b9d99a5bf660ca9feb5bea5dd13f12c2539dcb224d6689b7a1181af32d0ab20
4
- data.tar.gz: 84fa315a8e2fa932caf84cad75d9c86c643c8d3b1faa389b383125de23022630
3
+ metadata.gz: 7c584cb29547a8e6e2caf026d8860228366e2cae387ac4111c125e5450a90586
4
+ data.tar.gz: ea87c6fec5817023b653472f6566bf48e951755e16b8e5ab08378c4600ca01fe
5
5
  SHA512:
6
- metadata.gz: 82cb1c183a2d7a8ea950a181f2ae9571720533b6defd378bc0cab91fc84d876c75fc71029cd1f46c993c0b004eee7ecf32635bff808cda4419b3236ea7206c42
7
- data.tar.gz: 3bf761a214120ed1d12aad599e8137ce9a9b2028c757a7e59117d0ac3300e307237160cfb359032d8506db8efc37aee3669604bba0cbac59b60b51e064fc79e8
6
+ metadata.gz: c6b8fbe6975c800cd2ca179d6cc97555aa6b2cfa279d223f9cb52c03fa48186e336f6129701b820630eba912901c7d4b2a60f58678f282742cba36f4b46e0b3c
7
+ data.tar.gz: f08929aea4bb836e55a8ac0203cf14048ccfe1c60d1ed7af871625938877c0b2f38619cf2923da48bac9e002fa9dd37967639713390f0bc4c011dcd54f7eb50d
data/README.md CHANGED
@@ -403,6 +403,13 @@ Should give as output
403
403
  </data>
404
404
  ```
405
405
 
406
+ You can provide options to input.from_uri for better reading CSV formats these
407
+ are the same the Ruby [CSV](https://docs.ruby-lang.org/en/master/CSV.html#class-CSV-label-Options) class
408
+
409
+ Loading a CSV file with **;** as the row seperator
410
+ ```ruby
411
+ i = input.from_uri('https://support.staffbase.com/hc/en-us/article_attachments/360009197031/username.csv', col_sep: ';')
412
+ ```
406
413
 
407
414
  ## Installation
408
415
 
@@ -51,6 +51,8 @@ Gem::Specification.new do |spec|
51
51
  spec.add_runtime_dependency 'builder', '~> 3.2'
52
52
  spec.add_runtime_dependency 'parse-cron', '~> 0.1'
53
53
  spec.add_runtime_dependency 'linkeddata', '~> 3.3'
54
+ spec.add_runtime_dependency 'connection_pool', '~> 2.4'
55
+
54
56
 
55
57
  spec.add_development_dependency 'bundler', '~> 2.3'
56
58
  spec.add_development_dependency 'minitest', '~> 5.18'
@@ -0,0 +1,58 @@
1
+ require 'connection_pool'
2
+
3
+ module BunnyBurrow
4
+ class Connection
5
+ include Singleton
6
+ attr_reader :connection, :started
7
+ attr_accessor :verify_peer, :name, :rabbitmq_url
8
+
9
+ def initialize
10
+ super
11
+ @started = false
12
+ end
13
+ def connection
14
+ @connection ||= Bunny.new(@rabbitmq_url, verify_peer: @verify_peer, connection_name: @name)
15
+ unless @started
16
+ @connection.start
17
+ @started = true
18
+ end
19
+
20
+ @connection
21
+ end
22
+
23
+ def channel
24
+ @channel ||= ConnectionPool::Wrapper.new do
25
+ connection.create_channel
26
+ end
27
+ end
28
+ end
29
+
30
+ class Base
31
+ attr_accessor(
32
+ :name
33
+ )
34
+
35
+ private
36
+
37
+ def connection
38
+ Connection.instance.name = @name
39
+ Connection.instance.verify_peer = @verify_peer
40
+ Connection.instance.rabbitmq_url = @rabbitmq_url
41
+
42
+ unless @connection
43
+ @connection = Connection.instance.connection
44
+ end
45
+
46
+ @connection
47
+ end
48
+
49
+ def channel
50
+ Connection.instance.name = @name
51
+ Connection.instance.verify_peer = @verify_peer
52
+ Connection.instance.rabbitmq_url = @rabbitmq_url
53
+
54
+ @channel ||= Connection.instance.channel
55
+ end
56
+ end
57
+ end
58
+
@@ -1,4 +1,7 @@
1
+ require 'bunny_burrow'
2
+ require_relative '../ext/base'
1
3
  require 'listen'
4
+ require 'active_support/core_ext/hash'
2
5
 
3
6
  module DataCollector
4
7
  class Input
@@ -1,9 +1,4 @@
1
1
  require_relative 'generic'
2
- require 'bunny_burrow'
3
- require 'active_support/core_ext/hash'
4
- require 'ostruct'
5
- require 'securerandom'
6
- require 'thread'
7
2
 
8
3
  module DataCollector
9
4
  class Input
@@ -64,6 +59,7 @@ module DataCollector
64
59
  server.rabbitmq_url = @bunny_uri.to_s
65
60
  server.rabbitmq_exchange = @bunny_channel
66
61
 
62
+ #server.connection_name = @name
67
63
  server.logger = DataCollector::Core.logger if log
68
64
  end
69
65
 
@@ -161,7 +161,7 @@ module DataCollector
161
161
  when 'application/atom+xml'
162
162
  data = xml_to_hash(data, options)
163
163
  when 'text/csv'
164
- data = csv_to_hash(data)
164
+ data = csv_to_hash(data, options)
165
165
  when 'application/xml'
166
166
  data = xml_to_hash(data, options)
167
167
  when 'text/xml'
@@ -231,7 +231,7 @@ module DataCollector
231
231
  end #entry
232
232
  end #tar
233
233
  when '.csv'
234
- data = csv_to_hash(data)
234
+ data = csv_to_hash(data, options)
235
235
  else
236
236
  raise "Do not know how to process #{uri.to_s}"
237
237
  end
@@ -264,8 +264,15 @@ module DataCollector
264
264
  nori.parse(data)
265
265
  end
266
266
 
267
- def csv_to_hash(data)
268
- csv = CSV.parse(data, headers: true, header_converters: [:downcase, :symbol])
267
+ def csv_to_hash(data, options = {})
268
+ csv_option_keys = options.keys & CSV::DEFAULT_OPTIONS.keys
269
+ all_cvs_options = {headers: true, header_converters: [:downcase, :symbol]}
270
+
271
+ csv_option_keys.each do |k|
272
+ all_cvs_options[k] = options[k]
273
+ end
274
+
275
+ csv = CSV.parse(data, **all_cvs_options)
269
276
 
270
277
  csv.collect do |record|
271
278
  record.to_hash
@@ -1,5 +1,7 @@
1
1
  require 'bunny_burrow'
2
+ require_relative '../ext/base'
2
3
  require 'json'
4
+ require 'active_support/core_ext/hash'
3
5
 
4
6
  module DataCollector
5
7
  class Output
@@ -20,12 +20,14 @@ module DataCollector
20
20
  end
21
21
 
22
22
  private
23
- def create_producer
23
+ def create_producer(log = false)
24
24
  @producer ||= BunnyBurrow::Client.new do |client|
25
25
  parse_uri
26
26
  client.rabbitmq_url = @bunny_uri.to_s
27
27
  client.rabbitmq_exchange = @bunny_channel
28
- client.logger = DataCollector::Core.logger
28
+ #client.connection_name = @name
29
+
30
+ client.logger = DataCollector::Core.logger if log
29
31
  @running = true
30
32
  end
31
33
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module DataCollector
3
- VERSION = "0.35.0"
3
+ VERSION = "0.38.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.35.0
4
+ version: 0.38.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: 2023-11-13 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '3.3'
223
+ - !ruby/object:Gem::Dependency
224
+ name: connection_pool
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '2.4'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '2.4'
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: bundler
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -296,6 +310,7 @@ files:
296
310
  - lib/data_collector.rb
297
311
  - lib/data_collector/config_file.rb
298
312
  - lib/data_collector/core.rb
313
+ - lib/data_collector/ext/base.rb
299
314
  - lib/data_collector/ext/xml_utility_node.rb
300
315
  - lib/data_collector/input.rb
301
316
  - lib/data_collector/input/dir.rb