Class: PostmarkClient::EmailResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/postmark_client/models/email_response.rb

Overview

Represents a response from the Postmark Email API. Wraps the API response in a convenient Ruby object.

Examples:

Handling a successful response

response = client.send_email(email)
puts "Message ID: #{response.message_id}"
puts "Submitted at: #{response.submitted_at}"

Checking for errors

if response.success?
  puts "Email sent successfully!"
else
  puts "Error: #{response.message}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ EmailResponse

Initialize from API response hash

Parameters:

  • response (Hash)

    the API response



40
41
42
43
44
45
46
47
# File 'lib/postmark_client/models/email_response.rb', line 40

def initialize(response)
  @raw_response = response
  @to = response["To"]
  @submitted_at = parse_timestamp(response["SubmittedAt"])
  @message_id = response["MessageID"]
  @error_code = response["ErrorCode"]
  @message = response["Message"]
end

Instance Attribute Details

#error_codeInteger (readonly)

Returns error code (0 means success).

Returns:

  • (Integer)

    error code (0 means success)



29
30
31
# File 'lib/postmark_client/models/email_response.rb', line 29

def error_code
  @error_code
end

#messageString (readonly)

Returns response message.

Returns:

  • (String)

    response message



32
33
34
# File 'lib/postmark_client/models/email_response.rb', line 32

def message
  @message
end

#message_idString (readonly)

Returns unique message identifier.

Returns:

  • (String)

    unique message identifier



26
27
28
# File 'lib/postmark_client/models/email_response.rb', line 26

def message_id
  @message_id
end

#raw_responseHash (readonly)

Returns raw response data.

Returns:

  • (Hash)

    raw response data



35
36
37
# File 'lib/postmark_client/models/email_response.rb', line 35

def raw_response
  @raw_response
end

#submitted_atTime (readonly)

Returns timestamp when the email was submitted.

Returns:

  • (Time)

    timestamp when the email was submitted



23
24
25
# File 'lib/postmark_client/models/email_response.rb', line 23

def 
  @submitted_at
end

#toString (readonly)

Returns recipient email address.

Returns:

  • (String)

    recipient email address



20
21
22
# File 'lib/postmark_client/models/email_response.rb', line 20

def to
  @to
end

Instance Method Details

#error?Boolean

Check if there was an error

Returns:

  • (Boolean)

    true if error_code is not 0



59
60
61
# File 'lib/postmark_client/models/email_response.rb', line 59

def error?
  !success?
end

#success?Boolean

Check if the email was sent successfully

Returns:

  • (Boolean)

    true if error_code is 0



52
53
54
# File 'lib/postmark_client/models/email_response.rb', line 52

def success?
  error_code == 0
end

#to_sString

Get a string representation of the response

Returns:

  • (String)

    human-readable response summary



66
67
68
69
70
71
72
# File 'lib/postmark_client/models/email_response.rb', line 66

def to_s
  if success?
    "Email sent to #{to} (Message ID: #{message_id})"
  else
    "Error #{error_code}: #{message}"
  end
end