Mailgun Tracking

Gem Version Badge Travis CI Badge Dependency Status Badge Code Climate Badge Test Coverage Badge Inline Docs Badge

This gem provides a simple way for integration with Mailgun Webhooks.

Installation

Add this line to your application's Gemfile:

gem 'mailgun-tracking'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mailgun-tracking

Configuration

Rails

To integrate Mailgun Tracking with your Rails application, you need to know your api key and endpoint. Invoke the following command and replace API_KEY and ENDPOINT with your values:

rails generate mailgun:tracking:install API_KEY ENDPOINT

This command will generate the Mailgun Tracking configuration file under config/initializers/mailgun_tracking.rb.

Usage

Rails

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

  config.notifier.all do |payload|
    # Handle all event types.
  end
end

Subscriber objects that respond to #call

class Bounced
  def initialize(logger)
    @logger = logger
  end

  def call(payload)
    @logger.info(payload)
  end
end
Mailgun::Tracking.configure do |config|
  config.notifier.subscribe :bounced, Bounced.new
end

License

The gem is available as open source under the terms of the MIT License.