Class: SailthruMailer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sailthru_mailer/base.rb

Constant Summary collapse

VALID_CONFIGURATION_METHODS =
[:to, :from, :cc, :bcc, :reply_to, :date]
DEPRECATED_CONFIGURATION_METHODS =
[:subject]
CONFIGURATION_METHODS =
VALID_CONFIGURATION_METHODS + DEPRECATED_CONFIGURATION_METHODS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ Base

private initializer



13
14
15
16
# File 'lib/sailthru_mailer/base.rb', line 13

def initialize(name, *args)
  self.template = name
  self.send(name, *args)
end

Instance Attribute Details

#templateObject

we have accessors for



8
9
10
# File 'lib/sailthru_mailer/base.rb', line 8

def template
  @template
end

Class Method Details

.connection(reload = false) ⇒ Object



110
111
112
113
# File 'lib/sailthru_mailer/base.rb', line 110

def connection(reload = false)
  @connection = nil if reload
  @connection ||= SailthruMailer::Connection.new
end

.inherited(klass) ⇒ Object

called when someone inherits from us



104
105
106
107
108
# File 'lib/sailthru_mailer/base.rb', line 104

def inherited(klass)
  VALID_CONFIGURATION_METHODS.each do |m|
    klass.send(m, self.send(m))
  end
end

Instance Method Details

#deliverObject

send the mail



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/sailthru_mailer/base.rb', line 54

def deliver
  # handle test mode
  return SailthruMailer.deliveries << self if SailthruMailer.test
  # response = sailthru.send(template_name, email, vars, options, schedule_time)
  self.class.connection.deliver(
    self.template, 
    self.all_recipients,
    self.formatted_vars,
    self.formatted_options,
    (self.date || Time.now).utc.to_s
  )
end

#formatted_varsObject

formatted variable hash, ready for JSON encoding



67
68
69
70
71
72
73
# File 'lib/sailthru_mailer/base.rb', line 67

def formatted_vars
  {}.tap do |ret|
    self.vars.each_pair do |k,v|
      ret[k] = self.prep_for_json(v)
    end
  end
end

#vars(val = nil) ⇒ Object Also known as: body

variables for the template



42
43
44
45
# File 'lib/sailthru_mailer/base.rb', line 42

def vars(val = nil)
  @vars = val unless val.nil?
  @vars ||= {}
end

#vars=(val) ⇒ Object Also known as: body=



46
47
48
# File 'lib/sailthru_mailer/base.rb', line 46

def vars=(val)
  vars(val)
end