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.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/multi_mail/mandrill/sender.rb', line 22 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) unless @send_at.nil? or 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 |
Instance Method Details
#deliver!(mail) ⇒ Object
Delivers a message via the Mandrill API.
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 87 88 89 90 91 92 93 |
# File 'lib/multi_mail/mandrill/sender.rb', line 62 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/multi_mail/mandrill/sender.rb', line 36 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 |