barometer 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/LICENSE +1 -1
  4. data/{README.rdoc → README.md} +124 -110
  5. data/Rakefile +1 -21
  6. data/TODO +8 -9
  7. data/barometer.gemspec +20 -19
  8. data/bin/barometer +36 -83
  9. data/lib/barometer.rb +13 -11
  10. data/lib/barometer/base.rb +10 -10
  11. data/lib/barometer/data.rb +1 -1
  12. data/lib/barometer/data/distance.rb +25 -25
  13. data/lib/barometer/data/geo.rb +9 -9
  14. data/lib/barometer/data/local_datetime.rb +24 -20
  15. data/lib/barometer/data/local_time.rb +13 -13
  16. data/lib/barometer/data/location.rb +6 -6
  17. data/lib/barometer/data/pressure.rb +24 -24
  18. data/lib/barometer/data/speed.rb +28 -28
  19. data/lib/barometer/data/sun.rb +7 -7
  20. data/lib/barometer/data/temperature.rb +29 -29
  21. data/lib/barometer/data/units.rb +9 -9
  22. data/lib/barometer/data/zone.rb +19 -19
  23. data/lib/barometer/formats.rb +1 -1
  24. data/lib/barometer/formats/coordinates.rb +7 -7
  25. data/lib/barometer/formats/format.rb +6 -6
  26. data/lib/barometer/formats/geocode.rb +5 -5
  27. data/lib/barometer/formats/icao.rb +6 -6
  28. data/lib/barometer/formats/postalcode.rb +3 -3
  29. data/lib/barometer/formats/short_zipcode.rb +2 -2
  30. data/lib/barometer/formats/weather_id.rb +10 -10
  31. data/lib/barometer/formats/woe_id.rb +20 -20
  32. data/lib/barometer/formats/zipcode.rb +3 -3
  33. data/lib/barometer/key_file_parser.rb +20 -0
  34. data/lib/barometer/measurements/measurement.rb +32 -32
  35. data/lib/barometer/measurements/result.rb +39 -39
  36. data/lib/barometer/measurements/result_array.rb +12 -12
  37. data/lib/barometer/query.rb +15 -15
  38. data/lib/barometer/services.rb +3 -3
  39. data/lib/barometer/translations/icao_country_codes.yml +20 -20
  40. data/lib/barometer/translations/weather_country_codes.yml +1 -1
  41. data/lib/barometer/translations/zone_codes.yml +2 -2
  42. data/lib/barometer/version.rb +3 -0
  43. data/lib/barometer/weather.rb +27 -27
  44. data/lib/barometer/weather_services/noaa.rb +314 -3
  45. data/lib/barometer/weather_services/service.rb +32 -30
  46. data/lib/barometer/weather_services/weather_bug.rb +35 -33
  47. data/lib/barometer/weather_services/wunderground.rb +31 -29
  48. data/lib/barometer/weather_services/yahoo.rb +36 -35
  49. data/lib/barometer/web_services/geocode.rb +5 -7
  50. data/lib/barometer/web_services/noaa_station_id.rb +53 -0
  51. data/lib/barometer/web_services/placemaker.rb +11 -13
  52. data/lib/barometer/web_services/timezone.rb +5 -7
  53. data/lib/barometer/web_services/weather_id.rb +4 -6
  54. data/lib/barometer/web_services/web_service.rb +4 -4
  55. data/spec/barometer_spec.rb +25 -27
  56. data/spec/cassettes/Barometer.json +1 -0
  57. data/spec/cassettes/Query.json +1 -0
  58. data/spec/cassettes/Query_Format_Coordinates.json +1 -0
  59. data/spec/cassettes/Query_Format_Geocode.json +1 -0
  60. data/spec/cassettes/Query_Format_WeatherID.json +1 -0
  61. data/spec/cassettes/Query_Format_WoeID.json +1 -0
  62. data/spec/cassettes/WeatherService.json +1 -0
  63. data/spec/cassettes/WeatherService_Noaa.json +1 -0
  64. data/spec/cassettes/WeatherService_WeatherBug.json +1 -0
  65. data/spec/cassettes/WeatherService_Wunderground.json +1 -0
  66. data/spec/cassettes/WeatherService_Yahoo.json +1 -0
  67. data/spec/cassettes/WebService_Geocode.json +1 -0
  68. data/spec/cassettes/WebService_NoaaStation.json +1 -0
  69. data/spec/data/distance_spec.rb +60 -60
  70. data/spec/data/geo_spec.rb +23 -23
  71. data/spec/data/local_datetime_spec.rb +44 -44
  72. data/spec/data/local_time_spec.rb +47 -47
  73. data/spec/data/location_spec.rb +16 -16
  74. data/spec/data/pressure_spec.rb +61 -61
  75. data/spec/data/speed_spec.rb +69 -69
  76. data/spec/data/sun_spec.rb +25 -25
  77. data/spec/data/temperature_spec.rb +68 -68
  78. data/spec/data/units_spec.rb +21 -21
  79. data/spec/data/zone_spec.rb +35 -35
  80. data/spec/formats/coordinates_spec.rb +27 -27
  81. data/spec/formats/format_spec.rb +17 -25
  82. data/spec/formats/geocode_spec.rb +23 -31
  83. data/spec/formats/icao_spec.rb +26 -32
  84. data/spec/formats/postalcode_spec.rb +22 -28
  85. data/spec/formats/short_zipcode_spec.rb +20 -26
  86. data/spec/formats/weather_id_spec.rb +57 -67
  87. data/spec/formats/woe_id_spec.rb +59 -59
  88. data/spec/formats/zipcode_spec.rb +39 -47
  89. data/spec/key_file_parser_spec.rb +28 -0
  90. data/spec/measurements/measurement_spec.rb +79 -133
  91. data/spec/measurements/result_array_spec.rb +23 -38
  92. data/spec/measurements/result_spec.rb +100 -128
  93. data/spec/query_spec.rb +83 -100
  94. data/spec/spec_helper.rb +24 -6
  95. data/spec/weather_services/noaa_spec.rb +179 -0
  96. data/spec/weather_services/services_spec.rb +28 -36
  97. data/spec/weather_services/weather_bug_spec.rb +57 -77
  98. data/spec/weather_services/wunderground_spec.rb +36 -65
  99. data/spec/weather_services/yahoo_spec.rb +38 -60
  100. data/spec/weather_spec.rb +79 -79
  101. data/spec/web_services/geocode_spec.rb +7 -11
  102. data/spec/web_services/noaa_station_id_spec.rb +33 -0
  103. data/spec/web_services/placemaker_spec.rb +7 -12
  104. data/spec/web_services/web_services_spec.rb +3 -9
  105. metadata +214 -163
  106. data/VERSION.yml +0 -5
  107. data/lib/barometer/weather_services/google.rb +0 -142
  108. data/lib/barometer/weather_services/weather_dot_com.rb +0 -279
  109. data/spec/fakeweb_helper.rb +0 -179
  110. data/spec/fixtures/formats/weather_id/90210.xml +0 -7
  111. data/spec/fixtures/formats/weather_id/from_USGA0028.xml +0 -3
  112. data/spec/fixtures/formats/weather_id/ksfo.xml +0 -1
  113. data/spec/fixtures/formats/weather_id/manhattan.xml +0 -7
  114. data/spec/fixtures/formats/weather_id/new_york.xml +0 -1
  115. data/spec/fixtures/formats/weather_id/the_hills.xml +0 -1
  116. data/spec/fixtures/geocode/40_73_v3.json +0 -497
  117. data/spec/fixtures/geocode/90210_v3.json +0 -63
  118. data/spec/fixtures/geocode/T5B4M9_v3.json +0 -68
  119. data/spec/fixtures/geocode/atlanta_v3.json +0 -58
  120. data/spec/fixtures/geocode/calgary_ab_v3.json +0 -58
  121. data/spec/fixtures/geocode/ksfo_v3.json +0 -73
  122. data/spec/fixtures/geocode/newyork_ny_v3.json +0 -58
  123. data/spec/fixtures/services/google/calgary_ab.xml +0 -1
  124. data/spec/fixtures/services/placemaker/T5B4M9.xml +0 -65
  125. data/spec/fixtures/services/placemaker/atlanta.xml +0 -65
  126. data/spec/fixtures/services/placemaker/coords.xml +0 -65
  127. data/spec/fixtures/services/placemaker/ksfo.xml +0 -65
  128. data/spec/fixtures/services/placemaker/new_york.xml +0 -65
  129. data/spec/fixtures/services/placemaker/the_hills.xml +0 -65
  130. data/spec/fixtures/services/placemaker/w615702.xml +0 -47
  131. data/spec/fixtures/services/weather_bug/90210_current.xml +0 -93
  132. data/spec/fixtures/services/weather_bug/90210_forecast.xml +0 -76
  133. data/spec/fixtures/services/weather_dot_com/90210.xml +0 -1
  134. data/spec/fixtures/services/wunderground/current_calgary_ab.xml +0 -9
  135. data/spec/fixtures/services/wunderground/forecast_calgary_ab.xml +0 -13
  136. data/spec/fixtures/services/yahoo/90210.xml +0 -3
  137. data/spec/weather_services/google_spec.rb +0 -181
  138. data/spec/weather_services/weather_dot_com_spec.rb +0 -224
