@@ -10,7 +10,7 @@ class Link
1010 #
1111 # key - The key or name of the link.
1212 # link - The String with the URI of the link.
13- # entry_point - The EntryPoint object to inject the cofnigutation .
13+ # entry_point - The EntryPoint object to inject the configuration .
1414 # uri_variables - The optional Hash with the variables to expand the link
1515 # if it is templated.
1616 def initialize ( key , link , entry_point , uri_variables = nil )
@@ -80,76 +80,37 @@ def _hreflang
8080 @link [ 'hreflang' ]
8181 end
8282
83- # Public: Returns the Resource which the Link is pointing to.
84- def _get
85- @resource = begin
86- response = Futuroscope ::Future . new do
87- _connection . get ( _url )
88- end
89- Resource . new ( response . body , @entry_point , response )
90- end
91- end
92-
9383 def _resource
9484 @resource || _get
9585 end
9686
97- def _connection
98- @entry_point . connection
87+ # Public: Returns the Resource which the Link is pointing to.
88+ def _get
89+ http_method ( :get )
9990 end
10091
10192 def _options
102- @resource = begin
103- response = Futuroscope ::Future . new do
104- _connection . run_request ( :options , _url , nil , nil )
105- end
106- Resource . new ( response . body , @entry_point , response )
107- end
93+ http_method ( :options )
10894 end
10995
11096 def _head
111- @resource = begin
112- response = Futuroscope ::Future . new do
113- _connection . head ( _url )
114- end
115- Resource . new ( response . body , @entry_point , response )
116- end
97+ http_method ( :head )
11798 end
11899
119100 def _delete
120- @resource = begin
121- response = Futuroscope ::Future . new do
122- _connection . delete ( _url )
123- end
124- Resource . new ( response . body , @entry_point , response )
125- end
101+ http_method ( :delete )
126102 end
127103
128104 def _post ( params = { } )
129- @resource = begin
130- response = Futuroscope ::Future . new do
131- _connection . post ( _url , params )
132- end
133- Resource . new ( response . body , @entry_point , response )
134- end
105+ http_method ( :post , params )
135106 end
136107
137108 def _put ( params = { } )
138- @resource = begin
139- response = Futuroscope ::Future . new do
140- _connection . put ( _url , params )
141- end
142- Resource . new ( response . body , @entry_point , response )
143- end
109+ http_method ( :put , params )
144110 end
145111
146112 def _patch ( params = { } )
147- @resource = begin
148- response = Futuroscope ::Future . new do
149- _connection . patch ( _url , params )
150- end
151- Resource . new ( response . body , @entry_point , response )
152- end
113+ http_method ( :patch , params )
153114 end
154115
155116 def inspect
@@ -198,5 +159,14 @@ def to_ary
198159 def _uri_template
199160 @uri_template ||= URITemplate . new ( @link [ 'href' ] )
200161 end
162+
163+ def http_method ( method , body = nil )
164+ @resource = begin
165+ response = Futuroscope ::Future . new do
166+ @entry_point . connection . run_request ( method , _url , body , nil )
167+ end
168+ Resource . new ( response . body , @entry_point , response )
169+ end
170+ end
201171 end
202172end
0 commit comments