Class: Hooks::Plugins::Handlers::Base

Inherits:
Object
  • Object
show all
Includes:
Core::ComponentAccess
Defined in:
lib/hooks/plugins/handlers/base.rb

Overview

Base class for all webhook handlers

All custom handlers must inherit from this class and implement the #call method

Direct Known Subclasses

DefaultHandler

Instance Method Summary collapse

Methods included from Core::ComponentAccess

#failbot, #log, #method_missing, #respond_to_missing?, #stats

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hooks::Core::ComponentAccess

Instance Method Details

#call(payload:, headers:, env:, config:) ⇒ Hash, ...

Process a webhook request

Parameters:

  • payload (Hash, String)

    Parsed request body (JSON Hash) or raw string

  • headers (Hash)

    HTTP headers (string keys, optionally normalized - default is normalized)

  • env (Hash)

    Rack environment (contains the request context, headers, etc - very rich context)

  • config (Hash)

    Merged endpoint configuration including opts section (symbolized keys)

Returns:

  • (Hash, String, nil)

    Response body (will be auto-converted to JSON)

Raises:

  • (NotImplementedError)

    if not implemented by subclass



24
25
26
# File 'lib/hooks/plugins/handlers/base.rb', line 24

def call(payload:, headers:, env:, config:)
  raise NotImplementedError, "Handler must implement #call method"
end

#error!(body, status = 500) ⇒ Object

Terminate request processing with a custom error response

This method provides the same interface as Grape’s ‘error!` method, allowing handlers to immediately stop processing and return a specific error response to the client.

Examples:

Return a custom error with status 400

error!({ error: "validation_failed", message: "Invalid payload" }, 400)

Return a simple string error with status 401

error!("Unauthorized", 401)

Return an error with default 500 status

error!({ error: "internal_error", message: "Something went wrong" })

Parameters:

  • body (Object)

    The error body/data to return to the client

  • status (Integer) (defaults to: 500)

    The HTTP status code to return (default: 500)

Raises:



46
47
48
# File 'lib/hooks/plugins/handlers/base.rb', line 46

def error!(body, status = 500)
  raise Error.new(body, status)
end