require 'rubygems' require 'sinatra' require 'barometer' # load API keys @@config_file ||= File.expand_path(File.join('~', '.barometer')) keys = YAML.load_file(@@config_file) if keys["google"] && keys["google"]["geocode"] Barometer.google_geocode_key = keys["google"]["geocode"] else raise RunTimeError "no geocoding keys" exit end class Demometer < Sinatra::Default def config_weather_dot_com if File.exists?(@@config_file) keys = YAML.load_file(@@config_file) if keys["weather"] && keys["weather"]["partner"] && keys["weather"]["license"] partner_key = keys["weather"]["partner"].to_s license_key = keys["weather"]["license"].to_s else raise RunTimeError "no weather.com keys" exit end else File.open(@@config_file, 'w') {|f| f << "\nweather:\n partner: PARTNER_KEY\n license: LICENSE_KEY" } raise RunTimeError "no weather.com keys" exit end { :weather_dot_com => { :keys => { :partner => partner_key, :license => license_key } } } end def config_weather_bug if File.exists?(@@config_file) keys = YAML.load_file(@@config_file) if keys["weather_bug"] && keys["weather_bug"]["code"] code = keys["weather_bug"]["code"].to_s else raise RunTimeError "no weatherbug.com keys" exit end else File.open(@@config_file, 'w') {|f| f << "\weather_bug:\n code: API_CODE" } raise RunTimeError "no weatherbug.com keys" exit end { :weather_bug => { :keys => { :code => code } } } end helpers do def data(title, value) return if value.nil? "