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.
14 15 16 17 18 |
# File 'lib/hyperclient/link.rb', line 14 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`
139 140 141 142 143 144 145 |
# File 'lib/hyperclient/link.rb', line 139 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.
98 99 100 |
# File 'lib/hyperclient/link.rb', line 98 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.
114 115 116 |
# File 'lib/hyperclient/link.rb', line 114 def delete connection.delete(url) end |
#deprecation ⇒ Object
Returns the deprecation property of the Link
66 67 68 |
# File 'lib/hyperclient/link.rb', line 66 def deprecation @link['deprecation'] end |
#expand(uri_variables) ⇒ Object
Expands the Link when is templated with the given variables.
33 34 35 |
# File 'lib/hyperclient/link.rb', line 33 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.
102 103 104 |
# File 'lib/hyperclient/link.rb', line 102 def get 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.
110 111 112 |
# File 'lib/hyperclient/link.rb', line 110 def head connection.head(url) end |
#hreflang ⇒ Object
Returns the hreflang property of the Link
81 82 83 |
# File 'lib/hyperclient/link.rb', line 81 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.
130 131 132 |
# File 'lib/hyperclient/link.rb', line 130 def inspect "#<#{self.class.name} #{@link}>" end |
#name ⇒ Object
Returns the name property of the Link
61 62 63 |
# File 'lib/hyperclient/link.rb', line 61 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.
106 107 108 |
# File 'lib/hyperclient/link.rb', line 106 def 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.
126 127 128 |
# File 'lib/hyperclient/link.rb', line 126 def patch(params = {}) 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.
118 119 120 |
# File 'lib/hyperclient/link.rb', line 118 def post(params = {}) connection.post(url, params) end |
#profile ⇒ Object
Returns the profile property of the Link
71 72 73 |
# File 'lib/hyperclient/link.rb', line 71 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.
122 123 124 |
# File 'lib/hyperclient/link.rb', line 122 def put(params = {}) connection.put(url, params) end |
#resource ⇒ Object
Returns the Resource which the Link is pointing to.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/hyperclient/link.rb', line 86 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.
149 150 151 |
# File 'lib/hyperclient/link.rb', line 149 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.
24 25 26 |
# File 'lib/hyperclient/link.rb', line 24 def templated? !!@link['templated'] end |
#title ⇒ Object
Returns the title property of the Link
76 77 78 |
# File 'lib/hyperclient/link.rb', line 76 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.
157 158 159 |
# File 'lib/hyperclient/link.rb', line 157 def to_ary nil end |
#type ⇒ Object
Returns the type property of the Link
56 57 58 |
# File 'lib/hyperclient/link.rb', line 56 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
162 163 164 |
# File 'lib/hyperclient/link.rb', line 162 def uri_template @uri_template ||= URITemplate.new(@link['href']) end |
#url ⇒ Object
Returns the url of the Link.
41 42 43 44 45 46 |
# File 'lib/hyperclient/link.rb', line 41 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.
51 52 53 |
# File 'lib/hyperclient/link.rb', line 51 def variables uri_template.variables end |