Module: HazWebhooks::Hook

Extended by:
ActiveSupport::Concern
Defined in:
lib/haz_webhooks/hook.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#fire_webhook(key, data = nil) ⇒ Object



43
44
45
46
# File 'lib/haz_webhooks/hook.rb', line 43

def fire_webhook(key, data=nil)
  hook = self.webhooks.event(key).first
  hook.fire(data) if !hook.nil?
end

#set_webhook(key, url) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/haz_webhooks/hook.rb', line 34

def set_webhook(key, url)
  hook = self.webhooks.event(key).first
  if hook.nil?
    self.webhooks.create(:key => key, :active => true, :url => url)
  else
    hook.set(url)
  end
end

#webhook_url(key) ⇒ Object



48
49
50
# File 'lib/haz_webhooks/hook.rb', line 48

def webhook_url(key)
  self.webhooks.event(key).first.try(:url)
end