Class: SendcloudMailer::Base
- Inherits:
-
Object
- Object
- SendcloudMailer::Base
- Defined in:
- lib/sendcloud-mailer/base.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
- #from ⇒ Object
- #html ⇒ Object
-
#initialize(settings) ⇒ Base
constructor
A new instance of Base.
- #plain ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(settings) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/sendcloud-mailer/base.rb', line 5 def initialize(settings) self.settings = settings end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
3 4 5 |
# File 'lib/sendcloud-mailer/base.rb', line 3 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sendcloud-mailer/base.rb', line 9 def deliver!(mail) @mail = mail params = { :apiUser => settings[:api_user], :apiKey => settings[:api_key], :from => from, :to => to, :subject => mail.subject, :html => html, :plain => plain } result = Net::HTTP.post_form(URI.parse("http://api.sendcloud.net/apiv2/mail/send"), params) json = JSON.parse(result.body.force_encoding('UTF-8')) ActionMailer::Base.logger.error(json) unless json["result"] && !ActionMailer::Base.logger.nil? end |
#from ⇒ Object
27 28 29 |
# File 'lib/sendcloud-mailer/base.rb', line 27 def from @mail.header.fields.find{|f| f.name == "From"}.value end |
#html ⇒ Object
36 37 38 |
# File 'lib/sendcloud-mailer/base.rb', line 36 def html @mail.html_part ? @mail.html_part.body.decoded : nil end |
#plain ⇒ Object
40 41 42 |
# File 'lib/sendcloud-mailer/base.rb', line 40 def plain @mail.multipart? ? (@mail.text_part ? @mail.text_part.body.decoded : nil) : @mail.body.decoded end |
#to ⇒ Object
31 32 33 34 |
# File 'lib/sendcloud-mailer/base.rb', line 31 def to addresses = @mail.header.fields.find{|f| f.name == "To"}.address_list.addresses addresses.join(';') end |