Class: T::Mailer::DeliveryMethod

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/t/mailer/delivery_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#check_api_defined, #check_settings, #check_version_of, #field_value, #get_value_from, #using_gem

Constructor Details

#initialize(options = {}) ⇒ DeliveryMethod

Set settings with the required credentials for the API, but allow to call the delivery method without it. In that case it will set that up with the default. If credentials has been added then it will override the default credentials.

Parameters:

  • options (Hash) (defaults to: {})

    with the credentials



14
15
16
17
18
19
20
21
# File 'lib/t/mailer/delivery_method.rb', line 14

def initialize(options = {})
  @settings = {
    aws_access_key_id:     T::Mailer.configuration.aws_access_key_id,
    aws_default_region:    T::Mailer.configuration.aws_default_region,
    aws_secret_access_key: T::Mailer.configuration.aws_secret_access_key,
    sparkpost_api_key:     T::Mailer.configuration.sparkpost_api_key,
  }.merge!(options)
end

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



6
7
8
# File 'lib/t/mailer/delivery_method.rb', line 6

def settings
  @settings
end

Instance Method Details

#deliver!(message) ⇒ Object

Check that the delivery system is provided. If delivery system is missing it will raise error. If delivery system was provided then it will call the given delivery system with the message. If the provided delivery system does not exist the it will raise error.

Parameters:

  • message (Mail::Message)

    what we would like to send



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/t/mailer/delivery_method.rb', line 29

def deliver!(message)
  delivery_system = get_value_from(message["delivery_system"])

  if delivery_system.nil?
    fail Error::WrongDeliverySystem, "Delivery system is missing."
  end

  case delivery_system
  when "ses"
    DeliverySystem::AwsSes.new(settings).deliver(message)
  when "sparkpost"
    DeliverySystem::SparkPost.new(settings).deliver(message)
  else
    fail Error::WrongDeliverySystem,
      "The given delivery system is not supported."
  end
end