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 perform HTTP requests against itself and ease the way you access the resource’s attributes, links and embedded resources.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
A String representing the Resource name.
Class Method Summary collapse
-
.entry_point=(url) ⇒ void
Sets the entry point for all the resources in your API client.
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Resource
constructor
Initializes a Resource.
-
#initialize_representation(raw_representation) ⇒ void
private
private
Initializes a Representation.
-
#reload ⇒ Object
Gets a fresh representation from the resource representation.
-
#representation ⇒ Object
private
private
Returns the resource representation.
-
#url ⇒ Object
Returns A String representing the resource url.
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
A String representing the Resource name.
18 19 20 |
# File 'lib/hyperclient/resource.rb', line 18 def name @name end |
Class Method Details
.entry_point=(url) ⇒ void
This method returns an undefined value.
Sets the entry point for all the resources in your API client.
42 43 44 |
# File 'lib/hyperclient/resource.rb', line 42 def self.entry_point=(url) @@entry_point = URI(url) end |
Instance Method Details
#initialize_representation(raw_representation) ⇒ void (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.
This method returns an undefined value.
Initializes a Representation
69 70 71 72 73 |
# File 'lib/hyperclient/resource.rb', line 69 def initialize_representation(raw_representation) if raw_representation && !raw_representation.empty? @representation = Representation.new(raw_representation) end end |
#reload ⇒ Object
Gets a fresh representation from the resource representation.
58 59 60 61 |
# File 'lib/hyperclient/resource.rb', line 58 def reload initialize_representation(get) self end |
#representation ⇒ 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 resource representation.
76 77 78 79 |
# File 'lib/hyperclient/resource.rb', line 76 def representation reload unless @representation @representation end |
#url ⇒ Object
Returns A String representing the resource url.
47 48 49 50 51 52 53 |
# File 'lib/hyperclient/resource.rb', line 47 def url begin @@entry_point.merge(@url).to_s rescue URI::InvalidURIError @url end end |