Class: SendcloudMailer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sendcloud-mailer/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/sendcloud-mailer/base.rb', line 7

def initialize(settings)
  self.settings = settings
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



5
6
7
# File 'lib/sendcloud-mailer/base.rb', line 5

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sendcloud-mailer/base.rb', line 11

def deliver!(mail)
  @mail = mail

  params = {
    :apiUser => settings[:api_user],
    :apiKey => settings[:api_key],
    :from => from,
    :to => to,
    :cc => cc,
    :bcc => bcc,
    :subject => mail.subject,
    :html => html,
    :plain => plain,
    :attachments => attachments
  }
  params.delete_if { |k, v| v.nil? }

  result = RestClient.post( 'http://api.sendcloud.net/apiv2/mail/send', params )
  json = JSON.parse(result.force_encoding('UTF-8'))
  error(json) unless json["result"]
  unless @file.nil?
    File.unlink(@file.path) rescue nil
  end
end