Class: DevelopmentNotification::Email

Inherits:
ApplicationRecord show all
Defined in:
app/models/development_notification/email.rb

Class Method Summary collapse

Class Method Details

.create_from_leadersend_response_hash(**hash) ⇒ Object



34
35
36
37
38
39
# File 'app/models/development_notification/email.rb', line 34

def self.create_from_leadersend_response_hash(**hash)
  hash[:status] = self.statuses[hash[:status]]
  sent_mail = new(hash.symbolize_keys)  # .merge(without_protection: true)
  sent_mail.save
  return sent_mail
end

.send_email(title: nil, to: [], from: nil, fromname: nil, subject: nil, template: nil, template_path: nil, locals: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/development_notification/email.rb', line 8

def self.send_email(title: nil, to: [], from: nil, fromname: nil, subject: nil, template: nil, template_path: nil, locals: nil)
  mail_object = nil

  [to].flatten.each do |to_email|
    mailer = Leadersend::Mail.new(
      title: title, to: to_email, from: from,
      fromname: fromname, subject: subject, template: template
    )
    leadersend_response_hash = mailer.send

    mail_object = DevelopmentNotification::Email.create_from_leadersend_response_hash(leadersend_response_hash)
    puts "sent email to '#{to_email}'"

  end

  return mail_object

  # TODO add differentiation based on template/template_path argument to use raw html or path accordingly.
end

.statusesObject

private



30
31
32
# File 'app/models/development_notification/email.rb', line 30

def self.statuses
  ActiveSupport::HashWithIndifferentAccess.new(new: 0, sent: 1, error: 2)
end