Class: Poodle::EmailResponse

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

Overview

Email response model representing the API response for email operations

Examples:

Checking response status

response = client.send_email(email)
if response.success?
  puts "Email sent: #{response.message}"
else
  puts "Failed: #{response.message}"
end

Converting to hash

response_data = response.to_h
puts response_data[:success]
puts response_data[:message]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, message:, data: {}) ⇒ EmailResponse

Initialize a new EmailResponse

Parameters:

  • success (Boolean)

    whether the operation was successful

  • message (String)

    response message

  • data (Hash) (defaults to: {})

    additional response data



33
34
35
36
37
38
# File 'lib/poodle/email_response.rb', line 33

def initialize(success:, message:, data: {})
  @success = success
  @message = message
  @data = data
  freeze # Make the object immutable
end

Instance Attribute Details

#dataHash (readonly)

Returns additional response data.

Returns:

  • (Hash)

    additional response data



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

def data
  @data
end

#messageString (readonly)

Returns response message from the API.

Returns:

  • (String)

    response message from the API



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

def message
  @message
end

#successBoolean (readonly)

Returns whether the email was successfully queued.

Returns:

  • (Boolean)

    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

Parameters:

  • response_data (Hash)

    the API response data

Returns:



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

Returns:

  • (Boolean)

    true if failed



62
63
64
# File 'lib/poodle/email_response.rb', line 62

def failed?
  !@success
end

#inspectString

Get detailed string representation for debugging

Returns:

  • (String)

    detailed response information



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

Returns:

  • (Boolean)

    true if successful



55
56
57
# File 'lib/poodle/email_response.rb', line 55

def success?
  @success
end

#to_hHash

Convert response to hash

Returns:

  • (Hash)

    response data as hash



69
70
71
72
73
74
75
# File 'lib/poodle/email_response.rb', line 69

def to_h
  {
    success: @success,
    message: @message,
    data: @data
  }
end

#to_json(*args) ⇒ String

Convert response to JSON string

Returns:

  • (String)

    response data as JSON



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_sString

Get a string representation of the response

Returns:

  • (String)

    formatted response information



88
89
90
91
# File 'lib/poodle/email_response.rb', line 88

def to_s
  status = @success ? "SUCCESS" : "FAILED"
  "EmailResponse[#{status}]: #{@message}"
end