From e6a4ed74855fc69533857d23185b702d8e510a67 Mon Sep 17 00:00:00 2001 From: Gael Date: Fri, 18 Nov 2011 16:05:20 +0100 Subject: [PATCH] Doesnt crash anymore if no internet --- lib/viadeo/api/query_methods.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/viadeo/api/query_methods.rb b/lib/viadeo/api/query_methods.rb index 3bbac60..b4a7a3e 100644 --- a/lib/viadeo/api/query_methods.rb +++ b/lib/viadeo/api/query_methods.rb @@ -17,13 +17,16 @@ def simple_query(access_token, path, args) url = "#{DEFAULT_OAUTH_OPTIONS[:api_base]}#{path}?access_token=#{access_token}" args.each {|key, value| url += "&#{key}=#{CGI.escape(value.to_s)}"} uri = URI.parse(url) - (1..3).each do - connection = Net::HTTP.new(uri.host, 443) - connection.use_ssl = true - connection.verify_mode = OpenSSL::SSL::VERIFY_NONE - resp = connection.request_get(uri.path + '?' + uri.query) - - return Mash.from_json resp.body if resp.code == '200' + begin + (1..3).each do + connection = Net::HTTP.new(uri.host, 443) + connection.use_ssl = true + connection.verify_mode = OpenSSL::SSL::VERIFY_NONE + resp = connection.request_get(uri.path + '?' + uri.query) + return Mash.from_json resp.body if resp.code == '200' + end + rescue + puts "Error: #{$!}" end return nil end