Class: Idcf::Dns::Response
- Inherits:
-
Object
- Object
- Idcf::Dns::Response
- Extended by:
- Forwardable
- Defined in:
- lib/idcf/dns/response.rb
Overview
HTTP response
Instance Attribute Summary collapse
-
#body ⇒ Hash, ...
readonly
Response body as a hash, an array of hashes or nil.
-
#headers ⇒ Hash
readonly
HTTP response headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#count ⇒ Fixnum
(also: #size)
Returns the number of resources.
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
-
#message ⇒ String
Returns error message.
-
#reference ⇒ String
Returns error reference.
-
#resources ⇒ Array<Hash>
Returns an array of resource hashes.
-
#success? ⇒ Boolean
Request success?.
-
#uuid ⇒ String
UUID of a resource.
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of 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
#body ⇒ Hash, ... (readonly)
Returns response body as a hash, an array of hashes or nil.
16 17 18 |
# File 'lib/idcf/dns/response.rb', line 16 def body @body end |
#headers ⇒ Hash (readonly)
Returns HTTP response headers.
16 |
# File 'lib/idcf/dns/response.rb', line 16 attr_reader :body, :headers, :status |
#status ⇒ Object (readonly)
Returns the value of attribute status.
16 |
# File 'lib/idcf/dns/response.rb', line 16 attr_reader :body, :headers, :status |
Instance Method Details
#count ⇒ Fixnum 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 |
#message ⇒ String
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 if success? nil else body ? self["message"] : "Resource not found." end end |
#reference ⇒ String
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 |
#resources ⇒ Array<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
Returns request success?.
74 75 76 |
# File 'lib/idcf/dns/response.rb', line 74 def success? status < 400 end |
#uuid ⇒ String
Returns UUID of a resource.
79 80 81 |
# File 'lib/idcf/dns/response.rb', line 79 def uuid body.is_a?(Hash) && body.key?("uuid") ? self["uuid"] : nil end |