Module: Hooksmith

Defined in:
lib/hooksmith.rb,
lib/hooksmith/errors.rb,
lib/hooksmith/logger.rb,
lib/hooksmith/railtie.rb,
lib/hooksmith/request.rb,
lib/hooksmith/version.rb,
lib/hooksmith/dispatcher.rb,
lib/hooksmith/idempotency.rb,
lib/hooksmith/configuration.rb,
lib/hooksmith/event_recorder.rb,
lib/hooksmith/processor/base.rb,
lib/hooksmith/verifiers/base.rb,
lib/hooksmith/verifiers/hmac.rb,
lib/hooksmith/config/provider.rb,
lib/hooksmith/instrumentation.rb,
lib/hooksmith/config/event_store.rb,
lib/hooksmith/jobs/dispatcher_job.rb,
lib/hooksmith/verifiers/bearer_token.rb,
lib/hooksmith/rails/webhooks_controller.rb

Overview

Provides a DSL for registering webhook processors by provider and event.

Defined Under Namespace

Modules: Config, EventRecorder, Idempotency, Instrumentation, Jobs, Processor, Rails, Verifiers Classes: Configuration, ConfigurationError, Dispatcher, Error, InvalidPayloadError, Logger, MultipleProcessorsError, NoProcessorError, PersistenceError, ProcessorError, Railtie, Request, UnknownEventError, VerificationError

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Returns the configuration instance.

Returns:



55
56
57
# File 'lib/hooksmith.rb', line 55

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields the configuration to a block.

Yield Parameters:



61
62
63
# File 'lib/hooksmith.rb', line 61

def self.configure
  yield(configuration)
end

.loggerLogger

Returns the gem's logger instance.

Returns:

  • (Logger)

    the logger instance.



67
68
69
# File 'lib/hooksmith.rb', line 67

def self.logger
  Logger.instance
end

.verifier_configured?(provider) ⇒ Boolean

Checks if a provider has a verifier configured.

Parameters:

  • provider (Symbol, String)

    the provider name

Returns:

  • (Boolean)

    true if a verifier is configured



88
89
90
91
# File 'lib/hooksmith.rb', line 88

def self.verifier_configured?(provider)
  verifier = configuration.verifier_for(provider)
  verifier&.enabled? || false
end

.verify!(provider:, request:) ⇒ void

This method returns an undefined value.

Verifies an incoming webhook request for a provider.

Parameters:

  • provider (Symbol, String)

    the provider name

  • request (Hooksmith::Request)

    the incoming request

Raises:



77
78
79
80
81
82
# File 'lib/hooksmith.rb', line 77

def self.verify!(provider:, request:)
  verifier = configuration.verifier_for(provider)
  return unless verifier&.enabled?

  verifier.verify!(request)
end