class Drill::Mail::Default

Public Instance Methods

deliver() click to toggle source
# File lib/drill/mail/default.rb, line 8
def deliver
  return if params.skip_delivery

  template_name = params.template_name

  Drill.client.messages.send_template(template_name, [], message_hash)
end
deliver_later(wait: nil) click to toggle source
# File lib/drill/mail/default.rb, line 16
def deliver_later(wait: nil)
  return if params.skip_delivery

  template_name = params.template_name

  if wait
    worker.perform_in(wait.to_i, template_name, message_hash)
  else
    worker.perform_async(template_name, message_hash)
  end
end

Private Instance Methods

message_hash() click to toggle source
# File lib/drill/mail/default.rb, line 34
def message_hash
  message_hash = {}

  to_emails = Array(params.to).map do |email|
    { email: email }
  end
  cc_emails = Array(params.cc).map do |email|
    { email: email, type: 'cc' }
  end
  vars = Hash(params.vars).map do |name, content|
    { name: name.to_s.upcase, content: content }
  end

  all_emails = to_emails + cc_emails
  unless all_emails.empty?
    message_hash[:to] = all_emails

    unless vars.empty?
      message_hash[:merge_vars] =
        all_emails.each.with_object([]) do |email, arr|
          arr << { rcpt: email[:email], vars: vars }
        end
    end
  end
  message_hash[:from_name] = params.from_name if params.from_name
  message_hash[:from_email] = params.from_email if params.from_email
  if params.reply_to
    message_hash[:headers] = { 'Reply-To' => params.reply_to }
  end

  message_hash
end
worker() click to toggle source
# File lib/drill/mail/default.rb, line 30
def worker
  Drill::DeliveryWorker
end