Class: Waylon::Webhook

Inherits:
Sinatra::Base
  • Object
show all
Includes:
BaseComponent
Defined in:
lib/waylon/webhook.rb

Overview

Base class for Webhooks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

included

Class Method Details

.config_namespaceString

Config namespace for config keys

Returns:

  • (String)

    The namespace for config keys



10
11
12
# File 'lib/waylon/webhook.rb', line 10

def self.config_namespace
  "webhooks.#{component_namespace}"
end

Instance Method Details

#enqueue(content) ⇒ Object

Places the incoming request body onto the Senses queue for processing by workers

Parameters:

  • content (Hash)

    The verified request body



16
17
18
# File 'lib/waylon/webhook.rb', line 16

def enqueue(content)
  Resque.enqueue sense_class, content
end

#sense_classClass

Provides the Sense class that corresponds to this Webhook, with some sensible assumptions

Returns:

  • (Class)

    The name of the corresponding Sense class



22
23
24
25
# File 'lib/waylon/webhook.rb', line 22

def sense_class
  last = self.class.name.split("::").last
  Module.const_get("Waylon::Senses::#{last}")
end

#verify(_payload, _headers) ⇒ Boolean

This must be implemented on every Webhook to provide a mechanism to ensure received payloads are legit

Parameters:

  • _payload (String)

    The raw, unparsed request body

  • _headers (Hash)

    The raw, unparsed request headers as a Hash

Returns:

  • (Boolean)

Raises:



31
32
33
# File 'lib/waylon/webhook.rb', line 31

def verify(_payload, _headers)
  raise GenericException, "Not Implemented"
end