Sha256: 4403e3084c225781d7bb903b3cb89f48ec5f809cd3985eca2170317f6ad55cfe

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require "ahoy_email/version"
require "action_mailer"
require "nokogiri"
require "addressable/uri"
require "openssl"
require "ahoy_email/processor"
require "ahoy_email/interceptor"
require "ahoy_email/engine"

ActionMailer::Base.register_interceptor AhoyEmail::Interceptor

module AhoyEmail
  mattr_accessor :secret_token, :options

  self.options = {
    create_message: true,
    track_open: true,
    track_click: true,
    utm_source: nil,
    utm_medium: "email",
    utm_term: nil,
    utm_content: nil,
    utm_campaign: nil
  }
end

module ActionMailer
  class Base
    class_attribute :ahoy_options
    self.ahoy_options = {}

    class << self
      def ahoy(options)
        self.ahoy_options = ahoy_options.merge(options)
      end
    end

    def ahoy(options)
      @ahoy_options = (@ahoy_options || {}).merge(options)
    end

    def mail_with_ahoy(headers = {}, &block)
      message = mail_without_ahoy(headers, &block)

      options = AhoyEmail.options.merge(self.class.ahoy_options).merge(@ahoy_options || {})
      AhoyEmail::Processor.new(message, options).process!

      message
    end
    alias_method_chain :mail, :ahoy

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahoy_email-0.0.2 lib/ahoy_email.rb