module Mailgun::Tracking

The namespace for classes and modules that handle Mailgun webhooks.

Public Instance Methods

all(callable = nil, &block) click to toggle source

Subscribe to all events.

@param callable [#call] the event handler.

@example

Mailgun::Tracking.configure do |config|
  config.all do |payload|
    # Do something with the incoming data.
  end

  # The object should respond to #call
  config.all, All.new
end
# File lib/mailgun/tracking.rb, line 73
def all(callable = nil, &block)
  ::Mailgun::Tracking::Fanout.all(
    callable || block
  )
end
configuration() click to toggle source

@return [Mailgun::Tracking::Configuration]

# File lib/mailgun/tracking.rb, line 92
def configuration
  ::Mailgun::Tracking::Configuration.instance
end
configure() { |self| ... } click to toggle source

The default way to set up Mailgun Tracking.

@yield [self] block yields itself.

@example

Mailgun::Tracking.configure do |config|
  config.api_key = ENV['MAILGUN_API_KEY']

  config.endpoint = '/mailgun-tracking'

  config.on 'delivered' do |payload|
    # Do something with the incoming data.
  end

  # The object should respond to #call
  config.on 'bounced', Bounced.new

  config.all do |payload|
    # Do something with the incoming data.
  end
end
# File lib/mailgun/tracking.rb, line 35
def configure
  yield(self)
end
method_missing(method_name, *arguments, &block) click to toggle source

Delegate any missing method call to the configuration.

Calls superclass method
# File lib/mailgun/tracking.rb, line 80
def method_missing(method_name, *arguments, &block)
  return super unless configuration.respond_to?(method_name)

  configuration.public_send(method_name, *arguments, &block)
end
on(event, callable = nil, &block) click to toggle source

Subscribe to an event.

@param event [Symbol, String] the event identifier. @param callable [#call] the event handler.

@example

Mailgun::Tracking.configure do |config|
  config.on 'delivered' do |payload|
    # Do something with the incoming data.
  end

  # The object should respond to #call
  config.on 'bounced', Bounced.new
end
# File lib/mailgun/tracking.rb, line 53
def on(event, callable = nil, &block)
  ::Mailgun::Tracking::Fanout.on(
    event.to_s.dup.freeze,
    callable || block
  )
end
respond_to_missing?(method_name, include_private = false) click to toggle source

Replace the Object.respond_to?() method.

Calls superclass method
# File lib/mailgun/tracking.rb, line 87
def respond_to_missing?(method_name, include_private = false)
  configuration.respond_to?(method_name) || super
end