Class: Poodle::EmailResponse
- Inherits:
-
Object
- Object
- Poodle::EmailResponse
- Defined in:
- lib/poodle/email_response.rb
Overview
Email response model representing the API response for email operations
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Additional response data.
-
#message ⇒ String
readonly
Response message from the API.
-
#success ⇒ Boolean
readonly
Whether the email was successfully queued.
Class Method Summary collapse
-
.from_api_response(response_data) ⇒ EmailResponse
Create an EmailResponse from API response data.
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Check if email sending failed.
-
#initialize(success:, message:, data: {}) ⇒ EmailResponse
constructor
Initialize a new EmailResponse.
-
#inspect ⇒ String
Get detailed string representation for debugging.
-
#success? ⇒ Boolean
Check if email was successfully queued.
-
#to_h ⇒ Hash
Convert response to hash.
-
#to_json(*args) ⇒ String
Convert response to JSON string.
-
#to_s ⇒ String
Get a string representation of the response.
Constructor Details
#initialize(success:, message:, data: {}) ⇒ EmailResponse
Initialize a new EmailResponse
33 34 35 36 37 38 |
# File 'lib/poodle/email_response.rb', line 33 def initialize(success:, message:, data: {}) @success = success = @data = data freeze # Make the object immutable end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns additional response data.
26 27 28 |
# File 'lib/poodle/email_response.rb', line 26 def data @data end |
#message ⇒ String (readonly)
Returns response message from the API.
23 24 25 |
# File 'lib/poodle/email_response.rb', line 23 def end |
#success ⇒ Boolean (readonly)
Returns whether the email was successfully queued.
20 21 22 |
# File 'lib/poodle/email_response.rb', line 20 def success @success end |
Class Method Details
.from_api_response(response_data) ⇒ EmailResponse
Create an EmailResponse from API response data
44 45 46 47 48 49 50 |
# File 'lib/poodle/email_response.rb', line 44 def self.from_api_response(response_data) new( success: response_data[:success] || response_data["success"] || false, message: response_data[:message] || response_data["message"] || "", data: response_data ) end |
Instance Method Details
#failed? ⇒ Boolean
Check if email sending failed
62 63 64 |
# File 'lib/poodle/email_response.rb', line 62 def failed? !@success end |
#inspect ⇒ String
Get detailed string representation for debugging
96 97 98 99 |
# File 'lib/poodle/email_response.rb', line 96 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ "success=#{@success} message=#{@message.inspect} data=#{@data.inspect}>" end |
#success? ⇒ Boolean
Check if email was successfully queued
55 56 57 |
# File 'lib/poodle/email_response.rb', line 55 def success? @success end |
#to_h ⇒ Hash
Convert response to hash
69 70 71 72 73 74 75 |
# File 'lib/poodle/email_response.rb', line 69 def to_h { success: @success, message: , data: @data } end |
#to_json(*args) ⇒ String
Convert response to JSON string
80 81 82 83 |
# File 'lib/poodle/email_response.rb', line 80 def to_json(*args) require "json" to_h.to_json(*args) end |
#to_s ⇒ String
Get a string representation of the response
88 89 90 91 |
# File 'lib/poodle/email_response.rb', line 88 def to_s status = @success ? "SUCCESS" : "FAILED" "EmailResponse[#{status}]: #{@message}" end |