data/Rakefile CHANGED
@@ -6,27 +6,7 @@ require 'rspec/core/rake_task'
6
6
 
7
7
  RSpec::Core::RakeTask.new(:spec) do |spec|
8
8
  spec.pattern = 'spec/**/*_spec.rb'
9
- spec.rspec_opts = ["-c"]
10
- end
11
-
12
- RSpec::Core::RakeTask.new(:rcov) do |spec|
13
- spec.pattern = 'spec/**/*_spec.rb'
14
- spec.rcov = true
9
+ spec.rspec_opts = ["--color"]
15
10
  end
16
11
 
17
12
  task :default => :spec
18
-
19
- require 'rake/rdoctask'
20
- Rake::RDocTask.new do |rdoc|
21
- if File.exist?('VERSION.yml')
22
- config = YAML.load(File.read('VERSION.yml'))
23
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
24
- else
25
- version = ""
26
- end
27
-
28
- rdoc.rdoc_dir = 'rdoc'
29
- rdoc.title = "barometer #{version}"
30
- rdoc.rdoc_files.include('README*')
31
- rdoc.rdoc_files.include('lib/**/*.rb')
32
- end
data/TODO CHANGED
@@ -1,12 +1,11 @@
1
1
  == now
2
2
  - use Yahoo placemaker for geocoding (as exclusive, or as priority for supported conversions)
