class Mailkick::Service::Sendgrid

Public Class Methods

discoverable?() click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 28
def self.discoverable?
  !!(defined?(::SendgridToolkit) && ENV["SENDGRID_USERNAME"] && ENV["SENDGRID_PASSWORD"])
end
new(options = {}) click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 6
def initialize(options = {})
  @api_user = options[:api_user] || ENV["SENDGRID_USERNAME"]
  @api_key = options[:api_key] || ENV["SENDGRID_PASSWORD"]
end

Public Instance Methods

bounces() click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 24
def bounces
  fetch(::SendgridToolkit::Bounces, "bounce")
end
opt_outs() click to toggle source

TODO paginate

# File lib/mailkick/service/sendgrid.rb, line 12
def opt_outs
  unsubscribes + spam_reports + bounces
end
spam_reports() click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 20
def spam_reports
  fetch(::SendgridToolkit::SpamReports, "spam")
end
unsubscribes() click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 16
def unsubscribes
  fetch(::SendgridToolkit::Unsubscribes, "unsubscribe")
end

Protected Instance Methods

fetch(klass, reason) click to toggle source
# File lib/mailkick/service/sendgrid.rb, line 34
def fetch(klass, reason)
  klass.new(@api_user, @api_key).retrieve_with_timestamps.map do |record|
    {
      email: record["email"],
      time: record["created"],
      reason: reason
    }
  end
end