Sha256: 1ca935966ae7e46b056203ac11fc99a3c2594ed0f8234d30a6134849770ce2d0

Contents?: true

Size: 915 Bytes

Versions: 12

Compression:

Stored size: 915 Bytes

Contents

# https://github.com/wildbit/postmark-gem

module Mailkick
  class Service
    class Postmark < Mailkick::Service
      REASONS_MAP = {
        "SpamNotification" => "spam",
        "SpamComplaint" => "spam",
        "Unsubscribe" => "unsubscribe",
      }

      def initialize(options = {})
        @client = ::Postmark::ApiClient.new(options[:api_key] || ENV["POSTMARK_API_KEY"])
      end

      def opt_outs
        bounces
      end

      def bounces
        fetch(@client.bounces)
      end

      def self.discoverable?
        !!(defined?(::Postmark) && ENV["POSTMARK_API_KEY"])
      end

      protected

      def fetch(response)
        response.map do |record|
          {
            email: record[:email],
            time: ActiveSupport::TimeZone["UTC"].parse(record[:bounced_at]),
            reason: REASONS_MAP.fetch(record[:type], "bounce")
          }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mailkick-1.3.0 lib/mailkick/service/postmark.rb
mailkick-1.2.2 lib/mailkick/service/postmark.rb
mailkick-1.2.1 lib/mailkick/service/postmark.rb
mailkick-1.2.0 lib/mailkick/service/postmark.rb
mailkick-1.1.2 lib/mailkick/service/postmark.rb
mailkick-1.1.1 lib/mailkick/service/postmark.rb
mailkick-1.1.0 lib/mailkick/service/postmark.rb
mailkick-1.0.1 lib/mailkick/service/postmark.rb
mailkick-1.0.0 lib/mailkick/service/postmark.rb
mailkick-0.4.3 lib/mailkick/service/postmark.rb
mailkick-0.4.2 lib/mailkick/service/postmark.rb
mailkick-0.4.1 lib/mailkick/service/postmark.rb