lib/simplegdata.rb in simplegdata-0.0.2 vs lib/simplegdata.rb in simplegdata-0.0.6

- old
+ new

@@ -50,25 +50,31 @@ data = ActiveSupport::JSON.encode(data) end # Run the query and return the results as a ruby object response = request_raw(rest, url, data, options) - ActiveSupport::JSON.decode response + + unless response.nil? + ActiveSupport::JSON.decode response + end end # A class method to process a raw request. All handling is # done by the user. Deals with the unique issue of GData # API's sometimes returning 302 redirects with gsessionids # appended to them. def request_raw(rest, url, data = nil, options = nil) - response = access_token.request(rest, url, data, options) - #end - case response - when Net::HTTPSuccess then response.body - when Net::HTTPRedirection then access_token.request(rest, response['location'], data, options).body - else - response.error! + begin + response = access_token.request(rest, url, data, options) + case response + when Net::HTTPSuccess then response.body + when Net::HTTPRedirection then request_raw(rest, response['location'], data, options) + else + response.error! + end + rescue Exception => e # TODO: Figure out some better exception handling + nil end end private @@ -85,7 +91,6 @@ token_hash = { :oauth_token => @oauth_token, :oauth_token_secret => @oauth_secret } access_token = OAuth::AccessToken.from_hash(consumer, token_hash) end end - end