lib/barometer/web_services/placemaker.rb in barometer-0.7.3 vs lib/barometer/web_services/placemaker.rb in barometer-0.8.0
- old
+ new
@@ -6,38 +6,38 @@
# this uses Placemaker to obtain a WOEID, as only Yahoo knows them
#
# accepts: city name, coords, postal code, NOT zip code, NOT icao
#
class WebService::Placemaker < WebService
-
+
# get the woe_id for a given query
#
def self.fetch(query)
-
+
begin
require 'nokogiri'
rescue LoadError
puts "\n****\nTo use this functionality you will need to install Nokogiri >= 1.3.3\n****\n\n"
return nil
end
-
- puts "fetch woe_id: #{query.q}" if Barometer::debug?
+
return nil unless query
return nil unless _has_geocode_key?
raise ArgumentError unless _is_a_query?(query)
-
+ puts "fetch woe_id: #{query.q}" if Barometer::debug?
+
# BUG: httparty doesn't seem to post correctly
# self.post(
# 'http://wherein.yahooapis.com/v1/document',
# :query => {
# :documentType => "html",
# :outputType => 'xml',
# :documentContent => _adjust_query(query),
# :appid => Barometer.yahoo_placemaker_app_id
# }, :format => :xml, :timeout => Barometer.timeout
# )
-
+
# TODO: include timeout
# :timeout => Barometer.timeout
#
res = Net::HTTP.post_form(
URI.parse("http://wherein.yahooapis.com/v1/document"),
@@ -46,11 +46,11 @@
'outputType' => 'xml',
'documentContent' => _adjust_query(query),
'appid' => Barometer.yahoo_placemaker_app_id
}
)
-
+
Nokogiri::HTML.parse(res.body)
end
# get the location_data (geocode) for a given woe_id
#
@@ -61,21 +61,21 @@
self.get(
"http://weather.yahooapis.com/forecastrss",
:query => { :w => query.q },
:format => :xml,
:timeout => Barometer.timeout
- )['rss']['channel']["yweather:location"]
+ )['rss']['channel']["location"]
end
-
+
# parses a Nokogori doc object
#
def self.parse_woe_id(doc)
doc.search('woeid').first.content
end
-
+
private
-
+
# convert coordinates to a microformat version of coordinates
# so that Placemaker uses them correctly
#
def self._adjust_query(query)
output = query.q
@@ -91,7 +91,5 @@
!Barometer.yahoo_placemaker_app_id.nil?
end
end
end
-
-