zaikio-loom 0.3.0 → 1.0.1

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: 83b8f848c42ce893f17ea2fcc965f607cbb2582de13d2cb6a5082937f4035d66
4
- data.tar.gz: dcc33304f16d8e5b223ddd62d4edb339fc087cfb8f25b61a464a76e2f2a03a0c
3
+ metadata.gz: a73006847e32a2ba98ff3c5cc9dfd1639b9d0e198d1886f59eabf699f6872a11
4
+ data.tar.gz: 1706ee24ba6b90be47c15fa00ce8e889892fc6457c1a86267dcad091567b2654
5
5
  SHA512:
6
- metadata.gz: 3f123c3dd9b2356b118593d3de86f78b7ef9307c0118b174a84b44b77acff372660e39b9bbe218c19ca19f3602c98e0d9fc6159d54a50314d7688a2d12322ea0
7
- data.tar.gz: c612160d9ff55ebd84d2bc75d3d42549dfe6b0510f6dc57f43706cc4f5f2a3750fe7bb210a90fe898a36a15bcbf85076ac12dad73723d6483341dbca8be8934f
6
+ metadata.gz: 57bc16d2760ae45ea9518f5485226d0a3de33e41d71b1865acad56bd7728ef18ecd237ed84f716c3acbdf8867a2523bb907753fa5cab17cb0657cc85445d5c1c
7
+ data.tar.gz: 348db1e985341b8ce6faf351490ff3532add06bea87db825881f3806c1b0aa5cf719cc10594070eee1892ca0f85a0be208aabe874d3d9195420e8c5f428b96fa
@@ -1,5 +1,14 @@
1
1
  # Zaikio Loom Ruby Gem Changelog
2
2
 
3
+ ## 1.0.0 - 2020-06-03
4
+
5
+ - Fix a bug in the event serializer
6
+
7
+ ## 1.0.0 - 2020-06-03
8
+
9
+ - Add multi client support
10
+ - Confguration format changed
11
+
3
12
  ## 0.3.0 - 2020-04-22
4
13
 
5
14
  - Do not send events to Loom in development or staging environment
@@ -1,68 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zaikio-loom (0.3.0)
4
+ zaikio-loom (1.0.1)
5
5
  oj
6
6
  rails (~> 6.0, >= 6.0.2.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (6.0.2.2)
12
- actionpack (= 6.0.2.2)
11
+ actioncable (6.0.3.1)
12
+ actionpack (= 6.0.3.1)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.0.2.2)
16
- actionpack (= 6.0.2.2)
17
- activejob (= 6.0.2.2)
18
- activerecord (= 6.0.2.2)
19
- activestorage (= 6.0.2.2)
20
- activesupport (= 6.0.2.2)
15
+ actionmailbox (6.0.3.1)
16
+ actionpack (= 6.0.3.1)
17
+ activejob (= 6.0.3.1)
18
+ activerecord (= 6.0.3.1)
19
+ activestorage (= 6.0.3.1)
20
+ activesupport (= 6.0.3.1)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.0.2.2)
23
- actionpack (= 6.0.2.2)
24
- actionview (= 6.0.2.2)
25
- activejob (= 6.0.2.2)
22
+ actionmailer (6.0.3.1)
23
+ actionpack (= 6.0.3.1)
24
+ actionview (= 6.0.3.1)
25
+ activejob (= 6.0.3.1)
26
26
  mail (~> 2.5, >= 2.5.4)
27
27
  rails-dom-testing (~> 2.0)
28
- actionpack (6.0.2.2)
29
- actionview (= 6.0.2.2)
30
- activesupport (= 6.0.2.2)
28
+ actionpack (6.0.3.1)
29
+ actionview (= 6.0.3.1)
30
+ activesupport (= 6.0.3.1)
31
31
  rack (~> 2.0, >= 2.0.8)
32
32
  rack-test (>= 0.6.3)
33
33
  rails-dom-testing (~> 2.0)
34
34
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
- actiontext (6.0.2.2)
36
- actionpack (= 6.0.2.2)
37
- activerecord (= 6.0.2.2)
38
- activestorage (= 6.0.2.2)
39
- activesupport (= 6.0.2.2)
35
+ actiontext (6.0.3.1)
36
+ actionpack (= 6.0.3.1)
37
+ activerecord (= 6.0.3.1)
38
+ activestorage (= 6.0.3.1)
39
+ activesupport (= 6.0.3.1)
40
40
  nokogiri (>= 1.8.5)
41
- actionview (6.0.2.2)
42
- activesupport (= 6.0.2.2)
41
+ actionview (6.0.3.1)
42
+ activesupport (= 6.0.3.1)
43
43
  builder (~> 3.1)
44
44
  erubi (~> 1.4)
45
45
  rails-dom-testing (~> 2.0)
46
46
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
- activejob (6.0.2.2)
48
- activesupport (= 6.0.2.2)
47
+ activejob (6.0.3.1)
48
+ activesupport (= 6.0.3.1)
49
49
  globalid (>= 0.3.6)
50
- activemodel (6.0.2.2)
51
- activesupport (= 6.0.2.2)
52
- activerecord (6.0.2.2)
53
- activemodel (= 6.0.2.2)
54
- activesupport (= 6.0.2.2)
55
- activestorage (6.0.2.2)
56
- actionpack (= 6.0.2.2)
57
- activejob (= 6.0.2.2)
58
- activerecord (= 6.0.2.2)
50
+ activemodel (6.0.3.1)
51
+ activesupport (= 6.0.3.1)
52
+ activerecord (6.0.3.1)
53
+ activemodel (= 6.0.3.1)
54
+ activesupport (= 6.0.3.1)
55
+ activestorage (6.0.3.1)
56
+ actionpack (= 6.0.3.1)
57
+ activejob (= 6.0.3.1)
58
+ activerecord (= 6.0.3.1)
59
59
  marcel (~> 0.3.1)
60
- activesupport (6.0.2.2)
60
+ activesupport (6.0.3.1)
61
61
  concurrent-ruby (~> 1.0, >= 1.0.2)
62
62
  i18n (>= 0.7, < 2)
63
63
  minitest (~> 5.1)
64
64
  tzinfo (~> 1.1)
65
- zeitwerk (~> 2.2)
65
+ zeitwerk (~> 2.2, >= 2.2.2)
66
66
  addressable (2.7.0)
67
67
  public_suffix (>= 2.0.2, < 5.0)
68
68
  ast (2.4.0)
@@ -77,7 +77,6 @@ GEM
77
77
  hashdiff (1.0.1)
78
78
  i18n (1.8.2)
79
79
  concurrent-ruby (~> 1.0)
80
- jaro_winkler (1.5.4)
81
80
  loofah (2.5.0)
82
81
  crass (~> 1.0.2)
83
82
  nokogiri (>= 1.5.9)
@@ -86,60 +85,64 @@ GEM
86
85
  marcel (0.3.3)
87
86
  mimemagic (~> 0.3.2)
88
87
  method_source (1.0.0)
89
- mimemagic (0.3.4)
88
+ mimemagic (0.3.5)
90
89
  mini_mime (1.0.2)
91
90
  mini_portile2 (2.4.0)
92
- minitest (5.14.0)
91
+ minitest (5.14.1)
93
92
  mocha (1.11.2)
94
93
  nio4r (2.5.2)
95
94
  nokogiri (1.10.9)
96
95
  mini_portile2 (~> 2.4.0)
97
96
  oj (3.10.6)
98
97
  parallel (1.19.1)
99
- parser (2.7.1.1)
98
+ parser (2.7.1.3)
100
99
  ast (~> 2.4.0)
101
100
  public_suffix (4.0.4)
102
101
  rack (2.2.2)
103
102
  rack-test (1.1.0)
104
103
  rack (>= 1.0, < 3)
105
- rails (6.0.2.2)
106
- actioncable (= 6.0.2.2)
107
- actionmailbox (= 6.0.2.2)
108
- actionmailer (= 6.0.2.2)
109
- actionpack (= 6.0.2.2)
110
- actiontext (= 6.0.2.2)
111
- actionview (= 6.0.2.2)
112
- activejob (= 6.0.2.2)
113
- activemodel (= 6.0.2.2)
114
- activerecord (= 6.0.2.2)
115
- activestorage (= 6.0.2.2)
116
- activesupport (= 6.0.2.2)
104
+ rails (6.0.3.1)
105
+ actioncable (= 6.0.3.1)
106
+ actionmailbox (= 6.0.3.1)
107
+ actionmailer (= 6.0.3.1)
108
+ actionpack (= 6.0.3.1)
109
+ actiontext (= 6.0.3.1)
110
+ actionview (= 6.0.3.1)
111
+ activejob (= 6.0.3.1)
112
+ activemodel (= 6.0.3.1)
113
+ activerecord (= 6.0.3.1)
114
+ activestorage (= 6.0.3.1)
115
+ activesupport (= 6.0.3.1)
117
116
  bundler (>= 1.3.0)
118
- railties (= 6.0.2.2)
117
+ railties (= 6.0.3.1)
119
118
  sprockets-rails (>= 2.0.0)
120
119
  rails-dom-testing (2.0.3)
121
120
  activesupport (>= 4.2.0)
122
121
  nokogiri (>= 1.6)
123
122
  rails-html-sanitizer (1.3.0)
124
123
  loofah (~> 2.3)
125
- railties (6.0.2.2)
126
- actionpack (= 6.0.2.2)
127
- activesupport (= 6.0.2.2)
124
+ railties (6.0.3.1)
125
+ actionpack (= 6.0.3.1)
126
+ activesupport (= 6.0.3.1)
128
127
  method_source
129
128
  rake (>= 0.8.7)
130
129
  thor (>= 0.20.3, < 2.0)
131
130
  rainbow (3.0.0)
132
131
  rake (13.0.1)
132
+ regexp_parser (1.7.0)
133
133
  rexml (3.2.4)
134
- rubocop (0.82.0)
135
- jaro_winkler (~> 1.5.1)
134
+ rubocop (0.85.0)
136
135
  parallel (~> 1.10)
137
136
  parser (>= 2.7.0.1)
138
137
  rainbow (>= 2.2.2, < 4.0)
138
+ regexp_parser (>= 1.7)
139
139
  rexml
140
+ rubocop-ast (>= 0.0.3)
140
141
  ruby-progressbar (~> 1.7)
141
142
  unicode-display_width (>= 1.4.0, < 2.0)
142
- rubocop-performance (1.5.2)
143
+ rubocop-ast (0.0.3)
144
+ parser (>= 2.7.0.1)
145
+ rubocop-performance (1.6.0)
143
146
  rubocop (>= 0.71.0)
144
147
  ruby-progressbar (1.10.1)
145
148
  safe_yaml (1.0.5)
@@ -159,9 +162,9 @@ GEM
159
162
  addressable (>= 2.3.6)
160
163
  crack (>= 0.3.2)
161
164
  hashdiff (>= 0.4.0, < 2.0.0)
162
- websocket-driver (0.7.1)
165
+ websocket-driver (0.7.2)
163
166
  websocket-extensions (>= 0.1.0)
164
- websocket-extensions (0.1.4)
167
+ websocket-extensions (0.1.5)
165
168
  zeitwerk (2.3.0)
166
169
 
167
170
  PLATFORMS
data/README.md CHANGED
@@ -35,17 +35,35 @@ Zaikio::Loom.configure do |config|
35
35
 
36
36
  # The name of your application like it is named in the directory of the
37
37
  # choosen enviroment.
38
- config.app_name = 'my_application'
39
-
40
- # Your application's event password for the choosen environment
41
- # Do not add this password into version control.
42
- config.password = ENV.fetch('ZAIKIO_LOOM_PASSWORD')
38
+ config.application 'my_application' do |app|
39
+ # Your application's event password for the choosen environment
40
+ # Do not add this password into version control.
41
+ app.password = ENV.fetch('ZAIKIO_LOOM_PASSWORD')
42
+ end
43
43
 
44
44
  # The version of the event's payload format and structure
45
45
  config.version = '1.0'
46
46
  end
47
47
  ```
48
48
 
49
+ #### Multiple Clients
50
+
51
+ ```ruby
52
+ # in config/initializers/zaikio_loom.rb
53
+ Zaikio::Loom.configure do |config|
54
+ config.environment = :sandbox
55
+ config.version = '1.0'
56
+
57
+ config.application 'my_application' do |app|
58
+ app.password = ENV.fetch('ZAIKIO_LOOM_PASSWORD')
59
+ end
60
+
61
+ config.application 'my_other_app' do |app|
62
+ app.password = ENV.fetch('ZAIKIO_LOOM_OTHER_APP_PASSWORD')
63
+ end
64
+ end
65
+ ```
66
+
49
67
  ### Usage
50
68
 
51
69
  Firing events to Zaikio Loom:
@@ -60,6 +78,16 @@ Zaikio::Loom.fire_event(
60
78
 
61
79
  This example would publish an event (in the background) to Zaikio Loom with a random UUID and the current timestamp.
62
80
 
81
+ If you want to publish the event for a specific client, you have to add it as part of the event name:
82
+
83
+ ```rb
84
+ Zaikio::Loom.fire_event(
85
+ 'my_other_app.event_name',
86
+ subject: 'Org/3a242896-fa57-41ba-997e-8c212d7157f3',
87
+ payload: { foo: 'bar', baz: [1, 2, 3] }
88
+ )
89
+ ```
90
+
63
91
  If you need more control over the published event, for example:
64
92
 
65
93
  - to provide a specific unique UUID or timestamp in the past or
@@ -1,3 +1,4 @@
1
+ require "zaikio/loom/app_configuration"
1
2
  require "zaikio/loom/configuration"
2
3
  require "zaikio/loom/event"
3
4
  require "zaikio/loom/event_serializer"
@@ -0,0 +1,11 @@
1
+ module Zaikio
2
+ module Loom
3
+ class AppConfiguration
4
+ attr_accessor :app_name, :password
5
+
6
+ def initialize(app_name)
7
+ @app_name = app_name
8
+ end
9
+ end
10
+ end
11
+ end
@@ -9,12 +9,13 @@ module Zaikio
9
9
  production: "https://loom.zaikio.com"
10
10
  }.freeze
11
11
 
12
- attr_accessor :app_name, :password, :version
13
- attr_reader :environment, :host
12
+ attr_accessor :version
13
+ attr_reader :environment, :host, :apps
14
14
  attr_writer :logger
15
15
 
16
16
  def initialize
17
17
  @environment = :sandbox
18
+ @apps = {}
18
19
  end
19
20
 
20
21
  def logger
@@ -25,6 +26,11 @@ module Zaikio
25
26
  @environment = env.to_sym
26
27
  @host = HOSTS[environment]
27
28
  end
29
+
30
+ def application(name)
31
+ @apps[name.to_s] = AppConfiguration.new(name.to_s)
32
+ yield(@apps[name.to_s])
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -7,8 +7,8 @@ module Zaikio
7
7
  class Event
8
8
  attr_reader :id, :status_code, :response_body
9
9
 
10
- def initialize(name, subject:, id: nil, link: nil, payload: nil, receiver: nil, timestamp: nil, version: nil) # rubocop:disable Metrics/ParameterLists
11
- @event_name = "#{configuration.app_name}.#{name}"
10
+ def initialize(name, subject:, id: nil, link: nil, payload: nil, receiver: nil, timestamp: nil, version: nil) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
11
+ @event_name = name.to_s.count(".").zero? ? "#{configuration.apps.values.first.app_name}.#{name}" : name.to_s
12
12
  @id = id || SecureRandom.uuid
13
13
  @link = link
14
14
  @payload = payload
@@ -17,7 +17,7 @@ module Zaikio
17
17
  @timestamp = timestamp
18
18
  @version = version || configuration.version
19
19
 
20
- return if configuration.password
20
+ return if app_password
21
21
 
22
22
  configuration.logger.error("Zaikio::Loom is disabled – event password is missing")
23
23
  end
@@ -25,7 +25,7 @@ module Zaikio
25
25
  def fire # rubocop:disable Metrics/AbcSize
26
26
  log_event
27
27
 
28
- return false unless configuration.password && configuration.host
28
+ return false unless app_password && configuration.host
29
29
 
30
30
  uri = URI("#{configuration.host}/api/v1/events")
31
31
 
@@ -57,9 +57,17 @@ module Zaikio
57
57
 
58
58
  private
59
59
 
60
+ def app_name
61
+ @event_name.split(".").first
62
+ end
63
+
64
+ def app_password
65
+ configuration.apps[app_name].password
66
+ end
67
+
60
68
  def build_request(uri)
61
69
  Net::HTTP::Post.new(uri, "User-Agent" => "zaikio-loom:#{Zaikio::Loom::VERSION}").tap do |request|
62
- request.basic_auth(configuration.app_name, configuration.password)
70
+ request.basic_auth(app_name, app_password)
63
71
  request.body = event_as_json
64
72
  request.content_type = "application/json"
65
73
  end
@@ -10,7 +10,7 @@ module Zaikio
10
10
  end
11
11
 
12
12
  def deserialize(hash)
13
- name = hash.delete("name").split(".").last
13
+ name = hash.delete("name")
14
14
  timestamp = DateTime.parse(hash.delete("timestamp"))
15
15
  hash.delete("_aj_serialized")
16
16
  Event.new(name, **hash.symbolize_keys.merge(timestamp: timestamp))
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Loom
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "1.0.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-loom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-22 00:00:00.000000000 Z
12
+ date: 2020-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oj
@@ -166,6 +166,7 @@ files:
166
166
  - bin/test
167
167
  - config/initializers/register_zaikio_loom_event_serializer.rb
168
168
  - lib/zaikio/loom.rb
169
+ - lib/zaikio/loom/app_configuration.rb
169
170
  - lib/zaikio/loom/configuration.rb
170
171
  - lib/zaikio/loom/engine.rb
171
172
  - lib/zaikio/loom/event.rb