webhookr 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +1937 -0
  3. data/.travis.yml +8 -8
  4. data/Gemfile +12 -15
  5. data/Guardfile +12 -15
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +8 -7
  8. data/Rakefile +3 -3
  9. data/app/controllers/webhookr/events_controller.rb +23 -16
  10. data/config/routes.rb +9 -8
  11. data/lib/generators/webhookr/add_route_generator.rb +4 -4
  12. data/lib/generators/webhookr/init_generator.rb +14 -12
  13. data/lib/tasks/webhookr_tasks.rake +7 -7
  14. data/lib/webhookr.rb +13 -6
  15. data/lib/webhookr/adapter_response.rb +3 -1
  16. data/lib/webhookr/engine.rb +5 -4
  17. data/lib/webhookr/invalid_payload_error.rb +8 -2
  18. data/lib/webhookr/invalid_security_token_error.rb +3 -1
  19. data/lib/webhookr/invalid_service_name_error.rb +9 -0
  20. data/lib/webhookr/missing_callback_class_error.rb +9 -0
  21. data/lib/webhookr/ostruct_utils.rb +19 -19
  22. data/lib/webhookr/service.rb +28 -24
  23. data/lib/webhookr/services.rb +1 -1
  24. data/lib/webhookr/services/adapter.rb +1 -1
  25. data/lib/webhookr/services/adapter/base.rb +2 -2
  26. data/lib/webhookr/version.rb +3 -1
  27. data/test/dummy/Rakefile +0 -1
  28. data/test/dummy/app/controllers/application_controller.rb +2 -0
  29. data/test/dummy/app/helpers/application_helper.rb +2 -0
  30. data/test/dummy/config.ru +1 -1
  31. data/test/dummy/config/application.rb +8 -8
  32. data/test/dummy/config/boot.rb +4 -1
  33. data/test/dummy/config/environment.rb +2 -0
  34. data/test/dummy/config/environments/development.rb +2 -1
  35. data/test/dummy/config/environments/production.rb +2 -1
  36. data/test/dummy/config/environments/test.rb +5 -4
  37. data/test/dummy/config/initializers/backtrace_silencers.rb +2 -0
  38. data/test/dummy/config/initializers/inflections.rb +2 -0
  39. data/test/dummy/config/initializers/mime_types.rb +2 -0
  40. data/test/dummy/config/initializers/secret_token.rb +3 -1
  41. data/test/dummy/config/initializers/session_store.rb +3 -1
  42. data/test/dummy/config/initializers/webhookr.rb +3 -1
  43. data/test/dummy/config/initializers/wrap_parameters.rb +3 -2
  44. data/test/dummy/config/routes.rb +3 -1
  45. data/test/dummy/script/rails +2 -2
  46. data/test/functional/webhookr/events_controller_test.rb +38 -42
  47. data/test/functional/webhookr/events_routes_test.rb +22 -15
  48. data/test/functional/webhookr/service_test.rb +53 -48
  49. data/test/integration/webhookr/add_route_generator_test.rb +5 -4
  50. data/test/integration/webhookr/init_generator_test.rb +7 -6
  51. data/test/stubs/service_under_test_stubs.rb +26 -33
  52. data/test/test_helper.rb +10 -9
  53. data/test/unit/webhookr/adapter_response_test.rb +7 -6
  54. data/test/unit/webhookr/ostruct_utils_test.rb +14 -14
  55. data/test/unit/webhookr/{Services/ServiceUnderTest → services/service_under_test}/adapter_test.rb +14 -14
  56. data/test/webhookr_test.rb +5 -3
  57. data/webhookr.gemspec +3 -4
  58. metadata +24 -27
@@ -1,13 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.3"
4
- - "2.0.0"
5
- - jruby-19mode # JRuby in 1.9 mode
6
- - ruby-head
3
+ - 2.5.0
4
+ - 2.4.3
5
+ - 2.3.6
6
+ - 2.2.9
7
+ - jruby
7
8
  env:
8
- - RAILS_VERSION=4.0.0
9
- - RAILS_VERSION=3.2.13
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: ruby-head
13
+ - rvm: jruby
data/Gemfile CHANGED
@@ -1,21 +1,18 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem "rake", "~> 10.0"
7
- gem "minitest"
8
- gem "minitest-reporters"
9
- gem "em-websocket"
10
- gem "guard"
11
- gem "guard-minitest"
12
- gem "guard-markdown"
13
- gem "guard-livereload"
14
- gem "simplecov", :require => false
15
- gem 'coveralls', :require => false
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', :test_folders => 'test', :test_file_patterns => '*_test.rb' do
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$|) { "test" }
4
+ watch(%r|^test/stubs/(.+)\.rb$|) { 'test' }
5
5
 
6
6
  # Rails
