lib/oembed/provider.rb in ruby-oembed-0.8.9 vs lib/oembed/provider.rb in ruby-oembed-0.8.10
- old
+ new
@@ -76,10 +76,11 @@
# given url and return the appropriate OEmbed::Response.
#
# The query parameter should be a Hash of values which will be
# sent as query parameters in this request to the Provider endpoint. The
# following special cases apply to the query Hash:
+ # :timeout:: specifies the timeout (in seconds) for the http request.
# :format:: overrides this Provider's default request format.
# :url:: will be ignored, replaced by the url param.
def get(url, query = {})
query[:format] ||= @format
OEmbed::Response.create_for(raw(url, query), self, url, query[:format].to_s)
@@ -94,10 +95,12 @@
# @deprecated *Note*: This method will be made private in the future.
def build(url, query = {})
raise OEmbed::NotFound, url unless include?(url)
query = query.merge({:url => ::CGI.escape(url)})
+ query.delete(:timeout)
+
# TODO: move this code exclusively into the get method, once build is private.
this_format = (query[:format] ||= @format.to_s).to_s
endpoint = @endpoint.clone
@@ -128,9 +131,10 @@
max_redirects = 4
until found
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ http.read_timeout = http.open_timeout = query[:timeout] if query[:timeout]
%w{scheme userinfo host port registry}.each { |method| uri.send("#{method}=", nil) }
res = http.request(Net::HTTP::Get.new(uri.to_s))
#res = Net::HTTP.start(uri.host, uri.port) {|http| http.get(uri.request_uri) }