Class: Journeybook::PostmarkClient

Inherits:
Object
  • Object
show all
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

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

Raises:



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