7
- watch(%r{^app/models/(.+)\.rb$}) { |m|
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$}) { |m|
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
- ["test/functional", "test/integration"]
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', :convert_on_start => true do
25
- watch ('README.md') { "./README.md|./README.html" }
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')
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 2167961 Ontario Inc., Zoocasa <code@zoocasa.com>
1
+ Copyright (c) 2012-2017 J Smith <dark.panda@gmail.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # webhookr: Rails Webhooks Made Easy
2
- [![Build Status](https://travis-ci.org/zoocasa/webhookr.png?branch=master)](https://travis-ci.org/zoocasa/webhookr)
3
- [![Dependency Status](https://gemnasium.com/zoocasa/webhookr.png)](https://gemnasium.com/zoocasa/webhookr)
4
- [![Code Climate](https://codeclimate.com/github/zoocasa/webhookr.png)](https://codeclimate.com/github/zoocasa/webhookr)
5
- [![Coverage Status](https://coveralls.io/repos/zoocasa/webhookr/badge.png?branch=master)](https://coveralls.io/r/zoocasa/webhookr?branch=master)
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/zoocasa/webhookr-mailchimp).
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/zoocasa/webhookr-mailchimp)
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
- ## Author
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
- $:.push File.expand_path(File.dirname(__FILE__), 'lib')
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 :all => [:install, :test_versions]
42
+ task all: [:install, :test_versions]
43
43
  end
44
44
  end
45
45
 
46
- task :default => :test
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
- http_basic_authenticate_with(
4
- :name => Webhookr.config.basic_auth.username,
5
- :password => Webhookr.config.basic_auth.password
6
- ) if Webhookr.config.basic_auth.username && Webhookr.config.basic_auth.password
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
- before_filter :create_service
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 :nothing => true
19
+ render body: nil
12
20
  end
13
21
 
14
22
  def create
15
23
  @service.process!
16
- render :nothing => true
24
+ render body: nil
17
25
  end
18
26
 
19
27
  private
20
28
 
21
- def create_service
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], :payload => request.body.read, :security_token => params[:security_token]
34
+ params[:service_id],
35
+ payload: request.body.read,
36
+ security_token: params[:security_token]
28
37
  )
29
- rescue NameError => e
30
- raise ActionController::RoutingError.new("No service '#{params[:service_id]}' is available.")
31
- rescue Webhookr::InvalidSecurityTokenError => e
32
- raise ActionController::InvalidAuthenticityToken.new("Invalid or missing security token for service '#{params[:service_id]}'.")
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
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Webhookr::Engine.routes.draw do
2
- get "/events/:service_id(/:security_token)" => "events#show",
3
- :as => "events",
4
- :defaults => { :format => 'json' },
5
- :constraints => { :format => 'json' }
6
- post "/events/:service_id(/:security_token)" => "events#create",
7
- :as => "new_event",
8
- :defaults => { :format => 'json' },
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", :as => "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
- # Webhookr.config.basic_auth.username = "admin"
18
- # Webhookr.config.basic_auth.password = "password"
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
- def generate_security_token
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
- puts "No webhookr services configured - add and configure webhookr plugins." and next if Webhookr.adapters.empty?
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.each do |key, adapter|
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, :security_token => Webhookr.config[key].try(:security_token))}\n"
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
@@ -1,10 +1,15 @@
1
- require "securecompare"
2
- require "webhookr/engine"
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) ? Rails.application.config.webhookr :
19
- ActiveSupport::OrderedOptions.new
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 "webhookr/services"
25
-
32
+ require 'webhookr/services'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webhookr
2
4
  class AdapterResponse < Struct.new(:service_name, :event_type, :payload); end
3
- end
5
+ end
@@ -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
- self.config.webhookr = ActiveSupport::OrderedOptions.new
10
- self.config.webhookr.basic_auth = ActiveSupport::OrderedOptions.new
11
+ config.webhookr = ActiveSupport::OrderedOptions.new
12
+ config.webhookr.basic_auth = ActiveSupport::OrderedOptions.new
11
13
 
12
- initializer "webhookr.config" do |app|
14
+ initializer 'webhookr.config' do |app|
13
15
  end
14
16
  end
15
17
  end
16
-
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webhookr
2
- class InvalidPayloadError < RuntimeError; end
3
- end
4
+ class InvalidPayloadError < RuntimeError
5
+ def initialize(payload)
6
+ super("'#{payload.inspect}' is not valid")
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Webhookr
2
4
  class InvalidSecurityTokenError < RuntimeError; end
3
- end
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webhookr
4
+ class InvalidServiceNameError < NameError
5
+ def initialize(service_name)
6
+ super(%{Bad service name "#{service_name}"})
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webhookr
4
+ class MissingCallbackClassError < RuntimeError
5
+ def initialize(service_name)
6
+ super(%{No callback is configured for the service "#{service_name}".})
7
+ end
8
+ end
9
+ end