Class: Mailgun::Tracking::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun/tracking/notifier.rb

Overview

Wraps the Listener which gives a friendlier way to subscribe or broadcast.

Instance Method Summary collapse

Constructor Details

#initialize(listener = Listener.new) ⇒ Mailgun::Tracking::Notifier

Initializes a new Notifier object.


10
11
12
# File 'lib/mailgun/tracking/notifier.rb', line 10

def initialize(listener = Listener.new)
  @listener ||= listener
end

Instance Method Details

#all(callable = Proc.new) ⇒ NilClass

Adds a subscriber for all events.


31
32
33
# File 'lib/mailgun/tracking/notifier.rb', line 31

def all(callable = Proc.new)
  listener.add_subscriber(nil, callable)
end

#broadcast(event, payload) ⇒ NilClass

Broadcasts parameters to event subscribers.


41
42
43
44
# File 'lib/mailgun/tracking/notifier.rb', line 41

def broadcast(event, payload)
  Signature.verify!(payload)
  listener.broadcast(event, payload)
end

#subscribe(event, callable = Proc.new) ⇒ NilClass

Adds subscriber for the specified event.


21
22
23
# File 'lib/mailgun/tracking/notifier.rb', line 21

def subscribe(event, callable = Proc.new)
  listener.add_subscriber(event, callable)
end