Giter Site home page Giter Site logo

rin-tin-tin's Introduction

RinTinTin

Circle CI

"It's the hook that brings you BAAAAACK."

IMAGE ALT TEXT HERE

Under Development

This is not yet available on Rubygems.org as it's not complete. Although the functionality that is works well.

What does it do?

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"
}

Installation

gem "rin-tin-tin", github: "Storenvy/rin-tin-tin", require: 'rin_tin_tin'

Usage

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.

Find and work jobs

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

Dependencies

  • 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.

TODO

  • 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::Notifications 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.