lib/mailkick/service/mailchimp.rb in mailkick-0.2.0 vs lib/mailkick/service/mailchimp.rb in mailkick-0.2.1

- old
+ new

@@ -2,36 +2,36 @@ module Mailkick class Service class Mailchimp < Mailkick::Service def initialize(options = {}) - @gibbon = ::Gibbon::API.new(options[:api_key] || ENV["MAILCHIMP_API_KEY"]) + @gibbon = ::Gibbon::Request.new(api_key: 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") + fetch(@gibbon.lists(@list_id).members.retrieve(params: {status: "unsubscribed"}).body["members"], "unsubscribe") end def spam_reports - fetch(@gibbon.lists.abuse_reports(id: @list_id), "spam") + fetch(@gibbon.lists(@list_id).abuse_reports.retrieve.body["abuse_reports"], "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| + response.map do |record| { - email: record["email"], + email: record["email_address"], time: ActiveSupport::TimeZone["UTC"].parse(record["timestamp_opt"] || record["date"]), reason: reason } end end