Class: Journeybook::PostmarkClient
- Inherits:
-
Object
- Object
- Journeybook::PostmarkClient
- Defined in:
- app/services/journeybook/postmark_client.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- ENDPOINT =
URI("https://api.postmarkapp.com/email")
Instance Method Summary collapse
-
#initialize(api_key: Journeybook.configuration.postmark_api_key, endpoint: ENDPOINT) ⇒ PostmarkClient
constructor
A new instance of PostmarkClient.
- #send_email(from:, to:, subject:, text_body:, reply_to: nil) ⇒ Object
Constructor Details
#initialize(api_key: Journeybook.configuration.postmark_api_key, endpoint: ENDPOINT) ⇒ PostmarkClient
Returns a new instance of PostmarkClient.
11 12 13 14 |
# File 'app/services/journeybook/postmark_client.rb', line 11 def initialize(api_key: Journeybook.configuration.postmark_api_key, endpoint: ENDPOINT) @api_key = api_key @endpoint = endpoint end |
Instance Method Details
#send_email(from:, to:, subject:, text_body:, reply_to: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/services/journeybook/postmark_client.rb', line 16 def send_email(from:, to:, subject:, text_body:, reply_to: nil) response = Net::HTTP.start(@endpoint.host, @endpoint.port, use_ssl: @endpoint.scheme == "https") do |http| http.request(request(from:, to:, subject:, text_body:, reply_to:)) end return response if response.is_a?(Net::HTTPSuccess) raise Error, "Postmark delivery failed: #{response.code} #{response.body}" end |