Added new UserAgent lib to handle ftp/http/https calls.
This commit is contained in:
parent
ad579d8237
commit
4aed3e544e
2 changed files with 7 additions and 13 deletions
|
@ -4,8 +4,8 @@ class GeoLocation::Gmaps
|
||||||
|
|
||||||
def self.geocode(address)
|
def self.geocode(address)
|
||||||
url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI::escape address}&sensor=true"
|
url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{CGI::escape address}&sensor=true"
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
return if ! response.kind_of? Net::HTTPSuccess
|
return if !response.success?
|
||||||
|
|
||||||
result = JSON.parse( response.body )
|
result = JSON.parse( response.body )
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ class GeoLocation::Gmaps
|
||||||
|
|
||||||
def self.reverse_geocode(lat,lng)
|
def self.reverse_geocode(lat,lng)
|
||||||
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
|
url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
return if ! response.kind_of? Net::HTTPSuccess
|
return if !response.success?
|
||||||
|
|
||||||
result = JSON.parse( response.body )
|
result = JSON.parse( response.body )
|
||||||
|
|
||||||
|
|
12
lib/rss.rb
12
lib/rss.rb
|
@ -7,14 +7,8 @@ module Rss
|
||||||
|
|
||||||
begin
|
begin
|
||||||
puts 'fetch rss...'
|
puts 'fetch rss...'
|
||||||
response = Net::HTTP.get_response( URI.parse(url) )
|
response = UserAgent.request(url)
|
||||||
|
if !response.success?
|
||||||
# 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
|
|
||||||
raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
|
raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -42,4 +36,4 @@ module Rss
|
||||||
|
|
||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue