Class: MultiMail::Sender::Mandrill
- Inherits:
-
Object
- Object
- MultiMail::Sender::Mandrill
- Includes:
- Base
- Defined in:
- lib/multi_mail/mandrill/sender.rb
Overview
Mandrill's outgoing mail sender.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#async ⇒ Object
readonly
Returns the value of attribute async.
-
#ip_pool ⇒ Object
readonly
Returns the value of attribute ip_pool.
-
#send_at ⇒ Object
readonly
Returns the value of attribute send_at.
-
#template_content ⇒ Object
Returns the value of attribute template_content.
-
#template_name ⇒ Object
Returns the value of attribute template_name.
Attributes included from Base
Instance Method Summary collapse
-
#deliver!(mail) ⇒ Object
Delivers a message via the Mandrill API.
-
#initialize(options = {}) ⇒ Mandrill
constructor
Initializes a Mandrill outgoing email sender.
-
#parameters ⇒ Hash
Returns the additional parameters for the API call.
Methods included from Base
Constructor Details
#initialize(options = {}) ⇒ Mandrill
Initializes a Mandrill outgoing email sender.
"content"
key for the content to inject
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/multi_mail/mandrill/sender.rb', line 29 def initialize( = {}) super @api_key = settings.delete(:api_key) @async = settings.delete(:async) || false @ip_pool = settings.delete(:ip_pool) @send_at = settings.delete(:send_at) @template_name = settings.delete(:template_name) @template_content = settings.delete(:template_content) unless @send_at.nil? || String === @send_at @send_at = @send_at.utc.strftime('%Y-%m-%d %T') end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/multi_mail/mandrill/sender.rb', line 9 def api_key @api_key end |
#async ⇒ Object (readonly)
Returns the value of attribute async.
9 10 11 |
# File 'lib/multi_mail/mandrill/sender.rb', line 9 def async @async end |
#ip_pool ⇒ Object (readonly)
Returns the value of attribute ip_pool.
9 10 11 |
# File 'lib/multi_mail/mandrill/sender.rb', line 9 def ip_pool @ip_pool end |
#send_at ⇒ Object (readonly)
Returns the value of attribute send_at.
9 10 11 |
# File 'lib/multi_mail/mandrill/sender.rb', line 9 def send_at @send_at end |
#template_content ⇒ Object
Returns the value of attribute template_content.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def template_content @template_content end |
#template_name ⇒ Object
Returns the value of attribute template_name.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def template_name @template_name end |
Instance Method Details
#deliver!(mail) ⇒ Object
Delivers a message via the Mandrill API.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/multi_mail/mandrill/sender.rb', line 71 def deliver!(mail) = MultiMail::Message::Mandrill.new(mail).to_mandrill_hash.merge(parameters) api_params = { :key => api_key, :message => , :async => async, :ip_pool => ip_pool, :send_at => send_at, } if template_name api_method = 'send-template' api_params[:template_name] = template_name api_params[:template_content] = template_content else api_method = 'send' end response = Faraday.post("https://mandrillapp.com/api/1.0/messages/#{api_method}.json", JSON.dump(api_params)) body = JSON.load(response.body) unless response.status == 200 if body['status'] == 'error' case body['name'] when 'Invalid_Key' raise InvalidAPIKey, body['message'] when 'Unknown_Template' raise InvalidTemplate, body['message'] else raise "#{body['name']}: #{body['message']}" end else raise body['message'] end end if settings[:return_response] body else self end end |
#parameters ⇒ Hash
Returns the additional parameters for the API call.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/multi_mail/mandrill/sender.rb', line 45 def parameters parameters = settings.dup parameters.delete(:return_response) [:opens, :clicks].each do |sym| if tracking.key?(sym) parameter = :"track_#{sym}" case tracking[sym] when true, false, nil parameters[parameter] = tracking[sym] when 'yes' parameters[parameter] = true when 'no' parameters[parameter] = false end # ignore "htmlonly" end end parameters end |