Class: Hooksmith::Config::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/hooksmith/config/provider.rb

Overview

Provider is used internally by the DSL to collect processor registrations, optional verifier configuration, and idempotency settings.

Uses string keys internally to prevent Symbol DoS attacks when processing untrusted webhook input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ Provider

Returns a new instance of Provider.



31
32
33
34
35
36
# File 'lib/hooksmith/config/provider.rb', line 31

def initialize(provider)
  @provider = provider.to_s
  @entries = []
  @verifier = nil
  @idempotency_key = nil
end

Instance Attribute Details

#entriesArray<Hash> (readonly)

Returns list of entries registered.

Returns:

  • (Array<Hash>)

    list of entries registered.



14
15
16
# File 'lib/hooksmith/config/provider.rb', line 14

def entries
  @entries
end

#idempotency_keyProc?

Returns the idempotency key extractor for this provider.

Examples:

config.provider(:stripe) do |stripe|
  stripe.idempotency_key = ->(payload) { payload['id'] }
end

Returns:

  • (Proc, nil)

    the idempotency key extractor for this provider.



29
30
31
# File 'lib/hooksmith/config/provider.rb', line 29

def idempotency_key
  @idempotency_key
end

#providerString (readonly)

Returns the provider name.

Returns:

  • (String)

    the provider name.



12
13
14
# File 'lib/hooksmith/config/provider.rb', line 12

def provider
  @provider
end

#verifierHooksmith::Verifiers::Base?

Returns the verifier for this provider.

Examples:

config.provider(:stripe) do |stripe|
  stripe.verifier = Hooksmith::Verifiers::Hmac.new(
    secret: ENV['STRIPE_WEBHOOK_SECRET'],
    header: 'Stripe-Signature'
  )
end

Returns:



23
24
25
# File 'lib/hooksmith/config/provider.rb', line 23

def verifier
  @verifier
end

Instance Method Details

#register(event, processor_class_name) ⇒ Object

Registers a processor for a specific event.

Parameters:

  • event (Symbol, String)

    the event name.

  • processor_class_name (String)

    the processor class name.



42
43
44
# File 'lib/hooksmith/config/provider.rb', line 42

def register(event, processor_class_name)
  entries << { event: event.to_s, processor: processor_class_name }
end