Sha256: 6e3e5f238ac1ee6081c5ed5359c8d8fe25dcf12ab2ddd9c740b97f8c40a86b8f

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

module Barometer
  #
  # Web Service: Timezone
  #
  # uses geonames.org to obtain the full timezone for given coordinates
  #
  class WebService::Timezone < WebService
    
    # get the full timezone for given coordinates
    #
    def self.fetch(latitude, longitude)
      puts "timezone: #{latitude}, #{longitude}"
      return nil unless latitude && longitude
      _fetch_via_wunderground(latitude, longitude)
    end
    
    def self._fetch_via_geonames(latitude, longitude)
      response = self.get(
        "http://ws.geonames.org/timezone",
        :query => { :lat => latitude, :lng => longitude },
        :format => :xml,
        :timeout => Barometer.timeout
      )['geonames']['timezone']  
      response ? Data::Zone.new(response['timezoneId']) : nil
    end
    
    def self._fetch_via_wunderground(latitude, longitude)
      response = self.get(
        "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml",
        :query => {:query => "#{latitude},#{longitude}"},
        :format => :xml,
        :timeout => Barometer.timeout
      )['forecast']['simpleforecast']['forecastday'].first
      response ? Data::Zone.new(response['date']['tz_long']) : nil
    end
    
  end
end


Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
attack-barometer-0.6.0 lib/barometer/web_services/timezone.rb
attack-barometer-0.6.1 lib/barometer/web_services/timezone.rb
barometer-0.7.3 lib/barometer/web_services/timezone.rb
barometer-0.7.2 lib/barometer/web_services/timezone.rb
barometer-0.7.1 lib/barometer/web_services/timezone.rb
barometer-0.7.0 lib/barometer/web_services/timezone.rb
barometer-0.6.7 lib/barometer/web_services/timezone.rb
barometer-0.6.6 lib/barometer/web_services/timezone.rb
barometer-0.6.4 lib/barometer/web_services/timezone.rb
barometer-0.6.1 lib/barometer/web_services/timezone.rb
barometer-0.6.3 lib/barometer/web_services/timezone.rb
barometer-0.6.2 lib/barometer/web_services/timezone.rb