I am extracting some weather data from an online xml document using Nokogiri and I would like to set a timeout for a graceful recovery in case the source cannot be reached ...
My Google searches show a few possible methods for open-uri and Net :: HTTP, but none apply to Nokogiri. My attempts to use these methods will not work (not surprisingly):
begin currentloc = ("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + @destination.weatherloc) currentloc.read_timeout = 10
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 cannot convert Hash to string"
Does Nokogiri support this method (and if so ... how?), Or should I look at some other solution?
Thanks.
David smith
source share