Class: MandrillAPIDeliveryMethod::DeliveryMethod
- Inherits:
-
Object
- Object
- MandrillAPIDeliveryMethod::DeliveryMethod
- Defined in:
- lib/mandrill_api_delivery_method/delivery_method.rb
Defined Under Namespace
Classes: InvalidOption
Constant Summary collapse
- @@deliveries =
[]
Class Attribute Summary collapse
-
.deliveries ⇒ Object
Returns the value of attribute deliveries.
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(options = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(options = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
14 15 16 17 |
# File 'lib/mandrill_api_delivery_method/delivery_method.rb', line 14 def initialize( = {}) raise InvalidOption, "An API key is required when using the Mandrill API delivery method" if [:api_key].nil? self.settings = end |
Class Attribute Details
.deliveries ⇒ Object
Returns the value of attribute deliveries.
9 10 11 |
# File 'lib/mandrill_api_delivery_method/delivery_method.rb', line 9 def deliveries @deliveries end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
12 13 14 |
# File 'lib/mandrill_api_delivery_method/delivery_method.rb', line 12 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mandrill_api_delivery_method/delivery_method.rb', line 19 def deliver!(mail) begin mandrill = Mandrill::API.new self.settings[:api_key] = mail. || {} unless .has_key? :subject [:subject] = mail.subject end unless .has_key? :from_email [:from_email] = mail.from.first end unless .has_key? :to [:to] = [] mail.to.each do |email_address| [:to] << {email: email_address} end end if not mail.text_part.nil? [:text] = mail.text_part.body.to_s end if not mail.html_part.nil? [:html] = mail.html_part.body.to_s end async = false send_at = mail.deliver_at.nil? ? Time.now.utc.to_s : mail.deliver_at.uts.to_s result = mandrill..send , async, nil, send_at if self.settings[:test] self.class.deliveries << result end rescue Mandrill::Error => e puts "Error delivering mail to Mandrill API: #{e.class} - #{e.}" raise end end |