Module: Mailgun::Tracking

Defined in:
lib/mailgun/tracking.rb,
lib/mailgun/tracking/auth.rb,
lib/mailgun/tracking/fanout.rb,
lib/mailgun/tracking/railtie.rb,
lib/mailgun/tracking/version.rb,
lib/mailgun/tracking/middleware.rb,
lib/mailgun/tracking/configuration.rb,
lib/generators/mailgun/tracking/install_generator.rb

Overview

The namespace for classes and modules that handle Mailgun webhooks.

Defined Under Namespace

Modules: Version Classes: Auth, Configuration, Fanout, InstallGenerator, Middleware, Railtie

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object (private)

Delegate any missing method call to the configuration.



80
81
82
83
84
# 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

Class Method Details

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

Subscribe to all events.

Examples:

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

Parameters:

  • callable (#call) (defaults to: nil)

    the event handler.



73
74
75
76
77
# File 'lib/mailgun/tracking.rb', line 73

def all(callable = nil, &block)
  ::Mailgun::Tracking::Fanout.all(
    callable || block
  )
end

.configure {|self| ... } ⇒ Object

The default way to set up Mailgun Tracking.

Examples:

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

Yields:

  • (self)

    block yields itself.



35
36
37
# File 'lib/mailgun/tracking.rb', line 35

def configure
  yield(self)
end

.method_missing(method_name, *arguments, &block) ⇒ Object

Delegate any missing method call to the configuration.



80
81
82
83
84
# 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) ⇒ Object

Subscribe to an event.

Examples:

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

Parameters:

  • event (Symbol, String)

    the event identifier.

  • callable (#call) (defaults to: nil)

    the event handler.



53
54
55
56
57
58
# 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) ⇒ Boolean

Replace the Object.respond_to?() method.

Returns:

  • (Boolean)


87
88
89
# File 'lib/mailgun/tracking.rb', line 87

def respond_to_missing?(method_name, include_private = false)
  configuration.respond_to?(method_name) || super
end