Sha256: d5c8f9cfe445e401f6e0a4279bd82548c6e436b64921fc1a09e44e94450987f0

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

gem 'mandrill-api', '~> 1.0.53'
require 'mandrill'

module MnoEnterprise
  module MailAdapters
    class MandrillAdapter < Adapter
      class << self
        # Return a mandrill client configured with the right API key
        def client
          @client ||= Mandrill::API.new(ENV['MANDRILL_API_KEY'] || MnoEnterprise.mandrill_key)
        end

        # Send a template
        # @see Adapter#deliver
        def deliver(template, from, to, vars={}, opts={})
          # Prepare message from args
          message = { from_name: from[:name], from_email: from[:email]}
          message[:to] = [to].flatten.map { |t| {name: t[:name], email: t[:email], type: (t[:type] || :to) } }
          message[:global_merge_vars] = vars.map { |k,v| {name: k.to_s, content: v} }

          # Merge additional mandrill options
          message.merge!(opts)

          self.send_template(template,[],message)
        end

        # Send the provided template with options
        # MandrillClient.send_template(template_name(string), template_content(array), message(hash))
        def send_template(*args)
          if self.test?
            self.base_deliveries.push(args)
          else
            self.client.messages.send_template(*args)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mno-enterprise-core-3.1.4 lib/mno_enterprise/mail_adapters/mandrill_adapter.rb
mno-enterprise-core-3.1.3 lib/mno_enterprise/mail_adapters/mandrill_adapter.rb
mno-enterprise-core-3.1.2 lib/mno_enterprise/mail_adapters/mandrill_adapter.rb
mno-enterprise-core-3.1.1 lib/mno_enterprise/mail_adapters/mandrill_adapter.rb
mno-enterprise-core-3.1.0 lib/mno_enterprise/mail_adapters/mandrill_adapter.rb