Sha256: 012423301ee39925cf2964b871a02a1ab01c4e3a8d4040c526784e8de108a872

Contents?: true

Size: 862 Bytes

Versions: 7

Compression:

Stored size: 862 Bytes

Contents

# https://mandrillapp.com/api/docs/index.ruby.html

module Mailkick
  class Service
    class Mandrill < Mailkick::Service
      REASONS_MAP = {
        "hard-bounce" => "bounce",
        "soft-bounce" => "bounce",
        "spam" => "spam",
        "unsub" => "unsubscribe"
      }

      def initialize(options = {})
        require "mandrill"
        @mandrill = ::Mandrill::API.new(options[:api_key] || ENV["MANDRILL_APIKEY"])
      end

      # TODO paginate
      def opt_outs
        @mandrill.rejects.list.map do |record|
          {
            email: record["email"],
            time: ActiveSupport::TimeZone["UTC"].parse(record["created_at"]),
            reason: REASONS_MAP[record["reason"]]
          }
        end
      end

      def self.discoverable?
        !!(defined?(::Mandrill::API) && ENV["MANDRILL_APIKEY"])
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mailkick-0.1.1 lib/mailkick/service/mandrill.rb
mailkick-0.1.0 lib/mailkick/service/mandrill.rb
mailkick-0.0.6 lib/mailkick/service/mandrill.rb
mailkick-0.0.5 lib/mailkick/service/mandrill.rb
mailkick-0.0.4 lib/mailkick/service/mandrill.rb
mailkick-0.0.3 lib/mailkick/service/mandrill.rb
mailkick-0.0.2 lib/mailkick/service/mandrill.rb