Class: ApiNavigator::Link Private
- Inherits:
-
Object
- Object
- ApiNavigator::Link
- Defined in:
- lib/api_navigator/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
- #_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
Returns the Resource which the Link is pointing to.
- #_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 private
-
#_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.
- #http_method(method, body = nil) ⇒ Object private private
-
#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 further down the API if the resource cannot serve it.
-
#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.
14 15 16 17 18 19 20 |
# File 'lib/api_navigator/link.rb', line 14 def initialize(key, link, entry_point, uri_variables = nil) @key = key @link = link @entry_point = entry_point @uri_variables = uri_variables @resource = nil 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 further down the API if the resource cannot serve it.
126 127 128 129 130 131 132 |
# File 'lib/api_navigator/link.rb', line 126 def method_missing(method, *args, &block) if _resource.respond_to?(method.to_s) _resource.send(method, *args, &block) else super end end |
Instance Method Details
#_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.
99 100 101 |
# File 'lib/api_navigator/link.rb', line 99 def _delete http_method(:delete) end |
#_deprecation ⇒ Object
Returns the deprecation property of the Link
63 64 65 |
# File 'lib/api_navigator/link.rb', line 63 def _deprecation @link['deprecation'] end |
#_expand(uri_variables = {}) ⇒ Object
Expands the Link when is templated with the given variables.
35 36 37 |
# File 'lib/api_navigator/link.rb', line 35 def (uri_variables = {}) self.class.new(@key, @link, @entry_point, uri_variables) end |
#_get ⇒ Object
Returns the Resource which the Link is pointing to.
87 88 89 |
# File 'lib/api_navigator/link.rb', line 87 def _get http_method(:get) 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.
95 96 97 |
# File 'lib/api_navigator/link.rb', line 95 def _head http_method(:head) end |
#_hreflang ⇒ Object
Returns the hreflang property of the Link
78 79 80 |
# File 'lib/api_navigator/link.rb', line 78 def _hreflang @link['hreflang'] end |
#_name ⇒ Object
Returns the name property of the Link
58 59 60 |
# File 'lib/api_navigator/link.rb', line 58 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.
91 92 93 |
# File 'lib/api_navigator/link.rb', line 91 def http_method(:options) 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.
111 112 113 |
# File 'lib/api_navigator/link.rb', line 111 def _patch(params = {}) http_method(:patch, params) 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.
103 104 105 |
# File 'lib/api_navigator/link.rb', line 103 def _post(params = {}) http_method(:post, params) end |
#_profile ⇒ Object
Returns the profile property of the Link
68 69 70 |
# File 'lib/api_navigator/link.rb', line 68 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.
107 108 109 |
# File 'lib/api_navigator/link.rb', line 107 def _put(params = {}) http_method(:put, params) end |
#_resource ⇒ 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.
82 83 84 |
# File 'lib/api_navigator/link.rb', line 82 def _resource @resource || _get end |
#_templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
26 27 28 |
# File 'lib/api_navigator/link.rb', line 26 def _templated? !!@link['templated'] end |
#_title ⇒ Object
Returns the title property of the Link
73 74 75 |
# File 'lib/api_navigator/link.rb', line 73 def _title @link['title'] end |
#_type ⇒ Object
Returns the type property of the Link
53 54 55 |
# File 'lib/api_navigator/link.rb', line 53 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
149 150 151 |
# File 'lib/api_navigator/link.rb', line 149 def _uri_template @uri_template ||= URITemplate.new(@link['href']) end |
#_url ⇒ Object
Returns the url of the Link.
40 41 42 43 |
# File 'lib/api_navigator/link.rb', line 40 def _url return @link['href'] unless _templated? @url ||= _uri_template.(@uri_variables || {}) end |
#_variables ⇒ Object
Returns an array of variables from the URITemplate.
48 49 50 |
# File 'lib/api_navigator/link.rb', line 48 def _variables _uri_template.variables end |
#http_method(method, body = nil) ⇒ 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.
153 154 155 156 157 158 |
# File 'lib/api_navigator/link.rb', line 153 def http_method(method, body = nil) @resource = begin response = @entry_point.connection.run_request(method, _url, body, nil) Resource.from_representation(response.body, @entry_point, response) end 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.
115 116 117 |
# File 'lib/api_navigator/link.rb', line 115 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.
136 137 138 |
# File 'lib/api_navigator/link.rb', line 136 def respond_to_missing?(method, _include_private = false) _resource.respond_to?(method.to_s) 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 coercion (such as parallel assignment or Array#flatten). Returning nil tells Ruby that this record is not Array-like.
144 145 146 |
# File 'lib/api_navigator/link.rb', line 144 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.
119 120 121 |
# File 'lib/api_navigator/link.rb', line 119 def to_s _url end |