Sha256: 18c1edbf57135e8e1e464c58cca3a49d1eb8d3c8c3c4d41b768f5f8454b3540d

Contents?: true

Size: 1023 Bytes

Versions: 20

Compression:

Stored size: 1023 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"
      }

      # TODO remove ENV["MANDRILL_APIKEY"]
      def initialize(options = {})
        require "mandrill"
        @mandrill = ::Mandrill::API.new(
          options[:api_key] || ENV["MANDRILL_APIKEY"] || ENV["MANDRILL_API_KEY"]
        )
      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

      # TODO remove ENV["MANDRILL_APIKEY"]
      def self.discoverable?
        !!(defined?(::Mandrill::API) && (ENV["MANDRILL_APIKEY"] || ENV["MANDRILL_API_KEY"]))
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mailkick-1.3.1 lib/mailkick/service/mandrill.rb
mailkick-1.3.0 lib/mailkick/service/mandrill.rb
mailkick-1.2.2 lib/mailkick/service/mandrill.rb
mailkick-1.2.1 lib/mailkick/service/mandrill.rb
mailkick-1.2.0 lib/mailkick/service/mandrill.rb
mailkick-1.1.2 lib/mailkick/service/mandrill.rb
mailkick-1.1.1 lib/mailkick/service/mandrill.rb
mailkick-1.1.0 lib/mailkick/service/mandrill.rb
mailkick-1.0.1 lib/mailkick/service/mandrill.rb
mailkick-1.0.0 lib/mailkick/service/mandrill.rb
mailkick-0.4.3 lib/mailkick/service/mandrill.rb
mailkick-0.4.2 lib/mailkick/service/mandrill.rb
mailkick-0.4.1 lib/mailkick/service/mandrill.rb
mailkick-0.4.0 lib/mailkick/service/mandrill.rb
mailkick-0.3.1 lib/mailkick/service/mandrill.rb
mailkick-0.3.0 lib/mailkick/service/mandrill.rb
mailkick-0.2.1 lib/mailkick/service/mandrill.rb
mailkick-0.2.0 lib/mailkick/service/mandrill.rb
mailkick-0.1.6 lib/mailkick/service/mandrill.rb
mailkick-0.1.5 lib/mailkick/service/mandrill.rb