From 4aed3e544e452c7ce322ee8ce9c4cc104ca4da82 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 19 Sep 2013 16:18:55 +0200 Subject: [PATCH] Added new UserAgent lib to handle ftp/http/https calls. --- lib/geo_location/gmaps.rb | 8 ++++---- lib/rss.rb | 12 +++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/geo_location/gmaps.rb b/lib/geo_location/gmaps.rb index 707a40fb2..c286c9820 100644 --- a/lib/geo_location/gmaps.rb +++ b/lib/geo_location/gmaps.rb @@ -4,8 +4,8 @@ class GeoLocation::Gmaps def self.geocode(address) url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI::escape address}&sensor=true" - response = Net::HTTP.get_response( URI.parse(url) ) - return if ! response.kind_of? Net::HTTPSuccess + response = UserAgent.request(url) + return if !response.success? result = JSON.parse( response.body ) @@ -16,8 +16,8 @@ class GeoLocation::Gmaps def self.reverse_geocode(lat,lng) url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true" - response = Net::HTTP.get_response( URI.parse(url) ) - return if ! response.kind_of? Net::HTTPSuccess + response = UserAgent.request(url) + return if !response.success? result = JSON.parse( response.body ) diff --git a/lib/rss.rb b/lib/rss.rb index 083f04bce..081773b6b 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -7,14 +7,8 @@ module Rss begin puts 'fetch rss...' - response = Net::HTTP.get_response( URI.parse(url) ) - - # check if redirect is needed - if response.kind_of? Net::HTTPRedirection - url = response.header['location'] - response = Net::HTTP.get_response( URI.parse( url ) ) - end - if ! response.kind_of? Net::HTTPSuccess + response = UserAgent.request(url) + if !response.success? raise "Can't fetch '#{url}', http code: #{response.code.to_s}" return end @@ -42,4 +36,4 @@ module Rss return items end -end \ No newline at end of file +end