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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 06339853f7ece3c68f11ba4915da17e824ccb27d
4
- data.tar.gz: 2f4d22b89574c3415920c62daed2fb54c432e213
2
+ SHA256:
3
+ metadata.gz: 1f133f4e912d2bd925d5827a580c67b2971ec8698ef02105a3905f55638f3c17
4
+ data.tar.gz: dc3c1d619c4bdf260ae499928cacafea8b24dd06175114595b8c74c38dffe813
5
5
  SHA512:
6
- metadata.gz: 52b3d2514746e528b4cf60b2adfa88fe2dc511b1c03eac56c15abfa224b19c88fe822daa024005d65cf020805ab3df569937413319ffb825559948bba285ac22
7
- data.tar.gz: c51daa43fbc940543974b40c4d1568c4f62c7be1ab42ef0daa1c1201dfc8cc8e14dabdc3c242d1a1de3c66b53bd533bbbee9c970721768f20d2eae17ac602b62
6
+ metadata.gz: e748a268c94fa4a47fe0cf0b5287c84e63db249f6fef152924f60dc9f1671670840f4b91c5b09076d7fe9f0fbe76cfe283a39e21e8fc2ead865c924c6ac59fbf
7
+ data.tar.gz: 200e5903fa90f7af8f041a81a8e292ba7bac8818dd60d698ea7aa4f2f1e60b9e10a15b4ff1357b5325ebfbabc8dd08ce33f6ad1b779e8ef62a8bc19a87f160c8
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  /spec/examples.txt
16
+ *.sublime-*
@@ -1 +1 @@
1
- ruby-2.1.6
1
+ ruby-2.4.5
data/README.md CHANGED
@@ -1,31 +1,52 @@
1
- # OmniHooks
1
+ # OmniHooks: Standardized Multi-Provider Webhooks
2
2
 
3
- TODO: Write a gem description
3
+ ## Introduction
4
4
 
5
- ## Installation
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
- Add this line to your application's Gemfile:
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
- ```ruby
10
- gem 'omnihooks'
11
- ```
9
+ ## Getting Started
12
10
 
13
- And then execute:
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
- $ bundle
13
+ ````ruby
14
+ require 'sinatra'
15
+ require 'omnihooks'
16
16
 
17
- Or install it yourself as:
17
+ class MyApplication < Sinatra::Base
18
+ use Rack::Session::Cookie
19
+ use OmniHooks::Strategies::Developer
20
+ end
21
+ ````
18
22
 
19
- $ gem install omnihooks
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
- ## Usage
25
+ ````ruby
26
+ require 'sinatra'
27
+ require 'omnihooks'
22
28
 
23
- TODO: Write usage instructions here
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
- ## Contributing
46
+ ## Logging
26
47
 
27
- 1. Fork it ( https://github.com/[my-github-username]/omnihooks/fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
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
@@ -1,2 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
 
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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)
@@ -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
- [500, {}, [nil]]
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, {}, [nil]]
264
+ [200, {}, [EMPTY_STRING]]
263
265
  end
264
266
  end
265
267
 
@@ -1,3 +1,3 @@
1
1
  module OmniHooks
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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', '~> 1.0'
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, {}, [nil]])
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, {}, [nil]])
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, {}, [nil]])
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, {}, [nil]])
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, {}, [nil]])
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, {}, [nil]])
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.1
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: 2015-09-02 00:00:00.000000000 Z
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: '1.0'
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: '1.0'
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
- rubyforge_project:
148
- rubygems_version: 2.4.8
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: