No release in over 3 years
Low commit activity in last 3 years
Integration of Zapier REST hooks pattern within a Ruby on Rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.3.11, ~> 1.5
>= 4.11.1, ~> 4.11
>= 1.3.1, ~> 1.3
~> 0.59.2
>= 3.1.2, ~> 3.1
>= 1.3.11, ~> 1.3

Runtime

>= 5.1.0, ~> 5.1
 Project Readme

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, based on Ryan Alyn Porter initial solution.

License

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