Class: PostmarkClient::EmailResponse
- Inherits:
-
Object
- Object
- PostmarkClient::EmailResponse
- 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.
Instance Attribute Summary collapse
-
#error_code ⇒ Integer
readonly
Error code (0 means success).
-
#message ⇒ String
readonly
Response message.
-
#message_id ⇒ String
readonly
Unique message identifier.
-
#raw_response ⇒ Hash
readonly
Raw response data.
-
#submitted_at ⇒ Time
readonly
Timestamp when the email was submitted.
-
#to ⇒ String
readonly
Recipient email address.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Check if there was an error.
-
#initialize(response) ⇒ EmailResponse
constructor
Initialize from API response hash.
-
#success? ⇒ Boolean
Check if the email was sent successfully.
-
#to_s ⇒ String
Get a string representation of the response.
Constructor Details
#initialize(response) ⇒ EmailResponse
Initialize from API response hash
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 = (response["SubmittedAt"]) = response["MessageID"] @error_code = response["ErrorCode"] = response["Message"] end |
Instance Attribute Details
#error_code ⇒ Integer (readonly)
Returns error code (0 means success).
29 30 31 |
# File 'lib/postmark_client/models/email_response.rb', line 29 def error_code @error_code end |
#message ⇒ String (readonly)
Returns response message.
32 33 34 |
# File 'lib/postmark_client/models/email_response.rb', line 32 def end |
#message_id ⇒ String (readonly)
Returns unique message identifier.
26 27 28 |
# File 'lib/postmark_client/models/email_response.rb', line 26 def end |
#raw_response ⇒ Hash (readonly)
Returns raw response data.
35 36 37 |
# File 'lib/postmark_client/models/email_response.rb', line 35 def raw_response @raw_response end |
#submitted_at ⇒ Time (readonly)
Returns timestamp when the email was submitted.
23 24 25 |
# File 'lib/postmark_client/models/email_response.rb', line 23 def submitted_at @submitted_at end |
#to ⇒ String (readonly)
Returns 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
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
52 53 54 |
# File 'lib/postmark_client/models/email_response.rb', line 52 def success? error_code == 0 end |
#to_s ⇒ String
Get a string representation of the response
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 |