Class: SendGridActionMailerAdapter::DeliveryMethod
- Inherits:
-
Object
- Object
- SendGridActionMailerAdapter::DeliveryMethod
- Defined in:
- lib/sendgrid_actionmailer_adapter/delivery_method.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#deliver!(mail) ⇒ Object
Deliver a mail via SendGrid Web API.
-
#initialize(settings) ⇒ DeliveryMethod
constructor
Initialize this instance.
Constructor Details
#initialize(settings) ⇒ DeliveryMethod
Initialize this instance.
This method is expected to be called from Mail::Message class.
23 24 25 |
# File 'lib/sendgrid_actionmailer_adapter/delivery_method.rb', line 23 def initialize(settings) @settings = ::SendGridActionMailerAdapter::Configuration.settings.merge(settings) end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
10 11 12 |
# File 'lib/sendgrid_actionmailer_adapter/delivery_method.rb', line 10 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
Deliver a mail via SendGrid Web API.
This method is called from Mail::Message#deliver!.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sendgrid_actionmailer_adapter/delivery_method.rb', line 34 def deliver!(mail) sendgrid_mail = ::SendGridActionMailerAdapter::Converter.to_sendgrid_mail(mail) body = sendgrid_mail.to_json client = ::SendGrid::API.new(@settings[:sendgrid]).client.mail._('send') with_retry(@settings[:retry]) do response = client.post(request_body: body) handle_response!(response) end end |