injest-client 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4475a67ea575aa7767fdc17cee8b603933775eabb521e18fcfa40e0328e1c542
4
- data.tar.gz: 8e16f7d280c10585d37c34e47793f7bd8629feb34d7f95ab7931ad65a2ae20bc
3
+ metadata.gz: 537873778e69eb1891c08cd6f07d1d1a438dad7e16e2d3ce055858d8a1bb7f45
4
+ data.tar.gz: ce4241f6f40c171a8d5e47a931358d30fb099169d6da139b2145559c53629f90
5
5
  SHA512:
6
- metadata.gz: e3f70641b589fdf0e5f6e19f3b93fbc88a9d3248e535c5bd5a86382f1fdf90fce1cbb352a14c7da9b84ee09b92439abc2de4421befb4d731b81f661392aa3f32
7
- data.tar.gz: 67b802232e384eae6bb6501f967d4623976d0515ceee736395023975c98cb4c0fe37a05d22abbef73eb19a23fbe5f79936568e95414f4fc5d9b2cc2dc4ca577b
6
+ metadata.gz: 0b8ab0523bb1747ff28f558d2357c535bac33cae5170bcda0c667ef10f93444dc414c53a4d6426cfb95b992b80e9d9bc96300dda4e17299bd28d851201c468c2
7
+ data.tar.gz: a31278290f4a744026eb27507b29e22d030868c7b09f00d61774401b8183a962d8969f92f4567c9f513991e918efc8846eab3c41b467cf1852b0b025f0988873
data/lib/README.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Changelog
4
4
 
5
+ ### 0.1.8
6
+
7
+ - Fix bug in the configuration initialization which prevented the INJEST_ROOT and INJEST_JWT from being set correctly
8
+
9
+ ### 0.1.7
10
+
11
+ - Support multiple strategies via the `INJEST_STRATEGY` env var, example: `INJEST_STRATEGY="stdout,http"`
12
+ - Added the `jsonout` strategy
13
+
5
14
  ### 0.1.6
6
15
 
7
16
  - fix bad exception raise
@@ -26,6 +35,13 @@ ENV vars
26
35
  - `INJEST_JWT`: a JWT required with strategy `http` or `push`
27
36
  - `INJEST_CLIENT`: (optional) a string to bind to a specific client
28
37
 
38
+ ## Release
39
+
40
+ ```bash
41
+ ./console.sh build
42
+ ./console.sh release
43
+ ```
44
+
29
45
  ## TODO:
30
46
 
31
47
  - Customization with procs
@@ -1,18 +1,32 @@
1
1
  class Injest::Configuration
2
2
  include Singleton
3
3
 
4
- attr_reader :strategy,
5
- :injest_root, :injest_token, :injest_client
4
+ attr_reader :strategy,
5
+ :strategies,
6
+ :injest_root,
7
+ :injest_token,
8
+ :injest_client
6
9
 
7
10
  private
11
+
8
12
  def initialize
9
- @strategy = ENV.fetch('INJEST_STRATEGY', 'stdout')
13
+ @strategy = ENV.fetch('INJEST_STRATEGY')
14
+ set_strategies
10
15
 
11
- if strategy == 'http' || strategy == 'push'
16
+ if @strategies.include?('push') || @strategies.include?('http')
12
17
  @injest_root = ENV.fetch('INJEST_ROOT')
13
18
  @injest_token = ENV.fetch('INJEST_JWT')
14
19
  end
15
-
20
+
16
21
  @injest_client = ENV.fetch('INJEST_CLIENT', nil)
17
22
  end
23
+
24
+ def set_strategies
25
+ raw = @strategy
26
+ if raw == nil || raw == ''
27
+ @strategies = ['null']
28
+ else
29
+ @strategies = raw.split(',')
30
+ end
31
+ end
18
32
  end
data/lib/injest/writer.rb CHANGED
@@ -4,27 +4,48 @@ class Injest::Writer
4
4
  attr_reader :configuration, :http_client
5
5
 
6
6
  def append(data, sync: false)
7
- case configuration.strategy
8
- when 'push', 'http'
7
+ if @strategies.include?('push') || @strategies.include?('http')
9
8
  if sync
10
9
  http_client.push(data)
11
10
  else
12
11
  Injest::Worker.perform_async(data)
13
12
  end
14
-
15
- when 'stdout'
13
+ end
14
+
15
+ if @strategies.include?('stdout')
16
16
  print(data)
17
+ end
17
18
 
18
- when 'null'
19
- # Do nothing
20
- else
21
- # Do nothing
19
+ if @strategies.include?('jsonout')
20
+ if Kernel.const_defined?('Rails')
21
+ Rails.logger.info(data.to_json)
22
+ else
23
+ puts data.to_json
24
+ end
22
25
  end
26
+
27
+ # case configuration.strategy
28
+ # when 'push', 'http'
29
+ # if sync
30
+ # http_client.push(data)
31
+ # else
32
+ # Injest::Worker.perform_async(data)
33
+ # end
34
+ #
35
+ # when 'stdout'
36
+ # print(data)
37
+ #
38
+ # when 'null'
39
+ # # Do nothing
40
+ # else
41
+ # # Do nothing
42
+ # end
23
43
  end
24
44
 
25
45
  private
26
46
  def initialize
27
47
  @configuration = Injest::Configuration.instance
48
+ set_strategies
28
49
  @http_client = Injest::HttpClient.new(configuration)
29
50
  end
30
51
 
@@ -60,4 +81,13 @@ class Injest::Writer
60
81
  puts "Response: #{data[:response][:status]}"
61
82
  puts data[:response][:body].inspect
62
83
  end
84
+
85
+ def set_strategies
86
+ raw = @configuration.strategy
87
+ if raw == nil || raw == ''
88
+ @strategies = ['null']
89
+ else
90
+ @strategies = raw.split(',')
91
+ end
92
+ end
63
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: injest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Lampis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-25 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq