omnihooks 0.0.1 → 0.1.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 +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/README.md +40 -19
- data/Rakefile +4 -0
- data/lib/omnihooks/builder.rb +3 -4
- data/lib/omnihooks/strategy.rb +6 -4
- data/lib/omnihooks/version.rb +1 -1
- data/omnihooks.gemspec +1 -1
- data/spec/omnihooks/strategy_spec.rb +6 -6
- metadata +17 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f133f4e912d2bd925d5827a580c67b2971ec8698ef02105a3905f55638f3c17
|
4
|
+
data.tar.gz: dc3c1d619c4bdf260ae499928cacafea8b24dd06175114595b8c74c38dffe813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e748a268c94fa4a47fe0cf0b5287c84e63db249f6fef152924f60dc9f1671670840f4b91c5b09076d7fe9f0fbe76cfe283a39e21e8fc2ead865c924c6ac59fbf
|
7
|
+
data.tar.gz: 200e5903fa90f7af8f041a81a8e292ba7bac8818dd60d698ea7aa4f2f1e60b9e10a15b4ff1357b5325ebfbabc8dd08ce33f6ad1b779e8ef62a8bc19a87f160c8
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.5
|
data/README.md
CHANGED
@@ -1,31 +1,52 @@
|
|
1
|
-
# OmniHooks
|
1
|
+
# OmniHooks: Standardized Multi-Provider Webhooks
|
2
2
|
|
3
|
-
|
3
|
+
## Introduction
|
4
4
|
|
5
|
-
|
5
|
+
OmniHooks is a library that standardizes multi-provider webhooks for web applications. It was created to be powerful, flexible, and do as little as possible. Any developer can create strategies for OmniHooks that can handle webhooks via disparate systems.
|
6
6
|
|
7
|
-
|
7
|
+
In order to use OmniHooks in your applications, you will need to leverage one or more strategies. These strategies are generally released individually as RubyGems, and you can see a [community maintained list](https://github.com/dropstream/omnihooks/wiki/List-of-Strategies) on the wiki for this project.
|
8
8
|
|
9
|
-
|
10
|
-
gem 'omnihooks'
|
11
|
-
```
|
9
|
+
## Getting Started
|
12
10
|
|
13
|
-
|
11
|
+
Each OmniHook strategy is a Rack Middleware. That means that you can use it the same way that you use any other Rack middleware. For example, to use the built-in Developer strategy in a Sinatra application I might do this:
|
14
12
|
|
15
|
-
|
13
|
+
````ruby
|
14
|
+
require 'sinatra'
|
15
|
+
require 'omnihooks'
|
16
16
|
|
17
|
-
|
17
|
+
class MyApplication < Sinatra::Base
|
18
|
+
use Rack::Session::Cookie
|
19
|
+
use OmniHooks::Strategies::Developer
|
20
|
+
end
|
21
|
+
````
|
18
22
|
|
19
|
-
|
23
|
+
Because OmniHooks is built for multi-provider webhooks, I may want to leave room to run multiple strategies. For this, the built-in OmniHooks::Builder class gives you an easy way to specify multiple strategies.
|
20
24
|
|
21
|
-
|
25
|
+
````ruby
|
26
|
+
require 'sinatra'
|
27
|
+
require 'omnihooks'
|
22
28
|
|
23
|
-
|
29
|
+
class MyApplication < Sinatra::Base
|
30
|
+
use Rack::Session::Cookie
|
31
|
+
use OmniHooks::Builder do
|
32
|
+
provider :developer do |p|
|
33
|
+
p.configure do |c|
|
34
|
+
c.subscribe 'foo', Proc.new { |event| nil }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
provider :core_warehouse do |p|
|
38
|
+
p.configure do |c|
|
39
|
+
c.subscribe 'Shipment', Proc.new { |event| nil }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
````
|
24
45
|
|
25
|
-
##
|
46
|
+
## Logging
|
26
47
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
48
|
+
OmniHooks supports a configurable logger. By default, OmniHooks will log to STDOUT but you can configure this using `OmniHooks.config.logger`:
|
49
|
+
|
50
|
+
## Resources
|
51
|
+
|
52
|
+
The [OmniHooks Wiki](https://github.com/dropstream/omnihooks/wiki) has actively maintained in-depth documentation for OmniHooks. It should be your first stop if you are wondering about a more in-depth look at OmniHooks, how it works, and how to use it.
|
data/Rakefile
CHANGED
data/lib/omnihooks/builder.rb
CHANGED
@@ -3,19 +3,18 @@ require "active_support/inflector"
|
|
3
3
|
module OmniHooks
|
4
4
|
class Builder < ::Rack::Builder
|
5
5
|
|
6
|
-
def initialize(app, &block)
|
6
|
+
def initialize(app = nil, &block)
|
7
7
|
@options = nil
|
8
8
|
if rack14?
|
9
9
|
super
|
10
10
|
else
|
11
11
|
@app = app
|
12
|
-
super(&block)
|
13
|
-
@ins << @app
|
12
|
+
super(app, &block)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
16
|
def rack14?
|
18
|
-
Rack.release.split('.')[1].to_i >= 4
|
17
|
+
Rack.release.split('.')[0].to_i == 1 && Rack.release.split('.')[1].to_i >= 4
|
19
18
|
end
|
20
19
|
|
21
20
|
def on_failure(&block)
|
data/lib/omnihooks/strategy.rb
CHANGED
@@ -221,7 +221,6 @@ module OmniHooks
|
|
221
221
|
# @param env [Hash] The Rack environment.
|
222
222
|
def call!(env) # rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
223
223
|
@env = env
|
224
|
-
|
225
224
|
return instrument if on_request_path? && OmniHooks.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
226
225
|
|
227
226
|
@app.call(env)
|
@@ -253,13 +252,16 @@ module OmniHooks
|
|
253
252
|
begin
|
254
253
|
evt = get_event
|
255
254
|
evt_type = get_event_type
|
255
|
+
|
256
256
|
self.class.instrument(evt_type, evt) if evt
|
257
|
-
rescue => e
|
257
|
+
rescue Exception => e
|
258
258
|
log(:error, e.message)
|
259
|
-
|
259
|
+
log(:error, e.backtrace.join("\n"))
|
260
|
+
[500, {}, [EMPTY_STRING]]
|
260
261
|
else
|
262
|
+
log(:debug, "success")
|
261
263
|
# Send a 200 response back to
|
262
|
-
[200, {}, [
|
264
|
+
[200, {}, [EMPTY_STRING]]
|
263
265
|
end
|
264
266
|
end
|
265
267
|
|
data/lib/omnihooks/version.rb
CHANGED
data/omnihooks.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "activesupport", ">= 3.1"
|
21
|
-
spec.add_dependency 'rack',
|
21
|
+
spec.add_dependency 'rack', ">= 1.2", "< 3"
|
22
22
|
spec.add_dependency 'hashie', ['>= 1.2', '< 4']
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
@@ -203,7 +203,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
203
203
|
|
204
204
|
expect(ActiveSupport::Notifications).to receive(:instrument).with('class.bar', 'Foo')
|
205
205
|
|
206
|
-
expect(instance.call(make_env('/hooks/class'))).to eq([200, {}, [
|
206
|
+
expect(instance.call(make_env('/hooks/class'))).to eq([200, {}, ['']])
|
207
207
|
end
|
208
208
|
|
209
209
|
context 'with exception in event callback' do
|
@@ -222,7 +222,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
222
222
|
|
223
223
|
it 'should return a non 200 response' do
|
224
224
|
instance = klass.new(app)
|
225
|
-
expect(instance.call(make_env('/hooks/class'))).to eq([500, {}, [
|
225
|
+
expect(instance.call(make_env('/hooks/class'))).to eq([500, {}, ['']])
|
226
226
|
end
|
227
227
|
end
|
228
228
|
end
|
@@ -242,7 +242,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
242
242
|
it 'should return a success response' do
|
243
243
|
expect(subscriber).to receive(:call).with('Foo')
|
244
244
|
|
245
|
-
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.bar&payload=test')}))).to eq([200, {}, [
|
245
|
+
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.bar&payload=test')}))).to eq([200, {}, ['']])
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
@@ -250,7 +250,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
250
250
|
it 'should return a success response' do
|
251
251
|
expect(subscriber).not_to receive(:call)
|
252
252
|
|
253
|
-
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.sam&payload=test')}))).to eq([200, {}, [
|
253
|
+
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.sam&payload=test')}))).to eq([200, {}, ['']])
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
@@ -260,7 +260,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should return an error response' do
|
263
|
-
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.bar&payload=test')}))).to eq([500, {}, [
|
263
|
+
expect(strategy.call(make_env('/hooks/test', {'rack.input' => StringIO.new('type=foo.bar&payload=test')}))).to eq([500, {}, ['']])
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
@@ -285,7 +285,7 @@ RSpec.describe OmniHooks::Strategy do
|
|
285
285
|
end
|
286
286
|
|
287
287
|
it 'allows a request method of the correct type' do
|
288
|
-
expect(strategy.call(make_env('/hooks/test', 'REQUEST_METHOD' => 'PUT'))).to eq([200, {}, [
|
288
|
+
expect(strategy.call(make_env('/hooks/test', 'REQUEST_METHOD' => 'PUT'))).to eq([200, {}, ['']])
|
289
289
|
end
|
290
290
|
|
291
291
|
after do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnihooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Falconer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
- - "<"
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
36
|
+
version: '3'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.2'
|
44
|
+
- - "<"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '3'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: hashie
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,7 +106,7 @@ dependencies:
|
|
100
106
|
- - "~>"
|
101
107
|
- !ruby/object:Gem::Version
|
102
108
|
version: 3.3.0
|
103
|
-
description:
|
109
|
+
description:
|
104
110
|
email:
|
105
111
|
- karl.falconer@falconerdevelopment.com
|
106
112
|
executables: []
|
@@ -129,7 +135,7 @@ homepage: ''
|
|
129
135
|
licenses:
|
130
136
|
- MIT
|
131
137
|
metadata: {}
|
132
|
-
post_install_message:
|
138
|
+
post_install_message:
|
133
139
|
rdoc_options: []
|
134
140
|
require_paths:
|
135
141
|
- lib
|
@@ -144,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
150
|
- !ruby/object:Gem::Version
|
145
151
|
version: '0'
|
146
152
|
requirements: []
|
147
|
-
|
148
|
-
|
149
|
-
signing_key:
|
153
|
+
rubygems_version: 3.0.6
|
154
|
+
signing_key:
|
150
155
|
specification_version: 4
|
151
156
|
summary: A generalized framework for multiple-provider webhooks subscriptions.
|
152
157
|
test_files:
|