Class: WebhookInbox::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/webhook_inbox/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
# File 'lib/webhook_inbox/configuration.rb', line 7

def initialize
  @queue_name = "webhooks"
  @dashboard_auth = nil
  @handlers = {}
end

Instance Attribute Details

#dashboard_authObject

Returns the value of attribute dashboard_auth.



5
6
7
# File 'lib/webhook_inbox/configuration.rb', line 5

def dashboard_auth
  @dashboard_auth
end

#queue_nameObject

Returns the value of attribute queue_name.



5
6
7
# File 'lib/webhook_inbox/configuration.rb', line 5

def queue_name
  @queue_name
end

Instance Method Details

#handlers_for(provider, event_type) ⇒ Object

Returns all matching handler blocks for [provider, event_type]. Includes exact matches and wildcard “*” handlers for the provider.



28
29
30
31
32
# File 'lib/webhook_inbox/configuration.rb', line 28

def handlers_for(provider, event_type)
  exact    = @handlers[handler_key(provider, event_type)] || []
  wildcard = @handlers[handler_key(provider, "*")] || []
  exact + wildcard
end

#on(provider, event_type, &block) ⇒ Object

Register a handler block for a given provider + event type. Use “*” as event_type to match any event from that provider.

config.on(:stripe, "customer.subscription.created") { |event| ... }
config.on(:stripe, "*") { |event| ... }

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
# File 'lib/webhook_inbox/configuration.rb', line 18

def on(provider, event_type, &block)
  raise ArgumentError, "Handler block required" unless block

  key = handler_key(provider, event_type)
  @handlers[key] ||= []
  @handlers[key] << block
end