Metova::Webhooks
Easily add webhooks to your Rails app.
Installation
Add this line to your application's Gemfile:
gem 'metova-webhooks'
And then execute:
$ bundle
Or install it yourself as:
$ gem install metova-webhooks
Then install the migrations:
$ rake metova-webhooks:install:migrations
And migrate:
$ rake db:migrate
Notes
Webhooks requires a 'User' model and ActiveJob, so make sure you have those things.
Usage
In your webhookable model, include Metova::Webhookable
:
class MyModel
include Metova::Webhookable
def namespace
''
end
def hook_name
self.class.to_s.underscore
end
def webhook_event(event)
[namespace, hook_name, event].reject(&:empty?).join(':')
end
def webhook_serialize
self.to_json
end
end
Include Metova::WebhooksBase
in a controller:
class MyWebhooksController < ActionController::Base
include Metova::WebhooksBase
def create
super do |webhook|
webhook.errors.add :user, "is not allowed to make webhooks" if some_condition
end
end
protected
def current_user
nil
end
end
Add routes to your config/routes.rb
:
resources :webhooks, only: [:index, :create, :destroy]
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/metova/metova-webhooks.
License
The gem is available as open source under the terms of the MIT License.