Class: AmazonEmail

Inherits:
Object
  • Object
show all
Includes:
AmazonDeliver
Defined in:
lib/amazon_email.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AmazonDeliver

get

Constructor Details

#initialize(options) ⇒ AmazonEmail

Returns a new instance of AmazonEmail.



6
7
8
9
10
11
12
13
14
# File 'lib/amazon_email.rb', line 6

def initialize(options)
  @from = options[:from]
  @to = options[:to]
  @subject = options[:subject]
  @body = options[:body]
  @template = options[:template]
  @aws_access_key = options[:aws_access_key] || ENV['AWS_ACCESS_KEY']
  @aws_secret_key = options[:aws_secret_key] || ENV['AWS_SECRET_KEY']   
end

Instance Attribute Details

#aws_access_keyObject

Returns the value of attribute aws_access_key.



4
5
6
# File 'lib/amazon_email.rb', line 4

def aws_access_key
  @aws_access_key
end

#aws_secret_keyObject

Returns the value of attribute aws_secret_key.



4
5
6
# File 'lib/amazon_email.rb', line 4

def aws_secret_key
  @aws_secret_key
end

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/amazon_email.rb', line 4

def body
  @body
end

#fromObject

Returns the value of attribute from.



4
5
6
# File 'lib/amazon_email.rb', line 4

def from
  @from
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'lib/amazon_email.rb', line 4

def subject
  @subject
end

#templateObject

Returns the value of attribute template.



4
5
6
# File 'lib/amazon_email.rb', line 4

def template
  @template
end

#toObject

Returns the value of attribute to.



4
5
6
# File 'lib/amazon_email.rb', line 4

def to
  @to
end

Instance Method Details

#build_email_bodyObject



20
21
22
23
24
# File 'lib/amazon_email.rb', line 20

def build_email_body
  if self.template
    self.body = ERB.new(self.template).result(self.get_binding)
  end
end

#get_bindingObject



16
17
18
# File 'lib/amazon_email.rb', line 16

def get_binding
  binding
end

#sendObject



26
27
28
29
30
31
32
33
# File 'lib/amazon_email.rb', line 26

def send
  build_email_body
  if self.to.class == Array
    self.send_to_many
  else
    AmazonDeliver.get(self)
  end
end

#send_to_manyObject



35
36
37
38
39
40
41
# File 'lib/amazon_email.rb', line 35

def send_to_many
  email_list = self.to
  email_list.each do |e|
    self.to = e
    AmazonDeliver.get(self)
  end
end