Class: ClientResponse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#emailObject (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

#statusObject (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_reqObject



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_errObject



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_okObject



13
14
15
# File 'lib/email_api/email/data/client_response.rb', line 13

def set_ok
  @status = '200: OK'
end

#to_hashObject



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