class Mail::Notify::DeliveryMethod
Attributes
response[RW]
settings[RW]
Public Class Methods
new(settings)
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 8 def initialize(settings) raise ArgumentError, "You must specify an API key" if settings[:api_key].blank? @settings = settings end
Public Instance Methods
deliver!(mail)
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 14 def deliver!(mail) @mail = mail @personalisation = Personalisation.new(mail) send_email end
preview(mail)
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 20 def preview(mail) personalisation = Personalisation.new(mail).to_h template_id = mail[:template_id].to_s client.generate_template_preview(template_id, personalisation: personalisation) end
Private Instance Methods
client()
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 28 def client @client ||= Notifications::Client.new(@settings[:api_key], @settings[:base_url]) end
email_params()
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 32 def email_params { email_address: @mail.to.first, template_id: @mail[:template_id].to_s, personalisation: @personalisation.to_h, email_reply_to_id: optional_param(:reply_to_id), reference: optional_param(:reference) } end
optional_param(name)
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 42 def optional_param(name) @mail[name].presence&.to_s end
send_email()
click to toggle source
# File lib/mail/notify/delivery_method.rb, line 46 def send_email @response = client.send_email(email_params.compact) end