lib/mailkick/service/mandrill.rb in mailkick-0.0.1 vs lib/mailkick/service/mandrill.rb in mailkick-0.0.2
- old
+ new
@@ -1,20 +1,30 @@
# 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|
- # record
- # end
- []
+ @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