Class: MailMaleMail::PostalService::DeliveryMethod
- Inherits:
-
Object
- Object
- MailMaleMail::PostalService::DeliveryMethod
- Defined in:
- lib/mail_male_mail/postal_service/delivery_method.rb
Defined Under Namespace
Classes: InvalidOption
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.
21 22 23 24 25 26 |
# File 'lib/mail_male_mail/postal_service/delivery_method.rb', line 21 def initialize( = {}) unless [:url].present? || [:method].present? raise InvalidOption, "A url or method option is required to send email using the Postal Service delivery method" end self.settings = end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
20 21 22 |
# File 'lib/mail_male_mail/postal_service/delivery_method.rb', line 20 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
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 |
# File 'lib/mail_male_mail/postal_service/delivery_method.rb', line 27 def deliver!(mail) = [:to, :cc, :bcc].reduce({}) do |a, e| val = mail.public_send(e) a[e] = val.join(",") if val.present? a end [:subject] = mail.subject.to_s [:from] = mail.from.first.to_s [:extra_provider_data] = ActiveSupport::JSON.decode(mail.header['X-PostalService-Data'].to_s) if mail.header['X-PostalService-Data'] if mail.header['X-PostalService-Provider'] [:provider] = mail.header['X-PostalService-Provider'].to_s elsif self.settings[:provider] [:provider] = self.settings[:provider] end [:category] = mail.header['X-PostalService-Category'].to_s if mail.header['X-PostalService-Category'] [:text] = mail.text_part.body.to_s if mail.text_part [:html] = mail.html_part.body.to_s if mail.html_part unless mail.text_part || mail.html_part part = mail.content_type =~ /html/ ? :html : :text [part] = mail.body.to_s end MailMaleMail::PostalService.api_request(self.settings, ) end |