Sha256: 5b5544ed149a6253c8f0499562f471da7844696cd283e878a52c96212095ce05
Contents?: true
Size: 1.03 KB
Versions: 7
Compression:
Stored size: 1.03 KB
Contents
# https://github.com/amro/gibbon module Mailkick class Service class Mailchimp < Mailkick::Service def initialize(options = {}) @gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"]) @list_id = options[:list_id] || ENV["MAILCHIMP_LIST_ID"] end # TODO paginate def opt_outs unsubscribes + spam_reports end def unsubscribes fetch(@gibbon.lists.members(id: @list_id, status: "unsubscribed"), "unsubscribe") end def spam_reports fetch(@gibbon.lists.abuse_reports(id: @list_id), "spam") end def self.discoverable? !!(defined?(::Gibbon) && ENV["MAILCHIMP_API_KEY"] && ENV["MAILCHIMP_LIST_ID"]) end protected def fetch(response, reason) response["data"].map do |record| { email: record["email"], time: ActiveSupport::TimeZone["UTC"].parse(record["timestamp_opt"] || record["date"]), reason: reason } end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems