Class: LaunchControl::Mailer
- Inherits:
-
Object
- Object
- LaunchControl::Mailer
- Defined in:
- lib/launch_control.rb
Overview
To start using Launch Control, you first need to create a contract class, i.e.:
class ThankyouEmail < LaunchControl::MandrillContract
def template
'thank-you'
end
def validations
{
first_name: 'string',
last_name: 'string'
}
end
end
Define global merge vars to integrate with your Mandrill template:
mailer = ThankyouEmail.new
mailer.deliver(to: '[email protected]', subject: 'Bring it home safely', first_name: 'Pastor', last_name: 'Maldonado')
=> true
Now if you try and deliver this without the appropriate content, you’ll be pulled up on it:
mailer.deliver(to: '[email protected]', subject: 'I know what I\'m doing', first_name: 'Kimi')
=> false
mailer.errors
=> {:last_name=>"string required"}
Instance Attribute Summary collapse
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#cc ⇒ Object
Returns the value of attribute cc.
-
#from_email ⇒ Object
Returns the value of attribute from_email.
-
#from_name ⇒ Object
Returns the value of attribute from_name.
-
#merge_vars ⇒ Object
Returns the value of attribute merge_vars.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#status ⇒ Object
Returns the value of attribute status.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(template_id, options) ⇒ Mailer
constructor
A new instance of Mailer.
- #mandrill ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(template_id, options) ⇒ Mailer
Returns a new instance of Mailer.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/launch_control.rb', line 46 def initialize(template_id, ) = .dup raise 'Please configure your Mandrill API key before trying to deliver emails.' if LaunchControl.configuration.mandrill_api_key.nil? @template_id = template_id @to = .delete(:to) @cc = .delete(:cc) @bcc = .delete(:bcc) @from_name = .delete(:from_name) @from_email = .delete(:from_email) @reply_to = .delete(:reply_to) @subject = .delete(:subject) @attachments = .delete(:attachments) || [] @merge_vars = end |
Instance Attribute Details
#bcc ⇒ Object
Returns the value of attribute bcc.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def bcc @bcc end |
#cc ⇒ Object
Returns the value of attribute cc.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def cc @cc end |
#from_email ⇒ Object
Returns the value of attribute from_email.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def from_email @from_email end |
#from_name ⇒ Object
Returns the value of attribute from_name.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def from_name @from_name end |
#merge_vars ⇒ Object
Returns the value of attribute merge_vars.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def merge_vars @merge_vars end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def reply_to @reply_to end |
#status ⇒ Object
Returns the value of attribute status.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def status @status end |
#subject ⇒ Object
Returns the value of attribute subject.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def subject @subject end |
#template_id ⇒ Object
Returns the value of attribute template_id.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def template_id @template_id end |
#to ⇒ Object
Returns the value of attribute to.
43 44 45 |
# File 'lib/launch_control.rb', line 43 def to @to end |
Instance Method Details
#deliver ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/launch_control.rb', line 67 def deliver if valid? response = mandrill..send_template(@template_id, [], , false) @status = response[0]["status"] ["sent", "queued", "scheduled"].include?(@status) end end |
#mandrill ⇒ Object
63 64 65 |
# File 'lib/launch_control.rb', line 63 def mandrill @mandrill ||= Mandrill::API.new(LaunchControl.configuration.mandrill_api_key) end |
#valid? ⇒ Boolean
75 76 77 |
# File 'lib/launch_control.rb', line 75 def valid? !!(@to && @subject && @template_id) end |