Class: ClientResponse
- Inherits:
-
Object
- Object
- ClientResponse
- Defined in:
- lib/email_api/email/data/client_response.rb
Overview
Defines response returned by EmailClient and is used in the API’s output
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(email = EmailObject.new, status = 'UNDEFINED') ⇒ ClientResponse
constructor
A new instance of ClientResponse.
- #set_bad_req ⇒ Object
- #set_internal_err ⇒ Object
- #set_ok ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(email = EmailObject.new, status = 'UNDEFINED') ⇒ ClientResponse
Returns a new instance of ClientResponse.
8 9 10 11 |
# File 'lib/email_api/email/data/client_response.rb', line 8 def initialize(email = EmailObject.new, status = 'UNDEFINED') @email = email @status = status end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
5 6 7 |
# File 'lib/email_api/email/data/client_response.rb', line 5 def email @email end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/email_api/email/data/client_response.rb', line 6 def status @status end |
Instance Method Details
#==(other) ⇒ Object
25 26 27 28 |
# File 'lib/email_api/email/data/client_response.rb', line 25 def ==(other) return false unless other.respond_to?(:to_hash) to_hash == other.to_hash end |
#set_bad_req ⇒ Object
17 18 19 |
# File 'lib/email_api/email/data/client_response.rb', line 17 def set_bad_req @status = '400: BAD REQUEST' end |
#set_internal_err ⇒ Object
21 22 23 |
# File 'lib/email_api/email/data/client_response.rb', line 21 def set_internal_err @status = '500: INTERNAL SERVER ERROR' end |
#set_ok ⇒ Object
13 14 15 |
# File 'lib/email_api/email/data/client_response.rb', line 13 def set_ok @status = '200: OK' end |
#to_hash ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/email_api/email/data/client_response.rb', line 30 def to_hash hash = {} instance_variables.each do |var| name = var.to_s.delete('@') value = instance_variable_get(var) val_hash = value.to_hash if value.respond_to?(:to_hash) hash[name] = val_hash.nil? ? value : val_hash end hash end |