Hi,
I'm fetching some weather data from an online xml doc using Nokogiri, and I would like to set up a timeout for graceful recovery in case the source can't be reached...
My google searches show several possible methods for open-uri and Net::HTTP, but none specific to Nokogiri. My attempts to use those methods are failing (not too surprisingly):
begin
currentloc = ("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + @destination.weatherloc)
currentloc.read_timeout = 10 #
doc = Nokogiri::XML(open(currentloc))
rescue Timeout::Error
return "Current weather for this location not available: request timed out."
end
returns "NoMethodError", and:
begin
currentloc = ("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + @destination.weatherloc)
doc = Nokogiri::XML(open(currentloc), :read_timeout => 10)
rescue Timeout::Error
return "Current weather for this location not available: request timed out."
end
returns "TypeError can't convert Hash into String"
Does Nokogiri support this kind of method (and if so... how?), or should I be looking at some other solution?
Thanks.