Class: PlunkMail::DeliveryMethod
- Inherits:
-
Object
- Object
- PlunkMail::DeliveryMethod
- Defined in:
- lib/plunk_mail/delivery_method.rb
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(settings = {}) ⇒ DeliveryMethod
constructor
A new instance of DeliveryMethod.
Constructor Details
#initialize(settings = {}) ⇒ DeliveryMethod
Returns a new instance of DeliveryMethod.
5 6 7 |
# File 'lib/plunk_mail/delivery_method.rb', line 5 def initialize(settings = {}) @api_key = settings[:api_key] end |
Instance Method Details
#deliver!(mail) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/plunk_mail/delivery_method.rb', line 9 def deliver!(mail) response = Faraday.post( "https://next-api.useplunk.com/v1/send", { to: mail.to.first, subject: mail.subject, body: email_body(mail), from: { name: mail[:from]&.display_names&.first, email: mail.from.first }.compact }.to_json, { "Authorization" => "Bearer #{@api_key}", "Content-Type" => "application/json" } ) raise "Plunk error: #{response.status} #{response.body}" unless response.success? response end |