Class: Hyperclient::Response

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

Constructor Details

#initialize(response) ⇒ Response

Initializes a Response.

Parameters:

  • response

    A Hash representing the response from the API.



12
13
14
# File 'lib/hyperclient/response.rb', line 12

def initialize(response)
  @response = response
end

Instance Method Details

#attributesObject

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

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

#resourcesObject

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
  @embedded ||= Discoverer.new(@response['_embedded'])
end

#urlObject

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