Class: Emailfuse::Deliverer

Inherits:
Object
  • Object
show all
Defined in:
lib/emailfuse/deliverer.rb

Defined Under Namespace

Classes: Attachment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Deliverer

Returns a new instance of Deliverer.



16
17
18
# File 'lib/emailfuse/deliverer.rb', line 16

def initialize(settings)
  self.settings = settings
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



14
15
16
# File 'lib/emailfuse/deliverer.rb', line 14

def settings
  @settings
end

Instance Method Details

#api_tokenObject



20
21
22
# File 'lib/emailfuse/deliverer.rb', line 20

def api_token
  self.settings[:token] || Emailfuse.config.token
end

#deliver!(rails_message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/emailfuse/deliverer.rb', line 24

def deliver!(rails_message)
  attributes = {
    from: rails_message[:from],
    to: rails_message[:to].formatted,
    subject: rails_message.subject,
    html: extract_html(rails_message),
    text: extract_text(rails_message)
  }

  [ :reply_to, :cc ].each do |key|
    attributes[key] = rails_message[key].formatted if rails_message[key]
  end

  unless rails_message.attachments.empty?
    attributes[:attachments] = []
    rails_message.attachments.each do |attachment|
      attributes[:attachments] << Attachment.new(attachment, encoding: "ascii-8bit")
    end
  end

  Email.create(**attributes)
end