Skip to content

Instantly share code, notes, and snippets.

@bcooksey
bcooksey / contact.rb
Created December 19, 2013 15:28 — forked from endymion/contact.rb
Implementation of our REST Hooks API in ruby
class Contact < ActiveRecord::Base
...
def after_create
if Hook.hooks_exist?('new_contact', self)
Resque.enqueue(Hook, self.class.name, self.id)
# To trigger directly without Resque: Hook.trigger('new_contact', self)
end
end
@bcooksey
bcooksey / hook.rb
Created June 18, 2013 17:07 — forked from endymion/contact.rb
This is the orignal, see the new one
class Hook < ActiveRecord::Base
attr_accessible :event, :account_id, :subscription_url, :target_url
validates_presence_of :event, :account_id, :subscription_url, :target_url
# Looks for an appropriate REST hook that matches the record, and triggers the hook if one exists.
def self.trigger(event, record)
hooks = Hook.find(:all, :conditions => {
:event => event,
:account_id => record.account_id,
})