Class: Hyperclient::Resource
- Inherits:
-
Object
- Object
- Hyperclient::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/hyperclient/resource.rb
Overview
Represents a resource from your API. Its responsability is to ease the way you access its attributes, links and embedded resources.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the attributes of the Resource as Attributes.
-
#embedded ⇒ Object
readonly
Returns the embedded resource of the Resource as a ResourceCollection.
-
#links ⇒ Object
readonly
Returns the links of the Resource as a LinkCollection.
-
#response ⇒ Object
readonly
Returns the response object for the HTTP request that created this resource, if one exists.
Instance Method Summary collapse
-
#initialize(representation, entry_point, response = nil) ⇒ Resource
constructor
Initializes a Resource.
- #inspect ⇒ Object
-
#self_link ⇒ Object
private
private
Returns the self Link of the Resource.
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(representation, entry_point, response = nil) ⇒ Resource
Initializes a Resource.
34 35 36 37 38 39 40 41 |
# File 'lib/hyperclient/resource.rb', line 34 def initialize(representation, entry_point, response=nil) representation = representation ? representation.dup : {} @links = LinkCollection.new(representation['_links'], entry_point) = ResourceCollection.new(representation['_embedded'], entry_point) @attributes = Attributes.new(representation) @entry_point = entry_point @response = response end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the attributes of the Resource as Attributes.
13 14 15 |
# File 'lib/hyperclient/resource.rb', line 13 def attributes @attributes end |
#embedded ⇒ Object (readonly)
Returns the embedded resource of the Resource as a ResourceCollection.
20 21 22 |
# File 'lib/hyperclient/resource.rb', line 20 def end |
#links ⇒ Object (readonly)
Returns the links of the Resource as a LinkCollection.
16 17 18 |
# File 'lib/hyperclient/resource.rb', line 16 def links @links end |
#response ⇒ Object (readonly)
Returns the response object for the HTTP request that created this resource, if one exists.
24 25 26 |
# File 'lib/hyperclient/resource.rb', line 24 def response @response end |
Instance Method Details
#inspect ⇒ Object
43 44 45 |
# File 'lib/hyperclient/resource.rb', line 43 def inspect "#<#{self.class.name} self_link:#{self_link.inspect} attributes:#{@attributes.inspect}>" end |
#self_link ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the self Link of the Resource. Used to handle the HTTP methods.
58 59 60 |
# File 'lib/hyperclient/resource.rb', line 58 def self_link @links['self'] end |
#status ⇒ Object
51 52 53 |
# File 'lib/hyperclient/resource.rb', line 51 def status response && response.status end |
#success? ⇒ Boolean
47 48 49 |
# File 'lib/hyperclient/resource.rb', line 47 def success? response && response.success? end |