Class: Hyperclient::Link Private
- Inherits:
-
Object
- Object
- Hyperclient::Link
- Defined in:
- lib/hyperclient/link.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The Link is used to let a Resource interact with the API.
Direct Known Subclasses
Instance Method Summary collapse
- #_connection ⇒ Object private
- #_delete ⇒ Object private
-
#_deprecation ⇒ Object
Returns the deprecation property of the Link.
-
#_expand(uri_variables) ⇒ Object
Expands the Link when is templated with the given variables.
- #_get ⇒ Object private
- #_head ⇒ Object private
-
#_hreflang ⇒ Object
Returns the hreflang property of the Link.
-
#_name ⇒ Object
Returns the name property of the Link.
- #_options ⇒ Object private
- #_patch(params = {}) ⇒ Object private
- #_post(params = {}) ⇒ Object private
-
#_profile ⇒ Object
Returns the profile property of the Link.
- #_put(params = {}) ⇒ Object private
-
#_resource ⇒ Object
Returns the Resource which the Link is pointing to.
-
#_templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
-
#_title ⇒ Object
Returns the title property of the Link.
-
#_type ⇒ Object
Returns the type property of the Link.
-
#_uri_template ⇒ Object
private
private
Memoization for a URITemplate instance.
-
#_url ⇒ Object
Returns the url of the Link.
-
#_variables ⇒ Object
Returns an array of variables from the URITemplate.
-
#initialize(key, link, entry_point, uri_variables = nil) ⇒ Link
constructor
Initializes a new Link.
- #inspect ⇒ Object private
-
#method_missing(method, *args, &block) ⇒ Object
private
private
Delegate the method to the API if it exists.
-
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
private
private
Accessory method to allow the link respond to the methods that will hit method_missing.
-
#to_ary ⇒ Object
private
private
avoid delegating to resource.
- #to_s ⇒ Object private
Constructor Details
#initialize(key, link, entry_point, uri_variables = nil) ⇒ Link
Initializes a new Link.
16 17 18 19 20 21 |
# File 'lib/hyperclient/link.rb', line 16 def initialize(key, link, entry_point, uri_variables = nil) @key = key @link = link @entry_point = entry_point @uri_variables = uri_variables end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ 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.
Delegate the method to the API if it exists.
This allows ‘api.posts` instead of `api.links.posts.embedded`
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/hyperclient/link.rb', line 160 def method_missing(method, *args, &block) if @key && _resource.respond_to?(@key) && (delegate = _resource.send(@key)) && delegate.respond_to?(method.to_s) # named.named becomes named delegate.send(method, *args, &block) elsif _resource.respond_to?(method.to_s) _resource.send(method, *args, &block) else super end end |
Instance Method Details
#_connection ⇒ Object
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.
101 102 103 |
# File 'lib/hyperclient/link.rb', line 101 def _connection @entry_point.connection end |
#_delete ⇒ Object
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.
123 124 125 126 127 |
# File 'lib/hyperclient/link.rb', line 123 def _delete Futuroscope::Future.new do _connection.delete(_url) end end |
#_deprecation ⇒ Object
Returns the deprecation property of the Link
69 70 71 |
# File 'lib/hyperclient/link.rb', line 69 def _deprecation @link['deprecation'] end |
#_expand(uri_variables) ⇒ Object
Expands the Link when is templated with the given variables.
36 37 38 |
# File 'lib/hyperclient/link.rb', line 36 def (uri_variables) self.class.new(@key, @link, @entry_point, uri_variables) end |
#_get ⇒ Object
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.
105 106 107 108 109 |
# File 'lib/hyperclient/link.rb', line 105 def _get Futuroscope::Future.new do _connection.get(_url) end end |
#_head ⇒ Object
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.
117 118 119 120 121 |
# File 'lib/hyperclient/link.rb', line 117 def _head Futuroscope::Future.new do _connection.head(_url) end end |
#_hreflang ⇒ Object
Returns the hreflang property of the Link
84 85 86 |
# File 'lib/hyperclient/link.rb', line 84 def _hreflang @link['hreflang'] end |
#_name ⇒ Object
Returns the name property of the Link
64 65 66 |
# File 'lib/hyperclient/link.rb', line 64 def _name @link['name'] end |
#_options ⇒ Object
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.
111 112 113 114 115 |
# File 'lib/hyperclient/link.rb', line 111 def Futuroscope::Future.new do _connection.run_request(:options, _url, nil, nil) end end |
#_patch(params = {}) ⇒ Object
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.
141 142 143 144 145 |
# File 'lib/hyperclient/link.rb', line 141 def _patch(params = {}) Futuroscope::Future.new do _connection.patch(_url, params) end end |
#_post(params = {}) ⇒ Object
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.
129 130 131 132 133 |
# File 'lib/hyperclient/link.rb', line 129 def _post(params = {}) Futuroscope::Future.new do _connection.post(_url, params) end end |
#_profile ⇒ Object
Returns the profile property of the Link
74 75 76 |
# File 'lib/hyperclient/link.rb', line 74 def _profile @link['profile'] end |
#_put(params = {}) ⇒ Object
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.
135 136 137 138 139 |
# File 'lib/hyperclient/link.rb', line 135 def _put(params = {}) Futuroscope::Future.new do _connection.put(_url, params) end end |
#_resource ⇒ Object
Returns the Resource which the Link is pointing to.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hyperclient/link.rb', line 89 def _resource @resource ||= begin response = _get if response.success? Resource.new(response.body, @entry_point, response) else Resource.new(nil, @entry_point, response) end end end |
#_templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
27 28 29 |
# File 'lib/hyperclient/link.rb', line 27 def _templated? !!@link['templated'] end |
#_title ⇒ Object
Returns the title property of the Link
79 80 81 |
# File 'lib/hyperclient/link.rb', line 79 def _title @link['title'] end |
#_type ⇒ Object
Returns the type property of the Link
59 60 61 |
# File 'lib/hyperclient/link.rb', line 59 def _type @link['type'] end |
#_uri_template ⇒ 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.
Memoization for a URITemplate instance
190 191 192 |
# File 'lib/hyperclient/link.rb', line 190 def _uri_template @uri_template ||= URITemplate.new(@link['href']) end |
#_url ⇒ Object
Returns the url of the Link.
44 45 46 47 48 49 |
# File 'lib/hyperclient/link.rb', line 44 def _url return @link['href'] unless _templated? fail MissingURITemplateVariablesException if @uri_variables.nil? @url ||= _uri_template.(@uri_variables) end |
#_variables ⇒ Object
Returns an array of variables from the URITemplate.
54 55 56 |
# File 'lib/hyperclient/link.rb', line 54 def _variables _uri_template.variables end |
#inspect ⇒ Object
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.
147 148 149 |
# File 'lib/hyperclient/link.rb', line 147 def inspect "#<#{self.class.name}(#{@key}) #{@link}>" end |
#respond_to_missing?(method, _include_private = false) ⇒ Boolean (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.
Accessory method to allow the link respond to the methods that will hit method_missing.
173 174 175 176 177 178 179 |
# File 'lib/hyperclient/link.rb', line 173 def respond_to_missing?(method, _include_private = false) if @key && _resource.respond_to?(@key) && (delegate = _resource.send(@key)) && delegate.respond_to?(method.to_s) true else _resource.respond_to?(method.to_s) end end |
#to_ary ⇒ 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.
avoid delegating to resource
#to_ary is called for implicit array coersion (such as parallel assignment or Array#flatten). Returning nil tells Ruby that this record is not Array-like.
185 186 187 |
# File 'lib/hyperclient/link.rb', line 185 def to_ary nil end |
#to_s ⇒ Object
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.
151 152 153 |
# File 'lib/hyperclient/link.rb', line 151 def to_s _url end |