This is not yet available on Rubygems.org as it's not complete. Although the functionality that is works well.
Receiving webhooks is a delicate thing. Sometimes webhooks contain vital data and event notifications that are a must-have to keep your app's business logic in sync with the rest of your integration partners. But sometimes we drop the ball on these webhooks because our app has an exception while we're handling it or something else unexpected.
RinTinTin saves inbound webhooks to an ActiveModel-based Redis store for processing later.
RinTinTin::Webhoook.all.first.attributes =>
{
"id"=>333, # An auto-incrementing ID in Redis.
"sender"=>"PayPal", # The sender of the webhoook based on the url you define (e.g. "/hooks/PayPal")
"headers"=> { # The headers pulled from the request.
"Content-Type" => "application/json"
},
"body"=> {
"event-name" => "shipped"
},
"timestamp"=> "2015-04-22T12:00:44-07:00", # Currently a string. This will be a `DateTime` object in a later version.
"referrer"=> nil, # The HTTP referrer of the request.
"method"=> "POST"
}
gem "rin-tin-tin", github: "Storenvy/rin-tin-tin", require: 'rin_tin_tin'
In your app's route file:
mount RinTinTin::Engine, at: '/hooks'
You can specify any route you'd like for the engine. I chose "/hooks" because it's short.
Now you can send webhooks to any url after '/hooks' such as http://yourapp.com/hooks/PayPal. The receiver will be "PayPal" on these webhooks. The server will response with an empty body and a 200 OK
status, if the webhook was saved. If not, you'll get a 422 Unprocessible Entity
status.
RinTinTin::Webhook.all.each do |webhook|
# Process your webhook
if webhook.sender == 'PayPal' # <- Based on the URL you created, remember?
# Do important stuff.
# ...
# Then dismiss it when you're done.
webhook.destroy
end
end
- Ruby on Rails (Tested with Rails 3.2.14)
- Redis
- Currently relies heavily on redis-persistence but will not require this dependency in a later version.
- Create Worker class that your app's workers can inherit from for processing.
- Cast timestamps as DateTime objects.
- Allow your app to define callbacks for certain webhoook "senders". Callback usage could include enqueing a Resque job for processing the webhook.
- Fire
ActiveSupport::Notification
s during creation and deletion. - Create another key for storing processed webhooks for reference later.
- Build authenticated UI for browsing webhooks like resque-web.
- Remove redis-persistence.