Class: Mail::Postmark

Inherits:
Object
  • Object
show all
Defined in:
lib/postmark/handlers/mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Postmark

Returns a new instance of Postmark.



6
7
8
# File 'lib/postmark/handlers/mail.rb', line 6

def initialize(values)
  self.settings = { :api_token => ENV['POSTMARK_API_TOKEN'] }.merge(values)
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



4
5
6
# File 'lib/postmark/handlers/mail.rb', line 4

def settings
  @settings
end

Instance Method Details

#api_clientObject



24
25
26
27
28
# File 'lib/postmark/handlers/mail.rb', line 24

def api_client
  settings = self.settings.dup
  api_token = settings.delete(:api_token) || settings.delete(:api_key)
  ::Postmark::ApiClient.new(api_token, settings)
end

#deliver!(mail) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/postmark/handlers/mail.rb', line 10

def deliver!(mail)
  response = if mail.templated?
               api_client.deliver_message_with_template(mail)
             else
               api_client.deliver_message(mail)
             end

  if settings[:return_response]
    response
  else
    self
  end
end