Sha256: 2d5ba0c824d1bd3254e140f7110f8d21176fa8031bdcb815b4f8746692dfd4b4
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module Barometer # # Web Service: WeatherID # # uses Weather.com search to obtain a weather id # class WebService::WeatherID < WebService # get the weather_id for a given query # def self.fetch(query) puts "fetch weather_id: #{query.q}" if Barometer::debug? return nil unless query raise ArgumentError unless _is_a_query?(query) self.get( "http://xoap.weather.com/search/search", :query => { :where => _adjust_query(query.q) }, :format => :plain, :timeout => Barometer.timeout ) end # get the location_date (geocode) for a given weather_id # def self.reverse(query) puts "reverse weather_id: #{query.q}" if Barometer::debug? return nil unless query raise ArgumentError unless _is_a_query?(query) self.get( "http://weather.yahooapis.com/forecastrss", :query => { :p => query.q }, :format => :xml, :timeout => Barometer.timeout )['rss']['channel']["location"] end # filter out words that weather.com has trouble geo-locating # mostly these are icao related # def self._adjust_query(query) output = query.dup words_to_remove = %w(international airport municipal) words_to_remove.each do |word| output.gsub!(/#{word}/i, "") end output end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
barometer-0.8.0 | lib/barometer/web_services/weather_id.rb |