3
- - remove use of google api key
4
3
 
5
4
  == very soon
6
5
 
7
6
  - google geocoding terms of service indicate that "a map must be shown" ... what to do?
8
7
  - driver: hamweather
9
- - driver: meter
8
+ - driver: metar
10
9
  - improve code based on metrics
11
10
  - use Geomojo to convert coords to woe_id (when no yahoo key)
12
11
  - remove use of HTTParty, use Net:HTTP and Nokogiri instead
@@ -20,13 +19,13 @@
20
19
 
21
20
  - Rdoc compatible documentation
22
21
  - add uv, moon, elevation info to current
23
- - driver: noaa, intellicast
22
+ - driver: intellicast
24
23
  - weather.com simple_questions improve answers (use extra data)
25
24
  - make sure you can compare LocalTime to LocalDateTime in LocalTime class
26
25
 
27
26
  - be smart, never make duplicate queries
28
27
  - ie. if you are including wunderground, do it first and use the timezone info
29
-
28
+
30
29
  - conversion and weather fetching queries should have hooks to allow
31
30
  for configurable caching via memcache, then web service calls can
32
31
  be cached across multiple measurement instances.
@@ -38,15 +37,15 @@
38
37
  - Parsing dates is slow (ie Time.parse)
39
38
  for data parsing with known date/time formats, parse the
40
39
  needed information explicitly
41
-
40
+
42
41
  example:
43
-
42
+
44
43
  _parse_date(text)
45
44
  text =~ /^(\d\d\d\d)-(\d\d)-(\d\d)/
46
45
  Time.new($3,$2,$1)
47
46
  end
48
-
49
-
47
+
48
+
50
49
  == other weather info
51
50
 
52
51
  === intellicast
@@ -58,4 +57,4 @@ http://www.arl.noaa.gov/READYcmet.php
58
57
  http://www.windguru.cz/int/index.php
59
58
  http://www.nco.ncep.noaa.gov/pmb/products/gfs/
60
59
  http://www.weatherdeveloper.com/2008/01/31/grib2-migration/
61
- http://www.cpc.noaa.gov/products/wesley/wgrib2/
60
+ http://www.cpc.noaa.gov/products/wesley/wgrib2/
data/barometer.gemspec CHANGED
@@ -1,35 +1,36 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'barometer/version'
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{barometer}
5
- s.version = "0.7.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.rubygems_version = %q{1.3.5}
9
-
8
+ s.version = Barometer::VERSION
10
9
  s.authors = ["Mark G"]
11
10
  s.email = %q{barometer@attackcorp.com}
12
- s.date = %q{2011-06-02}
13
-
14
11
  s.summary = %q{A multi API consuming weather forecasting superstar.}
15
12
  s.description = %q{A multi API consuming weather forecasting superstar.}
16
13
  s.homepage = %q{http://github.com/attack/barometer}
17
14
 
18
15
  s.default_executable = %q{barometer}
19
-
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
20
  s.require_paths = ["lib"]
24
21
 
25
22
  s.rdoc_options = ["--charset=UTF-8"]
26
23
 
27
- s.add_dependency(%q<httparty>, ">= 0.4.5")
28
- s.add_dependency(%q<tzinfo>, ">= 0.3.14")
29
- s.add_dependency("nokogiri")
30
-
31
- s.add_development_dependency("rspec", "~> 2.6")
32
- s.add_development_dependency("mocha")
33
- s.add_development_dependency("fakeweb")
24
+ s.add_dependency %q<httparty>, ">= 0.4.5"
25
+ s.add_dependency %q<tzinfo>, ">= 0.3.14"
26
+ s.add_dependency "nokogiri"
27
+ s.add_dependency "yajl-ruby"
28
+ s.add_dependency "crack"
29
+
30
+ s.add_development_dependency "rspec"
31
+ s.add_development_dependency "webmock"
32
+ s.add_development_dependency "rake"
33
+ s.add_development_dependency "pry"
34
+ s.add_development_dependency "vcr"
35
+ s.add_development_dependency "fakefs"
34
36
  end
35
-
data/bin/barometer CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # == Barometer
3
+ # == Barometer
4
4
  # This is the command line interface to the barometer gem.
5
5
  #
6
6
  # == Examples
@@ -11,7 +11,7 @@
11
11
  # barometer --yahoo 90210
12
12
  # barometer --verbose 'new york'
13
13
  #
14
- # == Usage
14
+ # == Usage
15
15
  # barometer [options] query
16
16
  #
17
17
  # For help use: barometer -h
@@ -26,9 +26,8 @@
26
26
  # -i, --imperial measure in imperial
27
27
  # --wunderground add wunderground as a source
28
28
  # --yahoo add yahoo as a source
29
- # --google add google as a source
30
- # --weather add weather.com as a source
31
29
  # --bug add weather_bug as a source
30
+ # --noaa add NOAA as a source
32
31
  # -p, --pop pop threshold used to determine wet?
33
32
  # -s, --wind wind speed threshold used to determine windy?
34
33
  # -a, --at time/date used to determine when to calculate summary
@@ -38,7 +37,7 @@
38
37
  # http://github.com/attack/barometer
39
38
  #
40
39
  # == Copyright
41
- # Copyright (c) 2009-2011 Mark G. Licensed under the MIT License:
40
+ # Copyright (c) 2009-2013 Mark G. Licensed under the MIT License:
42
41
  # http://www.opensource.org/licenses/mit-license.php
43
42
 
44
43
  require 'rubygems'
@@ -53,15 +52,13 @@ require 'yaml'
53
52
 
54
53
  # file where API keys are stored
55
54
  KEY_FILE = File.expand_path(File.join('~', '.barometer'))
56
- BAROMETER_VERSION = '0.7.3'
57
55
 
58
56
  class App
59
-
60
57
  attr_reader :options
61
58
 
62
59
  def initialize(arguments, stdin)
63
60
  @arguments = arguments.dup
64
-
61
+
65
62
  # Set defaults
66
63
  @options = OpenStruct.new
67
64
  @options.timeout = 15
@@ -72,7 +69,7 @@ class App
72
69
  @options.verbose = false
73
70
  @options.at = nil
74
71
  @options.default = true
75
-
72
+
76
73
  # thresholds
77
74
  @options.windy_m = 10
78
75
  @options.windy_i = 7
@@ -81,28 +78,27 @@ class App
81
78
 
82
79
  # Parse options, check arguments, then process the command
83
80
  def run
84
- if parsed_options? && arguments_valid?
81
+ if parsed_options? && arguments_valid?
85
82
  puts "Start at #{DateTime.now}\n\n" if @options.verbose
86
83
  output_options if @options.verbose # [Optional]
87
-
88
- process_arguments
84
+
89
85
  process_command
90
-
86
+
91
87
  puts "\nFinished at #{DateTime.now}" if @options.verbose
92
88
  else
93
89
  output_usage
94
90
  end
95
91
  end
96
-
92
+
97
93
  protected
98
-
94
+
99
95
  # future options
100
96
  #
101
97
  # time: -a --at
102
98
  #
103
99
  def parsed_options?
104
100
  # Specify options
105
- opt = OptionParser.new
101
+ opt = OptionParser.new
106
102
  opt.on('-v', '--version') { output_version ; exit 0 }
107
103
  opt.on('-h', '--help') { output_help }
108
104
  opt.on('-V', '--verbose') { @options.verbose = true }
@@ -114,41 +110,22 @@ class App
114
110
  opt.on('-i', '--imperial') { @options.metric = false }
115
111
  opt.on('--wunderground') { @options.sources << :wunderground; @options.default = false }
116
112
  opt.on('--yahoo') { @options.sources << :yahoo; @options.default = false }
117
- opt.on('--google') { @options.sources << :google; @options.default = false }
118
- opt.on('--weather') { @options.sources << :weather_dot_com; @options.default = false }
119
113
  opt.on('--bug') { @options.sources << :weather_bug; @options.default = false }
114
+ opt.on('--noaa') { @options.sources << :noaa; @options.default = false }
120
115
  opt.on('-p n', '--pop n') {|n| @options.pop = n.to_i || 50 }
121
116
  opt.on('-s n', '--wind n') {|n| @options.metric ? @options.windy_m = n.to_f || 10 : @options.windy_i = n.to_f || 7 }
122
-
117
+
123
118
  opt.parse!(@arguments) rescue return false
124
-
119
+
125
120
  process_options
126
- true
127
- end
128
-
129
- def config_weather_dot_com
130
- if File.exists?(KEY_FILE)
131
- keys = YAML.load_file(KEY_FILE)
132
- if keys["weather"] && keys["weather"]["partner"] && keys["weather"]["license"]
133
- partner_key = keys["weather"]["partner"].to_s
134
- license_key = keys["weather"]["license"].to_s
135
- else
136
- weather_key_message
137
- exit
138
- end
139
- else
140
- File.open(KEY_FILE, 'w') {|f| f << "\nweather:\n partner: PARTNER_KEY\n license: LICENSE_KEY" }
141
- weather_key_message
142
- exit
143
- end
144
- { :weather_dot_com => { :keys => { :partner => partner_key, :license => license_key } } }
121
+ true
145
122
  end
146
-
123
+
147
124
  def config_weather_bug
148
125
  if File.exists?(KEY_FILE)
149
- keys = YAML.load_file(KEY_FILE)
150
- if keys["weather_bug"] && keys["weather_bug"]["code"]
151
- code = keys["weather_bug"]["code"].to_s
126
+ keys = YAML.load_file(KEY_FILE)
127
+ if keys["weather_bug"] && keys["weather_bug"]["code"]
128
+ code = keys["weather_bug"]["code"].to_s
152
129
  else
153
130
  bug_key_message
154
131
  exit
@@ -167,10 +144,6 @@ class App
167
144
  @options.sources = @options.sources.uniq
168
145
  Barometer.force_geocode = @options.geocode
169
146
  Barometer.enhance_timezone = @options.timezone
170
- if @options.sources.include?(:weather_dot_com)
171
- @options.sources.delete(:weather_dot_com)
172
- @options.sources << config_weather_dot_com
173
- end
174
147
  if @options.sources.include?(:weather_bug)
175
148
  @options.sources.delete(:weather_bug)
176
149
  @options.sources << config_weather_bug
@@ -178,11 +151,11 @@ class App
178
151
  Barometer.config = { 1 => @options.sources }
179
152
  Barometer.timeout = @options.timeout
180
153
  end
181
-
154
+
182
155
  def output_options
183
156
  puts "Options:\n"
184
-
185
- @options.marshal_dump.each do |name, val|
157
+
158
+ @options.marshal_dump.each do |name, val|
186
159
  puts " #{name} = #{val}"
187
160
  end
188
161
  puts
@@ -192,17 +165,11 @@ class App
192
165
  def arguments_valid?
193
166
  true if (@arguments.length >= 1 || @options.web)
194
167
  end
195
-
196
- # Setup the arguments
197
- def process_arguments
198
- #puts @arguments.inspect
199
- end
200
-
168
+
201
169
  def output_help
202
170
  output_version
203
- #output_usage
204
171
  end
205
-
172
+
206
173
  def output_usage
207
174
  puts "Usage: "
208
175
  puts "barometer [options] query"
@@ -219,18 +186,17 @@ class App
219
186
  puts " -i, --imperial measure in imperial"
220
187
  puts " --wunderground add wunderground as a source"
221
188
  puts " --yahoo add yahoo as a source"
222
- puts " --google add google as a source"
223
- puts " --weather add weather.com as a source"
224
189
  puts " --bug add weather_bug as a source"
190
+ puts " --noaa add NOAA as a source"
225
191
  puts " -p, --pop pop threshold used to determine wet?"
226
192
  puts " -s, --wind wind speed threshold used to determine windy?"
227
193
  puts " -a, --at time/date used to determine when to calculate summary"
228
194
  end
229
-
195
+
230
196
  def output_version
231
- puts "#{File.basename(__FILE__)} version #{BAROMETER_VERSION}"
197
+ puts "#{File.basename(__FILE__)} version #{Barometer::VERSION}"
232
198
  end
233
-
199
+
234
200
  def process_command
235
201
  barometer = Barometer.new(@arguments.join(" "))
236
202
  begin
@@ -359,7 +325,7 @@ def pretty_current(c)
359
325
  return unless c
360
326
  section("CURRENT", 2) do
361
327
  pretty_hash({
362
- "Measured at" => c.current_at, "Updated at" => c.updated_at,
328
+ "Measured at" => c.current_at, "Updated at" => c.updated_at.to_s(true),
363
329
  "Humidity" => c.humidity, "Icon" => c.icon,
364
330
  "Condition" => c.condition, "Temperature" => c.temperature,
365
331
  "Dew Point" => c.dew_point, "Heat Index" => c.heat_index,
@@ -375,7 +341,7 @@ def pretty_forecast(f)
375
341
  return unless f
376
342
  section("FOR: #{f.date}", 3) do
377
343
  pretty_hash({
378
- "Valid From" => f.valid_start_date.to_s(true),
344
+ "Valid From" => f.valid_start_date.to_s(true),
379
345
  "Valid Until" => f.valid_end_date.to_s(true),
380
346
  "Icon" => f.icon, "Description" => f.description,
381
347
  "Condition" => f.condition, "High" => f.high,
@@ -428,7 +394,7 @@ end
428
394
  def pretty_info(w)
429
395
  title("INFO", 1)
430
396
  value("GitHub", "http://github.com/attack/barometer")
431
- value("Barometer Version", BAROMETER_VERSION)
397
+ value("Barometer Version", Barometer::VERSION)
432
398
  value("Total Time", "#{(w.end_at - w.start_at)} s")
433
399
  end
434
400
 
@@ -449,18 +415,6 @@ def pretty_output(barometer)
449
415
  end
450
416
  end
451
417
 
452
- def weather_key_message
453
- puts
454
- puts "MISSING KEYS !!!"
455
- puts "Please update the key_file '#{KEY_FILE}' with your weather api keys"
456
- puts "Get it here: ???"
457
- puts "Then, add these lines to the file:"
458
- puts "weather:"
459
- puts " partner: PARTNER_KEY"
460
- puts " license: LICENSE_KEY"
461
- puts
462
- end
463
-
464
418
  def bug_key_message
465
419
  puts
466
420
  puts "MISSING KEYS !!!"
@@ -474,13 +428,12 @@ end
474
428
 
475
429
  # set API keys
476
430
  if File.exists?(KEY_FILE)
477
- keys = YAML.load_file(KEY_FILE)
478
- if keys["yahoo"] && keys["yahoo"]["app_id"]
479
- Barometer.yahoo_placemaker_app_id = keys["yahoo"]["app_id"]
431
+ keys = YAML.load_file(KEY_FILE)
432
+ if keys["yahoo"] && keys["yahoo"]["app_id"]
433
+ Barometer.yahoo_placemaker_app_id = keys["yahoo"]["app_id"]
480
434
  end
481
435
  else
482
- File.open(KEY_FILE, 'w') {|f| f << "yahoo: app_id: YOUR_KEY_KERE" }
483
- exit
436
+ File.open(KEY_FILE, 'w') {|f| f << "yahoo:\n app_id: YOUR_KEY_KERE" }
484
437
  end
485
438
 
486
439
  # Create and run the application
data/lib/barometer.rb CHANGED
@@ -1,31 +1,33 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
2
 
3
+ require 'barometer/version'
3
4
  require 'barometer/base'
4
5
  require 'barometer/query'
5
6
  require 'barometer/weather'
6
7
  require 'barometer/services'
7
8
  require 'barometer/data'
8
9
  require 'barometer/formats'
9
-
10
+ require 'barometer/key_file_parser'
11
+
10
12
  module Barometer
11
-
13
+
12
14
  @@debug_mode = false
13
15
  def self.debug; @@debug_mode; end;
14
16
  def self.debug=(value); @@debug_mode = value; end;
15
17
  def self.debug!; @@debug_mode = true; end;
16
18
  def self.debug?; @@debug_mode; end;
17
-
19
+
18
20
  def self.google_geocode_key
19
21
  warn "[DEPRECATION] `Barometer.google_geocode_key` is deprecated. A Google API key is no longer needed"
20
22
  end
21
23
  def self.google_geocode_key=(google_key)
22
24
  warn "[DEPRECATION] `Barometer.google_geocode_key=(key)` is deprecated. A Google API key is no longer needed"
23
25
  end
24
-
26
+
25
27
  @@yahoo_placemaker_app_id = nil
26
28
  def self.yahoo_placemaker_app_id; @@yahoo_placemaker_app_id; end;
27
29
  def self.yahoo_placemaker_app_id=(yahoo_key); @@yahoo_placemaker_app_id = yahoo_key; end;
28
-
30
+
29
31
  # sometimes a query is used as is and never gets geocoded (ie zipcode)
30
32
  # often, it is useful to have queries geocoded to know where in the
31
33
  # world that query points to. you can force the geocoding of
@@ -37,28 +39,28 @@ module Barometer
37
39
  def self.force_geocode; @@force_geocode; end;
38
40
  def self.force_geocode=(value); @@force_geocode = value; end;
39
41
  def self.force_geocode!; @@force_geocode = true; end;
40
-
42
+
41
43
  @@enhance_timezone = false
42
44
  def self.enhance_timezone; @@enhance_timezone; end;
43
45
  def self.enhance_timezone=(value); @@enhance_timezone = value; end;
44
46
  def self.enhance_timezone!; @@enhance_timezone = true; end;
45
-
47
+
46
48
  # adjust the timeout used when interactind with external web services
47
49
  #
48
50
  @@timeout = 15
49
51
  def self.timeout; @@timeout; end;
50
52
  def self.timeout=(value); @@timeout = value; end;
51
-
53
+
52
54
  def self.new(query=nil)
53
55
  Barometer::Base.new(query)
54
56
  end
55
-
57
+
56
58
  # update the Barometer configuration
57
59
  #
58
60
  def self.config=(config=nil)
59
61
  Barometer::Base.config = config
60
62
  end
61
-
63
+
62
64
  # shortcut to Barometer::Service.source method
63
65
  # allows Barometer.source(:wunderground)
64
66
  #
@@ -69,6 +71,6 @@ module Barometer
69
71
  # custom errors
70
72
  #
71
73
  class OutOfSources < StandardError; end
72
-
74
+
73
75
  end
74
76