Class: PostageApp::Mail::DeliveryMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/postageapp/mail/delivery_method.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DeliveryMethod

Creates a new DeliveryMethod instance with the supplied options.



7
8
9
# File 'lib/postageapp/mail/delivery_method.rb', line 7

def initialize(options)
  @options = options.dup
end

Class Method Details

.deliveriesObject



2
3
4
# File 'lib/postageapp/mail/delivery_method.rb', line 2

def self.deliveries
  @deliveries ||= [ ]
end

Instance Method Details

#deliver!(mail) ⇒ Object

Delivers a given Mail::Message through PostageApp using the configuration specified through Mail defaults or settings applied to ActionMailer.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/postageapp/mail/delivery_method.rb', line 13

def deliver!(mail)
  api_method, arguments = PostageApp::Mail::Arguments.new(mail).extract

  case (@options[:api_key])
  when false, :test
    # In testing mode, just capture the calls that would have been made so
    # they can be inspected later using the deliveries class method.
    self.class.deliveries << [ api_method, arguments ]
  when nil
    # If the API key is not defined, raise an error providing a hint as to
    # how to set that correctly.
    raise PostageApp::Error,
      "PostageApp API key not defined: Add :api_key to config.action_mailer.postageapp_settings to config/application.rb"
  else
    arguments['api_key'] ||= @options[:api_key]

    PostageApp::Request.new(api_method, arguments).send
  end
end