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.
-
#initialize(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.
-
#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.
-
#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.
-
#templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
-
#title ⇒ Object
Returns the title property of the Link.
-
#to_ary ⇒ Object
private
private
avoid delegating to resource.
-
#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.
Constructor Details
#initialize(link, entry_point, uri_variables = nil) ⇒ Link
Initializes a new Link.
15 16 17 18 19 |
# File 'lib/hyperclient/link.rb', line 15 def initialize(link, entry_point, uri_variables = nil) @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.links.posts.embedded` instead of `api.links.posts.resource.embedded`
154 155 156 157 158 159 160 |
# File 'lib/hyperclient/link.rb', line 154 def method_missing(method, *args, &block) if resource.respond_to?(method) 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.
99 100 101 |
# File 'lib/hyperclient/link.rb', line 99 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.
121 122 123 124 125 |
# File 'lib/hyperclient/link.rb', line 121 def delete Futuroscope::Future.new{ connection.delete(url) } end |
#deprecation ⇒ Object
Returns the deprecation property of the Link
67 68 69 |
# File 'lib/hyperclient/link.rb', line 67 def deprecation @link['deprecation'] end |
#expand(uri_variables) ⇒ Object
Expands the Link when is templated with the given variables.
34 35 36 |
# File 'lib/hyperclient/link.rb', line 34 def (uri_variables) self.class.new(@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.
103 104 105 106 107 |
# File 'lib/hyperclient/link.rb', line 103 def get Futuroscope::Future.new{ connection.get(url) } 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.
115 116 117 118 119 |
# File 'lib/hyperclient/link.rb', line 115 def head Futuroscope::Future.new{ connection.head(url) } end |
#hreflang ⇒ Object
Returns the hreflang property of the Link
82 83 84 |
# File 'lib/hyperclient/link.rb', line 82 def hreflang @link['hreflang'] 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.
145 146 147 |
# File 'lib/hyperclient/link.rb', line 145 def inspect "#<#{self.class.name} #{@link}>" end |
#name ⇒ Object
Returns the name property of the Link
62 63 64 |
# File 'lib/hyperclient/link.rb', line 62 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.
109 110 111 112 113 |
# File 'lib/hyperclient/link.rb', line 109 def Futuroscope::Future.new{ connection.run_request(:options, url, nil, nil) } 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.
139 140 141 142 143 |
# File 'lib/hyperclient/link.rb', line 139 def patch(params = {}) Futuroscope::Future.new{ connection.patch(url, 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.
127 128 129 130 131 |
# File 'lib/hyperclient/link.rb', line 127 def post(params = {}) Futuroscope::Future.new{ connection.post(url, params) } end |
#profile ⇒ Object
Returns the profile property of the Link
72 73 74 |
# File 'lib/hyperclient/link.rb', line 72 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.
133 134 135 136 137 |
# File 'lib/hyperclient/link.rb', line 133 def put(params = {}) Futuroscope::Future.new{ connection.put(url, params) } end |
#resource ⇒ Object
Returns the Resource which the Link is pointing to.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/hyperclient/link.rb', line 87 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 |
#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.
164 165 166 |
# File 'lib/hyperclient/link.rb', line 164 def respond_to_missing?(method, include_private = false) resource.respond_to?(method.to_s) end |
#templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
25 26 27 |
# File 'lib/hyperclient/link.rb', line 25 def templated? !!@link['templated'] end |
#title ⇒ Object
Returns the title property of the Link
77 78 79 |
# File 'lib/hyperclient/link.rb', line 77 def title @link['title'] 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.
172 173 174 |
# File 'lib/hyperclient/link.rb', line 172 def to_ary nil end |
#type ⇒ Object
Returns the type property of the Link
57 58 59 |
# File 'lib/hyperclient/link.rb', line 57 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
177 178 179 |
# File 'lib/hyperclient/link.rb', line 177 def uri_template @uri_template ||= URITemplate.new(@link['href']) end |
#url ⇒ Object
Returns the url of the Link.
42 43 44 45 46 47 |
# File 'lib/hyperclient/link.rb', line 42 def url return @link['href'] unless templated? raise MissingURITemplateVariablesException if @uri_variables == nil @url ||= uri_template.(@uri_variables) end |
#variables ⇒ Object
Returns an array of variables from the URITemplate.
52 53 54 |
# File 'lib/hyperclient/link.rb', line 52 def variables uri_template.variables end |