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.
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.
Constructor Details
#initialize(options = {}) ⇒ Mandrill
Initializes a Mandrill outgoing email sender.
18 19 20 21 22 23 24 |
# File 'lib/multi_mail/mandrill/sender.rb', line 18 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) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def api_key @api_key end |
#async ⇒ Object (readonly)
Returns the value of attribute async.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def async @async end |
#ip_pool ⇒ Object (readonly)
Returns the value of attribute ip_pool.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def ip_pool @ip_pool end |
#send_at ⇒ Object (readonly)
Returns the value of attribute send_at.
11 12 13 |
# File 'lib/multi_mail/mandrill/sender.rb', line 11 def send_at @send_at end |
Instance Method Details
#deliver!(mail) ⇒ Object
Delivers a message via the Mandrill API.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/multi_mail/mandrill/sender.rb', line 55 def deliver!(mail) = MultiMail::Message::Mandrill.new(mail).to_mandrill_hash.merge(parameters) response = Faraday.post('https://mandrillapp.com/api/1.0/messages/send.json', JSON.dump({ :key => api_key, :message => , :async => async, :ip_pool => ip_pool, :send_at => send_at, })) body = JSON.load(response.body) unless response.status == 200 if body['status'] == 'error' case body['name'] when 'Invalid_Key' raise InvalidAPIKey, body['message'] else raise 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/multi_mail/mandrill/sender.rb', line 29 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 |