class MimiMailer::Base

Public Class Methods

bulk_mail(options = {}) click to toggle source
# File lib/mimi_mailer/base.rb, line 34
def self.bulk_mail(options = {})
  if MimiMailer.deliveries_enabled?
    check_config!

    options = default_options.merge(options)
    options[:csv_file] = options.delete(:to) if options[:csv_file].nil?
    options[:body] = options[:body].to_yaml unless options[:body].nil?

    bulk_mail_options_sanity_check! options

    response = post('/mailer/to_imported_list', body: options)

    response.body.to_i
  end
end
default_options() click to toggle source
# File lib/mimi_mailer/base.rb, line 50
def self.default_options
  @default_options.merge(
    username: MimiMailer.config.username,
    api_key:  MimiMailer.config.api_key,
    from:     from_address
  )
end
deliver(*args) click to toggle source
# File lib/mimi_mailer/base.rb, line 14
def self.deliver(*args)
  raise NotImplementedError.new("#{self.class.name}.deliver must be overridden")
end
from_address(new_address = nil) click to toggle source
# File lib/mimi_mailer/base.rb, line 6
def self.from_address(new_address = nil)
  if new_address.nil?
    @from_address || MimiMailer.config.default_from_address || MimiMailer.config.username
  else
    @from_address = new_address
  end
end
mail(options = {}) click to toggle source
# File lib/mimi_mailer/base.rb, line 18
def self.mail(options = {})
  if MimiMailer.deliveries_enabled?
    check_config!

    options = default_options.merge(options)
    options[:recipient] = options.delete(:to) if options[:recipient].nil?
    options[:body] = options[:body].to_yaml unless options[:body].nil?

    mail_options_sanity_check! options

    response = post('/mailer', body: options)

    response.body.to_i
  end
end

Protected Class Methods

bulk_mail_options_sanity_check!(options) click to toggle source
# File lib/mimi_mailer/base.rb, line 68
def self.bulk_mail_options_sanity_check!(options)
  raise ArgumentError.new(":csv_file or :to must be specified") if options[:csv_file].nil?
  raise ArgumentError.new(":audience_list must be specified") if options[:audience_list].nil?
  raise ArgumentError.new(":promotion_name must be specified") if options[:promotion_name].nil?
end
check_config!() click to toggle source
# File lib/mimi_mailer/base.rb, line 59
def self.check_config!
  raise MimiMailer::InvalidConfigurationError unless MimiMailer.config.valid?
end
mail_options_sanity_check!(options) click to toggle source
# File lib/mimi_mailer/base.rb, line 63
def self.mail_options_sanity_check!(options)
  raise ArgumentError.new(":recipient or :to must be specified") if options[:recipient].nil?
  raise ArgumentError.new(":promotion_name must be specified") if options[:promotion_name].nil?
end