class Mailkick::Service::SendGridV2
Public Class Methods
discoverable?()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 26 def self.discoverable? !!(defined?(::SendGrid::API) && ENV["SENDGRID_API_KEY"]) end
new(options = {})
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 6 def initialize(options = {}) @api_key = options[:api_key] || ENV["SENDGRID_API_KEY"] end
Public Instance Methods
bounces()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 22 def bounces fetch(client.suppression.bounces, "bounce") end
opt_outs()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 10 def opt_outs unsubscribes + spam_reports + bounces end
spam_reports()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 18 def spam_reports fetch(client.suppression.spam_reports, "spam") end
unsubscribes()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 14 def unsubscribes fetch(client.suppression.unsubscribes, "unsubscribe") end
Protected Instance Methods
client()
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 32 def client @client ||= ::SendGrid::API.new(api_key: @api_key).client end
fetch(query, reason)
click to toggle source
# File lib/mailkick/service/sendgrid_v2.rb, line 36 def fetch(query, reason) # TODO paginate response = query.get raise "Bad status code: #{response.status_code}" if response.status_code.to_i != 200 response.parsed_body.map do |record| { email: record[:email], time: Time.at(record[:created]), reason: reason } end end