webhookr 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +1937 -0
- data/.travis.yml +8 -8
- data/Gemfile +12 -15
- data/Guardfile +12 -15
- data/MIT-LICENSE +1 -1
- data/README.md +8 -7
- data/Rakefile +3 -3
- data/app/controllers/webhookr/events_controller.rb +23 -16
- data/config/routes.rb +9 -8
- data/lib/generators/webhookr/add_route_generator.rb +4 -4
- data/lib/generators/webhookr/init_generator.rb +14 -12
- data/lib/tasks/webhookr_tasks.rake +7 -7
- data/lib/webhookr.rb +13 -6
- data/lib/webhookr/adapter_response.rb +3 -1
- data/lib/webhookr/engine.rb +5 -4
- data/lib/webhookr/invalid_payload_error.rb +8 -2
- data/lib/webhookr/invalid_security_token_error.rb +3 -1
- data/lib/webhookr/invalid_service_name_error.rb +9 -0
- data/lib/webhookr/missing_callback_class_error.rb +9 -0
- data/lib/webhookr/ostruct_utils.rb +19 -19
- data/lib/webhookr/service.rb +28 -24
- data/lib/webhookr/services.rb +1 -1
- data/lib/webhookr/services/adapter.rb +1 -1
- data/lib/webhookr/services/adapter/base.rb +2 -2
- data/lib/webhookr/version.rb +3 -1
- data/test/dummy/Rakefile +0 -1
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +8 -8
- data/test/dummy/config/boot.rb +4 -1
- data/test/dummy/config/environment.rb +2 -0
- data/test/dummy/config/environments/development.rb +2 -1
- data/test/dummy/config/environments/production.rb +2 -1
- data/test/dummy/config/environments/test.rb +5 -4
- data/test/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/test/dummy/config/initializers/inflections.rb +2 -0
- data/test/dummy/config/initializers/mime_types.rb +2 -0
- data/test/dummy/config/initializers/secret_token.rb +3 -1
- data/test/dummy/config/initializers/session_store.rb +3 -1
- data/test/dummy/config/initializers/webhookr.rb +3 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +3 -2
- data/test/dummy/config/routes.rb +3 -1
- data/test/dummy/script/rails +2 -2
- data/test/functional/webhookr/events_controller_test.rb +38 -42
- data/test/functional/webhookr/events_routes_test.rb +22 -15
- data/test/functional/webhookr/service_test.rb +53 -48
- data/test/integration/webhookr/add_route_generator_test.rb +5 -4
- data/test/integration/webhookr/init_generator_test.rb +7 -6
- data/test/stubs/service_under_test_stubs.rb +26 -33
- data/test/test_helper.rb +10 -9
- data/test/unit/webhookr/adapter_response_test.rb +7 -6
- data/test/unit/webhookr/ostruct_utils_test.rb +14 -14
- data/test/unit/webhookr/{Services/ServiceUnderTest → services/service_under_test}/adapter_test.rb +14 -14
- data/test/webhookr_test.rb +5 -3
- data/webhookr.gemspec +3 -4
- metadata +24 -27
data/.travis.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
3
|
+
- 2.5.0
|
4
|
+
- 2.4.3
|
5
|
+
- 2.3.6
|
6
|
+
- 2.2.9
|
7
|
+
- jruby
|
7
8
|
env:
|
8
|
-
- RAILS_VERSION=
|
9
|
-
- RAILS_VERSION=
|
10
|
-
- RAILS_VERSION=3.1.12
|
9
|
+
- RAILS_VERSION=5.1
|
10
|
+
- RAILS_VERSION=4.2
|
11
11
|
matrix:
|
12
12
|
allow_failures:
|
13
|
-
- rvm:
|
13
|
+
- rvm: jruby
|
data/Gemfile
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
15
|
-
gem '
|
16
|
-
end
|
17
|
-
|
18
|
-
if File.exists?('Gemfile.local')
|
19
|
-
instance_eval File.read('Gemfile.local')
|
6
|
+
gem 'coveralls', require: false
|
7
|
+
gem 'em-websocket'
|
8
|
+
gem 'guard'
|
9
|
+
gem 'guard-livereload'
|
10
|
+
gem 'guard-markdown'
|
11
|
+
gem 'guard-minitest'
|
12
|
+
gem 'minitest'
|
13
|
+
gem 'minitest-reporters'
|
14
|
+
gem 'rake', '~> 10.0'
|
15
|
+
gem 'simplecov', require: false
|
20
16
|
end
|
21
17
|
|
18
|
+
instance_eval File.read('Gemfile.local') if File.exist?('Gemfile.local')
|
data/Guardfile
CHANGED
@@ -1,31 +1,28 @@
|
|
1
1
|
|
2
|
-
guard 'minitest', :
|
2
|
+
guard 'minitest', test_folders: 'test', test_file_patterns: '*_test.rb' do
|
3
3
|
watch(%r|^test/(.+)_test\.rb|)
|
4
|
-
watch(%r|^test/stubs/(.+)\.rb$|) {
|
4
|
+
watch(%r|^test/stubs/(.+)\.rb$|) { 'test' }
|
5
5
|
|
6
6
|
# Rails
|
7
|
-
watch(%r{^app/models/(.+)\.rb$})
|
7
|
+
watch(%r{^app/models/(.+)\.rb$}) do |m|
|
8
8
|
"test/unit/#{m[1]}_test.rb"
|
9
|
-
|
9
|
+
end
|
10
10
|
|
11
|
-
watch(%r{^app/controllers/(.+)\.rb$})
|
11
|
+
watch(%r{^app/controllers/(.+)\.rb$}) do |m|
|
12
12
|
"test/functional/#{m[1]}_test.rb"
|
13
|
-
|
13
|
+
end
|
14
14
|
|
15
|
-
watch('config/routes.rb')
|
16
|
-
[
|
17
|
-
|
15
|
+
watch('config/routes.rb') do
|
16
|
+
['test/functional', 'test/integration']
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
guard 'livereload' do
|
21
21
|
watch('README.html')
|
22
22
|
end
|
23
23
|
|
24
|
-
guard 'markdown', :
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
if File.exists?('Guardfile.local')
|
29
|
-
instance_eval File.read('Guardfile.local')
|
24
|
+
guard 'markdown', convert_on_start: true do
|
25
|
+
watch('README.md') { './README.md|./README.html' }
|
30
26
|
end
|
31
27
|
|
28
|
+
instance_eval File.read('Guardfile.local') if File.exist?('Guardfile.local')
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# webhookr: Rails Webhooks Made Easy
|
2
|
-
[![Build Status](https://travis-ci.org/
|
3
|
-
[![Dependency Status](https://gemnasium.com/
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
-
[![Coverage Status](https://coveralls.io/repos/
|
2
|
+
[![Build Status](https://travis-ci.org/dark-panda/webhookr.png?branch=master)](https://travis-ci.org/dark-panda/webhookr)
|
3
|
+
[![Dependency Status](https://gemnasium.com/dark-panda/webhookr.png)](https://gemnasium.com/dark-panda/webhookr)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/dark-panda/webhookr.png)](https://codeclimate.com/github/dark-panda/webhookr)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/dark-panda/webhookr/badge.png?branch=master)](https://coveralls.io/r/dark-panda/webhookr?branch=master)
|
6
6
|
|
7
7
|
## <a name="introduction"></a>Introduction
|
8
8
|
|
@@ -59,7 +59,7 @@ end
|
|
59
59
|
## <a name="usage"></a>Usage & Setup
|
60
60
|
|
61
61
|
webhookr works with Rails 3.1 onwards. It generally requires a plugin to be
|
62
|
-
useful, such as the [MailChimp plugin](https://github.com/
|
62
|
+
useful, such as the [MailChimp plugin](https://github.com/dark-panda/webhookr-mailchimp).
|
63
63
|
|
64
64
|
## Setup
|
65
65
|
|
@@ -130,9 +130,10 @@ If you are sending sensitive data via webhooks, it is recommended you use HTTPS.
|
|
130
130
|
|
131
131
|
### <a name="supported_services"></a>Supported Services
|
132
132
|
|
133
|
-
* MailChimp - [webhookr-mail_chimp](https://github.com/
|
133
|
+
* MailChimp - [webhookr-mail_chimp](https://github.com/dark-panda/webhookr-mailchimp)
|
134
134
|
* Mandrill - [webhookr-mandrill](https://github.com/gerrypower/webhookr-mandrill)
|
135
135
|
* Stripe - [webhookr-stripe](https://github.com/gerrypower/webhookr-stripe)
|
136
|
+
* Recurly - [webhookr-recurly](https://github.com/tfe/webhookr-recurly)
|
136
137
|
* Github - coming soon
|
137
138
|
|
138
139
|
## <a name="works_with"></a>Works with:
|
@@ -169,7 +170,7 @@ While this gem is currently a 0.x release, suggestion is to require the exact ve
|
|
169
170
|
|
170
171
|
webhookr is released under the [MIT license](http://www.opensource.org/licenses/MIT).
|
171
172
|
|
172
|
-
##
|
173
|
+
## Authors
|
173
174
|
|
174
175
|
* [Gerry Power](https://github.com/gerrypower)
|
175
176
|
* [J Smith](https://github.com/dark-panda)
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
|
|
7
7
|
require 'rdoc/task'
|
8
8
|
require 'bundler/gem_tasks'
|
9
9
|
|
10
|
-
|
10
|
+
$LOAD_PATH.push File.expand_path(File.dirname(__FILE__), 'lib')
|
11
11
|
|
12
12
|
version = Webhookr::VERSION
|
13
13
|
|
@@ -39,8 +39,8 @@ namespace :webhookr do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
desc 'Install and test all'
|
42
|
-
task :
|
42
|
+
task all: [:install, :test_versions]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
task :
|
46
|
+
task default: :test
|
@@ -1,37 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webhookr
|
2
4
|
class EventsController < ActionController::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
if Webhookr.config.basic_auth.username && Webhookr.config.basic_auth.password
|
6
|
+
http_basic_authenticate_with(
|
7
|
+
name: Webhookr.config.basic_auth.username,
|
8
|
+
password: Webhookr.config.basic_auth.password
|
9
|
+
)
|
10
|
+
end
|
7
11
|
|
8
|
-
|
12
|
+
if respond_to?(:before_action)
|
13
|
+
before_action :create_service
|
14
|
+
else
|
15
|
+
before_filter :create_service
|
16
|
+
end
|
9
17
|
|
10
18
|
def show
|
11
|
-
render :
|
19
|
+
render body: nil
|
12
20
|
end
|
13
21
|
|
14
22
|
def create
|
15
23
|
@service.process!
|
16
|
-
render :
|
24
|
+
render body: nil
|
17
25
|
end
|
18
26
|
|
19
27
|
private
|
20
28
|
|
21
|
-
|
22
|
-
begin
|
29
|
+
def create_service
|
23
30
|
# Rails 4.0.0 fix: https://github.com/rails/rails/pull/11353
|
24
31
|
request.body.rewind
|
25
32
|
|
26
33
|
@service = Webhookr::Service.new(
|
27
|
-
params[:service_id],
|
34
|
+
params[:service_id],
|
35
|
+
payload: request.body.read,
|
36
|
+
security_token: params[:security_token]
|
28
37
|
)
|
29
|
-
rescue
|
30
|
-
raise ActionController::RoutingError
|
31
|
-
rescue Webhookr::InvalidSecurityTokenError
|
32
|
-
raise ActionController::InvalidAuthenticityToken
|
38
|
+
rescue Webhookr::InvalidServiceNameError
|
39
|
+
raise ActionController::RoutingError, "No service '#{params[:service_id]}' is available."
|
40
|
+
rescue Webhookr::InvalidSecurityTokenError
|
41
|
+
raise ActionController::InvalidAuthenticityToken, "Invalid or missing security token for service '#{params[:service_id]}'."
|
33
42
|
end
|
34
|
-
end
|
35
|
-
|
36
43
|
end
|
37
44
|
end
|
data/config/routes.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Webhookr::Engine.routes.draw do
|
2
|
-
get
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
post
|
7
|
-
|
8
|
-
|
9
|
-
:constraints => { :format => 'json' }
|
4
|
+
get '/events/:service_id(/:security_token)' => 'events#show',
|
5
|
+
as: 'events',
|
6
|
+
defaults: { format: 'json' }
|
7
|
+
|
8
|
+
post '/events/:service_id(/:security_token)' => 'events#create',
|
9
|
+
as: 'new_event',
|
10
|
+
defaults: { format: 'json' }
|
10
11
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webhookr
|
2
4
|
module Generators
|
3
5
|
class AddRouteGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
desc 'This generator adds \'mount Webhookr::Engine => "/webhookr", :as => "webhookr"\' to your routes'
|
6
|
+
desc 'This generator adds \'mount Webhookr::Engine => "/webhookr", as: "webhookr"\' to your routes'
|
6
7
|
def add_route
|
7
|
-
route 'mount Webhookr::Engine => "/webhookr", :
|
8
|
+
route 'mount Webhookr::Engine => "/webhookr", as: "webhookr"'
|
8
9
|
end
|
9
|
-
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -1,30 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Webhookr
|
2
4
|
module Generators
|
3
5
|
class InitGenerator < Rails::Generators::NamedBase
|
4
|
-
|
5
6
|
desc "This generator creates an initializer file 'config/initializers/NAME.rb'"
|
6
7
|
def init
|
7
8
|
initializer("#{file_name}.rb") do
|
8
|
-
file_contents
|
9
|
+
file_contents.strip_heredoc
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
13
|
def file_contents
|
13
|
-
<<-eos
|
14
|
-
# Webhookr Initializer
|
14
|
+
<<-eos
|
15
|
+
# Webhookr Initializer
|
15
16
|
|
16
|
-
## Turn on http basic authentication for all plugins
|
17
|
-
|
18
|
-
|
17
|
+
## Turn on http basic authentication for all plugins
|
18
|
+
# Webhookr.config.basic_auth.username = "admin"
|
19
|
+
# Webhookr.config.basic_auth.password = "password"
|
19
20
|
|
20
|
-
## Plugin Initializers go here ##
|
21
|
-
eos
|
21
|
+
## Plugin Initializers go here ##
|
22
|
+
eos
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
rand(10000000000000000).floor.to_s(36)
|
26
|
-
end
|
25
|
+
private
|
27
26
|
|
27
|
+
def generate_security_token
|
28
|
+
SecureRandom.hex(32)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
namespace :webhookr do
|
2
|
-
desc "List the configured services and paths"
|
3
|
-
task :services => :environment do
|
4
1
|
|
5
|
-
|
2
|
+
namespace :webhookr do
|
3
|
+
desc 'List the configured services and paths'
|
4
|
+
task services: :environment do
|
5
|
+
puts 'No webhookr services configured - add and configure webhookr plugins.' and next if Webhookr.adapters.empty?
|
6
6
|
|
7
7
|
include Webhookr::Engine.routes.url_helpers
|
8
8
|
|
9
|
-
Webhookr.adapters.
|
9
|
+
Webhookr.adapters.each_key do |key|
|
10
10
|
puts "\n\n#{key}:"
|
11
|
-
%w{ GET POST}.each do |x|
|
12
|
-
puts " #{x}\t#{events_path(key, :
|
11
|
+
%w{ GET POST }.each do |x|
|
12
|
+
puts " #{x}\t#{events_path(key, security_token: Webhookr.config[key].try(:security_token))}\n"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/webhookr.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securecompare'
|
4
|
+
require 'webhookr/engine'
|
3
5
|
|
4
6
|
module Webhookr
|
5
7
|
extend ActiveSupport::Autoload
|
6
8
|
|
7
9
|
autoload :InvalidPayloadError
|
10
|
+
autoload :InvalidSecurityTokenError
|
11
|
+
autoload :InvalidServiceNameError
|
12
|
+
autoload :MissingCallbackClassError
|
8
13
|
autoload :AdapterResponse
|
9
14
|
autoload :Service
|
10
15
|
autoload :VERSION
|
@@ -15,11 +20,13 @@ module Webhookr
|
|
15
20
|
end
|
16
21
|
|
17
22
|
def config
|
18
|
-
@config ||= defined?(Rails)
|
19
|
-
|
23
|
+
@config ||= if defined?(Rails)
|
24
|
+
Rails.application.config.webhookr
|
25
|
+
else
|
26
|
+
ActiveSupport::OrderedOptions.new
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
|
-
require
|
25
|
-
|
32
|
+
require 'webhookr/services'
|
data/lib/webhookr/engine.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/kernel/singleton_class'
|
2
4
|
|
3
5
|
module Webhookr
|
@@ -6,11 +8,10 @@ module Webhookr
|
|
6
8
|
|
7
9
|
# Enable basic auth for all services when config.basic_auth.username
|
8
10
|
# and config.basic_auth.password are set.
|
9
|
-
|
10
|
-
|
11
|
+
config.webhookr = ActiveSupport::OrderedOptions.new
|
12
|
+
config.webhookr.basic_auth = ActiveSupport::OrderedOptions.new
|
11
13
|
|
12
|
-
initializer
|
14
|
+
initializer 'webhookr.config' do |app|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
16
|
-
|