Giter Site home page Giter Site logo

pombredanne / zapier-rest-hooks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esbanarango/zapier-rest-hooks

0.0 1.0 0.0 59 KB

Rails engine that provides all the functionality/structure for Zapier REST hooks pattern.

License: MIT License

Ruby 88.48% HTML 11.52%

zapier-rest-hooks's Introduction

ZapierRestHooks

Gem Version Build Status Code Climate Test Coverage

Rails engine that provides functionality for Zapier REST hooks pattern.

Installation

Add this line to your application's Gemfile:

gem 'zapier_rest_hooks'

After you've added ZapierRestHooks to your gemfile, you can install it with:

rails generate zapier_rest_hooks:install

The generator will mount ZapierRestHooks in your config/routes.rb at the path /hooks.

Now run rake db:migrate

Usage

By adding ZapierRestHooks engine to your Rails app, you will have access to ZapierRestHooks::Hook model. This model maps the Hook object described on Zapier REST Hooks pattern.

Here's an example on how you can integrate hooks into your existing models.

Note:

This is simple example, in real life you should wrap ZapierRestHooks::Hook.trigger inside a Job.

A hook can be scoped to an owner. By default it's nil but you can specify it if you need it.

class Candidate < ActiveRecord::Base
  # Relations
  belongs_to :organization

  # Callbacks
  after_create :trigger_hooks_with_owner, if: :organization
  after_create :trigger_hooks_without_owner, unless: :organization

  private

  def trigger_hooks_with_owner
    return unless ZapierRestHooks::Hook.hooks_exist?('new_candidate', organization)
    # Scoped event.
    ZapierRestHooks::Hook.trigger('new_candidate', self.to_json, organization)
  end

  def trigger_hooks_without_owner
    return unless ZapierRestHooks::Hook.hooks_exist?('new_candidate')
    # Global event.
    ZapierRestHooks::Hook.trigger('new_candidate', self.to_json)
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/esbanarango/zapier-REST-hooks. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Author

This was written by Esteban Arango Medina while working at Interviewed, based on Ryan Alyn Porter initial solution.

License

The gem is available as open source under the terms of the MIT License.

zapier-rest-hooks's People

Contributors

esbanarango avatar

Watchers

 avatar

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.