Module: EventSubEvents

Defined in:
lib/event_sub_events.rb,
lib/event_sub_events/engine.rb,
lib/event_sub_events/version.rb,
lib/event_sub_events/signature_verifier.rb,
app/controllers/event_sub_events/webhook_controller.rb

Defined Under Namespace

Classes: Engine, Error, Namespace, NotificationAdapter, ProcessError, SignatureVerificationError, SignatureVerifier, UnauthorizedError, WebhookController

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.adapterObject

Returns the value of attribute adapter.



7
8
9
# File 'lib/event_sub_events.rb', line 7

def adapter
  @adapter
end

.backendObject

Returns the value of attribute backend.



7
8
9
# File 'lib/event_sub_events.rb', line 7

def backend
  @backend
end

.event_filterObject

Returns the value of attribute event_filter.



7
8
9
# File 'lib/event_sub_events.rb', line 7

def event_filter
  @event_filter
end

.namespaceObject

Returns the value of attribute namespace.



7
8
9
# File 'lib/event_sub_events.rb', line 7

def namespace
  @namespace
end

.signing_secretsObject (readonly)

Returns the value of attribute signing_secrets.



8
9
10
# File 'lib/event_sub_events.rb', line 8

def signing_secrets
  @signing_secrets
end

Class Method Details

.all(callable = nil, &block) ⇒ Object



26
27
28
29
# File 'lib/event_sub_events.rb', line 26

def all(callable = nil, &block)
  callable ||= block
  subscribe nil, callable
end

.configure(&block) ⇒ Object Also known as: setup

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/event_sub_events.rb', line 10

def configure(&block)
  raise ArgumentError, "must provide a block" unless block_given?
  block.arity.zero? ? instance_eval(&block) : yield(self)
end

.instrument(event) ⇒ Object



16
17
18
19
# File 'lib/event_sub_events.rb', line 16

def instrument(event)
  event = event_filter.call(event)
  backend.instrument namespace.call(event.subscription.type), event if event
end

.listening?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/event_sub_events.rb', line 31

def listening?(name)
  namespaced_name = namespace.call(name)
  backend.notifier.listening?(namespaced_name)
end

.signing_secretObject



41
42
43
# File 'lib/event_sub_events.rb', line 41

def signing_secret
  self.signing_secrets && self.signing_secrets.first
end

.signing_secret=(value) ⇒ Object Also known as: signing_secrets=



36
37
38
# File 'lib/event_sub_events.rb', line 36

def signing_secret=(value)
  @signing_secrets = Array(value).compact
end

.subscribe(name, callable = nil, &block) ⇒ Object



21
22
23
24
# File 'lib/event_sub_events.rb', line 21

def subscribe(name, callable = nil, &block)
  callable ||= block
  backend.subscribe namespace.to_regexp(name), adapter.call(callable)
end