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_response(raw_response) ⇒ void
private
private
Initializes a Response.
-
#reload ⇒ Object
Gets a fresh response from the resource representation.
-
#response ⇒ Object
private
private
Returns the resource response.
-
#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_response(raw_response) ⇒ 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 Response
69 70 71 72 73 74 |
# File 'lib/hyperclient/resource.rb', line 69 def initialize_response(raw_response) if raw_response && raw_response.is_a?(Hash) && !raw_response.empty? @response = Response.new(raw_response) @url = @response.url if @response.url end end |
#reload ⇒ Object
Gets a fresh response from the resource representation.
58 59 60 61 |
# File 'lib/hyperclient/resource.rb', line 58 def reload initialize_response(get) self end |
#response ⇒ 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 response.
77 78 79 80 |
# File 'lib/hyperclient/resource.rb', line 77 def response reload unless @response @response 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 |