lib/hyperclient/link.rb in hyperclient-0.8.1 vs lib/hyperclient/link.rb in hyperclient-0.8.2

- old
+ new

@@ -1,6 +1,5 @@ -require 'hyperclient/resource' require 'uri_template' require 'futuroscope' module Hyperclient # Internal: The Link is used to let a Resource interact with the API. @@ -16,10 +15,11 @@ def initialize(key, link, entry_point, uri_variables = nil) @key = key @link = link @entry_point = entry_point @uri_variables = uri_variables + @resource = nil end # Public: Indicates if the link is an URITemplate or a regular URI. # # Returns true if it is templated. @@ -165,12 +165,18 @@ @uri_template ||= URITemplate.new(@link['href']) end def http_method(method, body = nil) @resource = begin - response = Futuroscope::Future.new do - @entry_point.connection.run_request(method, _url, body, nil) - end + response = + if @entry_point.options[:async] + Futuroscope::Future.new do + @entry_point.connection.run_request(method, _url, body, nil) + end + else + @entry_point.connection.run_request(method, _url, body, nil) + end + Resource.new(response.body, @entry_point, response) end end end end