Class: Idcf::Dns::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/idcf/dns/response.rb

Overview

HTTP response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ Response



19
20
21
22
23
# File 'lib/idcf/dns/response.rb', line 19

def initialize(faraday_response)
  @body    = faraday_response.body
  @headers = faraday_response.headers
  @status  = faraday_response.status
end

Instance Attribute Details

#bodyHash, ... (readonly)



16
17
18
# File 'lib/idcf/dns/response.rb', line 16

def body
  @body
end

#headersHash (readonly)



16
# File 'lib/idcf/dns/response.rb', line 16

attr_reader :body, :headers, :status

#statusObject (readonly)

Returns the value of attribute status.



16
# File 'lib/idcf/dns/response.rb', line 16

attr_reader :body, :headers, :status

Instance Method Details

#countFixnum Also known as: size

Returns the number of resources.



30
31
32
33
34
35
36
37
38
39
# File 'lib/idcf/dns/response.rb', line 30

def count
  case body
  when Array
    body.size
  when Hash
    body.key?("uuid") ? 1 : 0
  else
    0
  end
end

#messageString

Returns error message. When request succeed, this returns nil.



46
47
48
49
50
51
52
# File 'lib/idcf/dns/response.rb', line 46

def message
  if success?
    nil
  else
    body ? self["message"] : "Resource not found."
  end
end

#referenceString

Returns error reference. When request succeed, this returns nil.



58
59
60
61
62
63
64
# File 'lib/idcf/dns/response.rb', line 58

def reference
  if success?
    nil
  else
    body ? self["reference"] : "No reference"
  end
end

#resourcesArray<Hash>

Returns an array of resource hashes.



69
70
71
# File 'lib/idcf/dns/response.rb', line 69

def resources
  body && [*body]
end

#success?Boolean



74
75
76
# File 'lib/idcf/dns/response.rb', line 74

def success?
  status < 400
end

#uuidString



79
80
81
# File 'lib/idcf/dns/response.rb', line 79

def uuid
  body.is_a?(Hash) && body.key?("uuid") ? self["uuid"] : nil
end