Sha256: da890f8ae2d40cb150e086adb41e9c399e7c225774a04857112ba307ee004529

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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

1 entries across 1 versions & 1 rubygems

Version Path
barometer-0.8.0 lib/barometer/web_services/timezone.rb