Class: Hyperclient::Response
- Inherits:
-
Object
- Object
- Hyperclient::Response
- Defined in:
- lib/hyperclient/response.rb
Overview
This class is responsible for parsing a response from the API and exposing some methods to access its values.
It is mainly used by Hyperclient::Resource.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns a Hash with the attributes of the resource.
-
#initialize(response) ⇒ Response
constructor
Initializes a Response.
-
#links ⇒ Object
Returns a Discoverer for the _links section of the response.
-
#resources ⇒ Object
Returns a Discoverer for the _embedded section of the response.
-
#url ⇒ Object
Returns a String with the resource URL or nil of it does not have one.
Constructor Details
#initialize(response) ⇒ Response
Initializes a Response.
12 13 14 |
# File 'lib/hyperclient/response.rb', line 12 def initialize(response) @response = response end |
Instance Method Details
#attributes ⇒ Object
Returns a Hash with the attributes of the resource.
29 30 31 |
# File 'lib/hyperclient/response.rb', line 29 def attributes @attributes ||= @response.dup.delete_if {|key, value| key =~ /^_/} end |
#links ⇒ Object
Returns a Discoverer for the _links section of the response. It can be used later to use the resources from this section.
18 19 20 |
# File 'lib/hyperclient/response.rb', line 18 def links @links ||= Discoverer.new(@response['_links']) end |
#resources ⇒ Object
Returns a Discoverer for the _embedded section of the response. It can be used later to use the resources from this section.
24 25 26 |
# File 'lib/hyperclient/response.rb', line 24 def resources ||= Discoverer.new(@response['_embedded']) end |
#url ⇒ Object
Returns a String with the resource URL or nil of it does not have one.
35 36 37 38 39 40 |
# File 'lib/hyperclient/response.rb', line 35 def url if @response && @response['_links'] && @response['_links']['self'] && (url = @response['_links']['self']['href']) return url end end |