Class: TMS::Mail::DeliveryMethod
- Inherits:
-
Object
- Object
- TMS::Mail::DeliveryMethod
- Includes:
- Mail::CheckDeliveryParams
- Defined in:
- lib/tms_client/mail/delivery_method.rb
Overview
Use TMS from the mail gem or ActionMailer as a delivery method.
# Gemfile
gem 'tms_client', :require=>'tms_client/mail/delivery_method'
# config/environment.rb
config.action_mailer.delivery_method = :govdelivery_tms
config.action_mailer.govdelivery_tms_settings = {
:auth_token=>'auth_token',
:api_root=>'https://stage-tms.govdelivery.com'
}
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #client ⇒ Object
- #deliver!(mail) ⇒ Object
-
#initialize(values) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(values) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
20 21 22 |
# File 'lib/tms_client/mail/delivery_method.rb', line 20 def initialize(values) self.settings = values end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
24 25 26 |
# File 'lib/tms_client/mail/delivery_method.rb', line 24 def settings @settings end |
Instance Method Details
#client ⇒ Object
43 44 45 |
# File 'lib/tms_client/mail/delivery_method.rb', line 43 def client @client ||= TMS::Client.new(settings[:auth_token], settings) end |
#deliver!(mail) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tms_client/mail/delivery_method.rb', line 26 def deliver!(mail) #check_params(mail) raise TMS::Errors::NoRelation.new('email_messages', client) unless client.respond_to?(:email_messages) envelope_from = mail.return_path || mail.sender || mail.from_addrs.first = client..build( :from_name => mail[:from].display_names.first, :subject => mail.subject, :body => (mail.body || mail.html_part.body || mail.text_part.body).to_s ) mail.to.each { |recip| .recipients.build(:email => recip) } .post! end |