attack-barometer 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.rdoc +51 -9
  2. data/VERSION.yml +1 -1
  3. data/bin/barometer +57 -7
  4. data/lib/barometer/base.rb +3 -0
  5. data/lib/barometer/data/sun.rb +10 -0
  6. data/lib/barometer/data/zone.rb +79 -188
  7. data/lib/barometer/data.rb +11 -6
  8. data/lib/barometer/formats/coordinates.rb +4 -1
  9. data/lib/barometer/formats/geocode.rb +9 -7
  10. data/lib/barometer/formats/icao.rb +2 -2
  11. data/lib/barometer/formats/weather_id.rb +2 -2
  12. data/lib/barometer/measurements/common.rb +113 -0
  13. data/lib/barometer/{data → measurements}/current.rb +17 -42
  14. data/lib/barometer/measurements/forecast.rb +62 -0
  15. data/lib/barometer/measurements/forecast_array.rb +72 -0
  16. data/lib/barometer/{data → measurements}/measurement.rb +57 -45
  17. data/lib/barometer/measurements/night.rb +27 -0
  18. data/lib/barometer/query.rb +55 -5
  19. data/lib/barometer/services.rb +3 -1
  20. data/lib/barometer/translations/zone_codes.yml +360 -0
  21. data/lib/barometer/weather.rb +5 -4
  22. data/lib/barometer/weather_services/google.rb +19 -35
  23. data/lib/barometer/weather_services/service.rb +113 -255
  24. data/lib/barometer/weather_services/weather_bug.rb +291 -2
  25. data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
  26. data/lib/barometer/weather_services/wunderground.rb +83 -89
  27. data/lib/barometer/weather_services/yahoo.rb +44 -91
  28. data/lib/barometer/web_services/geocode.rb +1 -0
  29. data/lib/barometer/web_services/timezone.rb +40 -0
  30. data/lib/barometer/web_services/weather_id.rb +17 -2
  31. data/lib/barometer.rb +11 -0
  32. data/lib/demometer/demometer.rb +28 -0
  33. data/lib/demometer/public/css/master.css +259 -1
  34. data/lib/demometer/views/index.erb +2 -0
  35. data/lib/demometer/views/layout.erb +3 -2
  36. data/lib/demometer/views/measurement.erb +4 -1
  37. data/lib/demometer/views/readme.erb +116 -88
  38. data/spec/data/sun_spec.rb +53 -0
  39. data/spec/data/zone_spec.rb +330 -100
  40. data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
  41. data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
  42. data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
  43. data/spec/formats/weather_id_spec.rb +10 -5
  44. data/spec/measurements/common_spec.rb +352 -0
  45. data/spec/{data → measurements}/current_spec.rb +40 -103
  46. data/spec/measurements/forecast_array_spec.rb +165 -0
  47. data/spec/measurements/forecast_spec.rb +135 -0
  48. data/spec/{data → measurements}/measurement_spec.rb +86 -107
  49. data/spec/measurements/night_measurement_spec.rb +49 -0
  50. data/spec/query_spec.rb +12 -2
  51. data/spec/spec_helper.rb +28 -1
  52. data/spec/weather_services/google_spec.rb +27 -117
  53. data/spec/weather_services/services_spec.rb +49 -1024
  54. data/spec/weather_services/weather_bug_spec.rb +274 -0
  55. data/spec/weather_services/weather_dot_com_spec.rb +45 -125
  56. data/spec/weather_services/wunderground_spec.rb +42 -136
  57. data/spec/weather_services/yahoo_spec.rb +26 -116
  58. data/spec/weather_spec.rb +45 -45
  59. metadata +23 -11
  60. data/lib/barometer/data/forecast.rb +0 -84
  61. data/lib/barometer/data/night.rb +0 -69
  62. data/lib/barometer/extensions/graticule.rb +0 -51
  63. data/spec/data/forecast_spec.rb +0 -192
  64. data/spec/data/night_measurement_spec.rb +0 -136
@@ -1 +1,259 @@
1
- /* nothing to see here */
1
+ /*
2
+ Copyright: Blake Mizerany, www.sinatrarb.com
3
+ Permission Pending
4
+ */
5
+
6
+ body {
7
+ color:#000;
8
+ font-family:'lucida grande', 'lucida sans unicade', sans-serif;
9
+ font-size:100%;
10
+ line-height:1.3;
11
+ background-color:#fff;
12
+ margin:0;
13
+ padding:0;
14
+ }
15
+
16
+ /* HEADER */
17
+ #head {
18
+ text-align:center;
19
+ }
20
+ #head img {
21
+ vertical-align:middle;
22
+ margin:-10px 0 0 -82px;
23
+ padding:0 15px 0 0;
24
+ border:0;
25
+ }
26
+ #head h1 {
27
+ color:#000;
28
+ font-family:'georgia', 'bitstream vera serif', serif;
29
+ font-size:4em;
30
+ font-weight:normal;
31
+ letter-spacing:-3px;
32
+ line-height:1;
33
+ margin:0;
34
+ padding:20px 0 8px 0;
35
+ }
36
+ #head h1 a, #head h1 a:link, #head h1 a:visited, #head h1 a:hover {
37
+ color:#100;
38
+ text-decoration:none;
39
+ }
40
+ #head ul {
41
+ font-size:1.1em;
42
+ font-family:"lucida console", "monaco", "andale mono", "bitstream vera sans mono",
43
+ "consolas", monospace;
44
+ font-weight:normal;
45
+ text-transform:uppercase;
46
+ letter-spacing:2px;
47
+ text-align:center;
48
+ margin:0;
49
+ padding:0 40px 0.25em 40px;
50
+ }
51
+ #head ul li {
52
+ display:inline;
53
+ list-style-type:none;
54
+ padding:0 0.5em 0 0;
55
+ }
56
+ #head ul a, #head ul a:link, #head ul a:visited {
57
+ color:#56534f;
58
+ text-decoration:none;
59
+ }
60
+ #head ul a:hover {
61
+ color:#000;
62
+ text-decoration:underline
63
+ }
64
+
65
+ /* CONTENT */
66
+
67
+ #content {
68
+ color:#333;
69
+ font-size:1.1em;
70
+ max-width:44em;
71
+ min-width:27em;
72
+ margin:7px auto;
73
+ border-top:2px solid #837d7c;
74
+ }
75
+ strong {
76
+ font-weight:bold;
77
+ }
78
+
79
+ /* HEADINGS */
80
+
81
+ h1, h2, h3, h4, h5, h6 {
82
+ color:#000;
83
+ }
84
+ h1, h2 {
85
+ color:#211d1f;
86
+ font-family:'georgia', 'bitstream vera serif', serif;
87
+ font-weight:normal;
88
+ }
89
+ h1 a, h2 a { color:#222 }
90
+ h1 {
91
+ font-size:2.25em;
92
+ letter-spacing:-1px;
93
+ margin-bottom:0;
94
+ }
95
+ h2 {
96
+ font-size:1.5em;
97
+ letter-spacing:-1px;
98
+ margin:1.25em 0 -0.32em 0;
99
+ }
100
+ h3 {
101
+ color:#211d1f;
102
+ font-size:1.02em;
103
+ font-weight:bold;
104
+ margin:1.8em 0 -0.25em 0;
105
+ letter-spacing:-1px;
106
+ }
107
+ h3 a {
108
+ color:#000;
109
+ text-decoration:underline;
110
+ }
111
+
112
+ /* LINKS */
113
+ a {
114
+ color:#000;
115
+ text-decoration:underline;
116
+ }
117
+ a:hover {
118
+ color:#910;
119
+ text-decoration:underline;
120
+ }
121
+ a img {
122
+ border:none;
123
+ }
124
+ a.out {
125
+ background: url('/images/link-out.gif') center right no-repeat;
126
+ padding-right: 12px;
127
+ }
128
+
129
+
130
+ /* CODE */
131
+
132
+ code, pre, textarea, tt {
133
+ font-family:"lucida console", "monaco", "andale mono", "bitstream vera sans mono",
134
+ "consolas", monospace;
135
+ }
136
+ pre {
137
+ font-size:0.85em;
138
+ background:#f4f5f5;
139
+ border:2px solid #d5d0d2;
140
+ padding:0.5em;
141
+ line-height:1.15;
142
+ color:#222;
143
+ }
144
+ code, tt {
145
+ font-size:0.85em;
146
+ color:#444;
147
+ }
148
+ h1 code, h2 code, h3 code, h4 code {
149
+ color:#333;
150
+ }
151
+ pre code {
152
+ font-size:1em;
153
+ color:#222;
154
+ }
155
+
156
+ /* MISC */
157
+
158
+ hr {
159
+ margin:3em 0;
160
+ padding:0;
161
+ color:#eee;
162
+ }
163
+
164
+ /* HOME */
165
+
166
+ body#home {
167
+ background: #fff url(../images/legend.gif) no-repeat fixed right 130px;
168
+ }
169
+ #home #content {
170
+ font-size:1.05em;
171
+ margin:20px 0 0 0;
172
+ padding:0 20px;
173
+ border-width:0;
174
+ }
175
+ #home #head, #home #foot {
176
+ display:none;
177
+ }
178
+ .pipe {
179
+ clear:both;
180
+ padding:50px 0;
181
+ }
182
+ .pipe p {
183
+ color:#000;
184
+ font-size:62px;
185
+ font-family:'georgia', 'bitstream vera serif', serif;
186
+ letter-spacing:-3px;
187
+ line-height:1;
188
+ text-align:right;
189
+ margin:0em 43% 0 0;
190
+ padding:0 60px 0 0;
191
+ }
192
+ .pipe pre {
193
+ float:right;
194
+ background:transparent;
195
+ font-size:28px;
196
+ margin:0;
197
+ padding:5px 0 0 0;
198
+ width:42%;
199
+ border-width:0;
200
+ }
201
+ .pipe pre code {
202
+ color:#666;
203
+ background:transparent;
204
+ }
205
+ .pipe.shell p {
206
+ font-size:56px;
207
+ }
208
+ .pipe.shell pre {
209
+ font-size:18px;
210
+ }
211
+ .pipe.nav p {
212
+ font-size:100px;
213
+ letter-spacing:-6px;
214
+ }
215
+ .pipe.nav pre {
216
+ font-size:36px;
217
+ padding-top:20px;
218
+ text-transform:uppercase;
219
+ letter-spacing:4px;
220
+ line-height:1.25;
221
+ }
222
+ .pipe.nav {
223
+ padding:25px 0 50px 0;
224
+ }
225
+ .pipe.nav a, .pipe.nav a:link, .pipe.nav a:visited {
226
+ color:#444;
227
+ text-decoration:none;
228
+ }
229
+ .pipe.nav a:hover {
230
+ color:#000;
231
+ text-decoration:underline;
232
+ }
233
+
234
+ form {
235
+ text-align: center;
236
+ }
237
+
238
+ form .text-input input {
239
+ font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Arial, sans-serif;
240
+ margin: 10px 0 5px 10px;
241
+ color: #686868;
242
+ font-size: 40px;
243
+ text-align: left;
244
+ text-transform: lowercase;
245
+ }
246
+
247
+ form .submit-input input {
248
+ position: relative;
249
+ margin: 0 7% 0 0;
250
+ float: right;
251
+ }
252
+
253
+ form .options-input {
254
+ position: relative;
255
+ margin: 0 7% 0 0;
256
+ float: left;
257
+ text-align: left;
258
+ }
259
+
@@ -18,6 +18,7 @@
18
18
  <input type="checkbox" name="query[source]" value="yahoo" /> Yahoo
19
19
  <input type="checkbox" name="query[source]" value="google" /> Google
20
20
  <input type="checkbox" name="query[source]" value="weather_dot_com" /> Weather.com
21
+ <input type="checkbox" name="query[source]" value="weather_bug" /> Weather Bug
21
22
  <br/>
22
23
  Force Geocode? :
23
24
  <input id="query_geocode" name="query[geocode]" type="checkbox" value="1" checked="checked" />
@@ -81,6 +82,7 @@
81
82
  <% end %>
82
83
 
83
84
  <% @weather.measurements.each do |measurement| %>
85
+ <hr/>
84
86
  <%= erb(:measurement, :locals => { :measurement => measurement }, :layout => false) %>
85
87
  <% end %>
86
88
 
@@ -3,10 +3,10 @@
3
3
  <head>
4
4
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
5
  <title>Barometer</title>
6
- <!--> <link rel='stylesheet' href='/css/master.css' type='text/css' media="screen, projection">
6
+ <link rel='stylesheet' href='/css/master.css' type='text/css' media="screen, projection">
7
7
  <link rel='stylesheet' href='/css/syntax.css' type='text/css' media="screen, projection">
8
8
  <link rel='stylesheet' href='/css/print.css' type='text/css' media="print">
9
- <link rel='shortcut icon' href='/images/favicon.ico'>-->
9
+ <!--><link rel='shortcut icon' href='/images/favicon.ico'>-->
10
10
  <link rel='alternate' href='http://attack.github.com/feed.xml' type='application/atom+xml' title='Barometers Blog'>
11
11
 
12
12
  </head>
@@ -21,6 +21,7 @@
21
21
  <li><a href='/readme.html'>README</a></li>
22
22
  <li><a href='/contributing.html'>Contribute</a></li>
23
23
  <li><a class="out" href='http://github.com/attack/barometer'>Code</a></li>
24
+ <li><a href='/about.html'>About</a></li>
24
25
  </ul>
25
26
  </div>
26
27
 
@@ -6,6 +6,7 @@
6
6
  <%= data("Time Stamp", measurement.utc_time_stamp) %>
7
7
  <%= data("Metric", measurement.metric?) %>
8
8
  <%= data("Success", measurement.success?) %>
9
+ <%= data("Service Time", "#{(measurement.end_at - measurement.start_at)} s") %>
9
10
  </ul>
10
11
  <ul>- Modified Query -
11
12
  <%= data("Query", measurement.query) %>
@@ -54,9 +55,11 @@
54
55
  <h3>Timezone</h3>
55
56
  <p>
56
57
  <ul>
57
- <%= data("Long", measurement.timezone.timezone) %>
58
+ <%= data("Long", measurement.timezone.full) %>
58
59
  <%= data("Code", measurement.timezone.code) %>
59
60
  <%= data("DST?", measurement.timezone.dst?) %>
61
+ <%= data("Now", measurement.timezone.now(true)) %>
62
+ <%= data("Today", measurement.timezone.today) %>
60
63
  </ul>
61
64
  </p>
62
65
  <% end %>
@@ -9,35 +9,45 @@ information, or they can be used in a hierarchical configuration where
9
9
  lower preferred weather services are only used if previous services are
10
10
  unavailable.
11
11
  </p>
12
+ <p>
13
+ Barometer handles all conversions of the supplied query, so that the same
14
+ query can be used for all (or most) services, even if they don&#8217;t
15
+ support the query directly. See the &quot;Query&quot; section for more
16
+ information on this.
17
+ </p>
12
18
  <h2>version</h2>
13
19
  <p>
14
- Version 0.3.3 is the current release of this gem. The gem is available from
20
+ Version 0.6.0 is the current release of this gem. The gem is available from
15
21
  github (attack-barometer) or rubyforge (barometer). It is fully functional
16
- (for three weather service APIs).
22
+ (for five weather service APIs).
17
23
  </p>
18
24
  <h2>status</h2>
19
-
20
25
  <p>
21
26
  Currently this project is in development and will only work for a few
22
- weather services (wunderground, google, yahoo).
27
+ weather services (wunderground, google, yahoo, weather.com, weather_bug).
23
28
  </p>
24
29
  <p>
25
30
  Features to be added next:
26
31
  </p>
27
32
  <ul>
28
- <li>even more weather service drivers (noaa, weather.com, weatherbug)
33
+ <li>even more weather service drivers (noaa)
34
+
35
+ </li>
36
+ <li>icon support
29
37
 
30
38
  </li>
31
39
  </ul>
32
40
  <h1>dependencies</h1>
33
- <h3>Google API key</h3>
41
+ <h2>Google API key</h2>
34
42
  <p>
35
43
  In most cases you will need to have a free google geocode api key. Get one
36
44
  here: <a href="http://code.google.com/apis/maps/signup.html">code.google.com/apis/maps/signup.html</a>
37
-
38
- Then put it in the file &#8217;~/.barometer&#8217; by adding the line:
39
- geocode_google: YOUR_KEY_HERE
45
+ Then put it in the file &#8217;~/.barometer&#8217; by adding the lines:
40
46
  </p>
47
+ <pre>
48
+ google:
49
+ geocode: YOUR_KEY_HERE
50
+ </pre>
41
51
  <p>
42
52
  You will need this for:
43
53
  </p>
@@ -54,8 +64,26 @@ doesn&#8217;t require any geocoding)
54
64
 
55
65
  </li>
56
66
  </ul>
57
-
58
- <h3>HTTParty</h3>
67
+ <h3>other keys</h3>
68
+ <p>
69
+ The same file can hold all your weather service API keys.
70
+ </p>
71
+ <p>
72
+ eg. weather.com
73
+ </p>
74
+ <pre>
75
+ weather:
76
+ partner: YOUR_PARTNER_KEY
77
+ license: YOUR_LICENSE_KEY
78
+ </pre>
79
+ <p>
80
+ eg. weatherbug.com
81
+ </p>
82
+ <pre>
83
+ weather_bug:
84
+ code: YOUR_API_CODE
85
+ </pre>
86
+ <h2>HTTParty</h2>
59
87
  <p>
60
88
  Why? HTTParty was created and designed specifically for consuming web
61
89
  services. I choose to use this over using the Net::HTTP library directly to
@@ -64,41 +92,67 @@ allow for faster development of this project.
64
92
  <p>
65
93
  HTTParty is also extended to include configurable Timeout support.
66
94
  </p>
67
- <h3>tzinfo</h3>
95
+ <h2>tzinfo</h2>
68
96
  <p>
69
97
  Why? Barometer deals with time information for locations all over the
70
98
  world. This information doesn&#8217;t mean that much if it can&#8217;t be
71
99
  converted to times that don&#8217;t correspond to the applicable timezone.
72
100
  Tzinfo handles this time zone manipulation.
73
101
  </p>
74
- <h3>graticule (very soft dependency)</h3>
75
-
102
+ <h1>queries</h1>
76
103
  <p>
77
- Why? Barometer returns the weather for a given location. Most weather
78
- service APIs are somewhat restricted on the query format they receive. To
79
- bridge this gap and allow for maximum flexibility on the
80
- &#8216;barometer&#8217; query format, the query will be geo-coded using the
81
- Google geocoding service, if required. Graticule can provide this geocoding
82
- interface.
104
+ The query handling is one of the most beneficial and powerful features of
105
+ Barometer. Every weather service accepts a different set of possible
106
+ queries, so it usually the case that the same query can only be used for a
107
+ couple weather services.
83
108
  </p>
84
109
  <p>
85
- Using Graticule requires a free Google API key for geocoding. It is
86
- possible to use barometer without geocoding, though your query format will
87
- be limited to that of the weather service API.
110
+ Barometer will allow the use of all query formats for all services
111
+ (mostly). It does this by first determining the original query format, then
112
+ converting the query to a compatible format for each specific weather
113
+ service.
88
114
  </p>
89
115
  <p>
90
- ALTERNATE: If you supply a Google API key but don&#8217;t install the
91
- Graticule gem, HTTParty will be used instead to provide the same geocoding.
92
- Basically Graticule is only used if it exists.
116
+ For example, Yahoo! only accepts US Zip Code or Weather.com ID. With
117
+ Barometer you can query Yahoo! with a simple location (ie: Paris) or even
118
+ an Airport code (ICAO) and it will return the weather as expected.
93
119
  </p>
120
+ <h2>acceptable formats</h2>
121
+ <ul>
122
+ <li>zipcode
123
+
124
+ </li>
125
+ <li>icao (international airport code)
126
+
127
+ </li>
128
+ <li>coordinates (latitude and longitude)
129
+
130
+ </li>
131
+ <li>postal code
132
+
133
+ </li>
134
+ <li>weather.com ID
135
+
136
+ </li>
137
+ <li>location name (ie address, city, state, landmark, etc.)
138
+
139
+ </li>
140
+ <li>if the query is of the formats zipcode or postal code it may not support
141
+ conversion to other formats.
142
+
143
+ </li>
144
+ </ul>
145
+ <h2>conversion caching</h2>
94
146
  <p>
95
- NOTE: you can force Barometer not to use Graticule, even if you have it
96
- installed using the following:
147
+ Barometer has internal conversion caching. No conversion will be repeated
148
+ during a measurement, thus limiting the number of web queries needed.
149
+ </p>
150
+ <p>
151
+ Example: If you configure Barometer to use both Yahoo and Weather.com, then
152
+ use a query like &quot;denver&quot;, this will require a conversion from
153
+ &quot;denver&quot; to its weather.com weather_id. This conversion is needed
154
+ for both web services but will only happen once and be cached.
97
155
  </p>
98
- <pre>
99
-
100
- Barometer.skip_graticule = true
101
- </pre>
102
156
  <h1>usage</h1>
103
157
  <p>
104
158
  You can use barometer right out of the box, as it is configured to use one
@@ -117,7 +171,17 @@ with geo-coding.
117
171
  weather = barometer.measure
118
172
 
119
173
  puts weather.current.temperture
120
-
174
+ </pre>
175
+ <h2>sources</h2>
176
+ <p>
177
+ The available sources are:
178
+ </p>
179
+ <pre>
180
+ Wunderground.com (:wunderground) [default]
181
+ Yahoo! Weather (:yahoo)
182
+ Google Weather (:google)
183
+ Weather.com (:weather_dot_com)
184
+ WeatherBug.com (:weather_bug)
121
185
  </pre>
122
186
  <h2>source configuration</h2>
123
187
  <p>
@@ -133,7 +197,6 @@ Weather services in parallel
133
197
  </pre>
134
198
  <p>
135
199
  Weather services in primary/failover
136
-
137
200
  </p>
138
201
  <pre>
139
202
  Barometer.config = { 1 =&gt; [:yahoo], 2 =&gt; :wunderground }
@@ -144,7 +207,12 @@ a weight value, this weight is respected when calculating averages.
144
207
  </p>
145
208
  <pre>
146
209
  Barometer.config = { 1 =&gt; [{:wunderground =&gt; {:weight =&gt; 2}}, :google] }
147
-
210
+ </pre>
211
+ <p>
212
+ Weather services, one with keys.
213
+ </p>
214
+ <pre>
215
+ Barometer.config = { 1 =&gt; [:yahoo, {:weather_dot_com =&gt; {:keys =&gt; {:partner =&gt; PARTNER_KEY, :license =&gt; LICENSE_KEY } }}] }
148
216
  </pre>
149
217
  <h3>multiple weather API, with hierarchy</h3>
150
218
  <pre>
@@ -159,7 +227,6 @@ a weight value, this weight is respected when calculating averages.
159
227
 
160
228
  puts weather.current.temperture
161
229
  </pre>
162
-
163
230
  <h2>command line</h2>
164
231
  <p>
165
232
  You can use barometer from the command line.
@@ -175,7 +242,6 @@ for more command line information.
175
242
  # barometer -h
176
243
  </pre>
177
244
  <h3>web demo</h3>
178
-
179
245
  <p>
180
246
  There is a Sinatra application that demos the functionality of Barometer,
181
247
  and provides Barometer information. Start this local demo with:
@@ -187,7 +253,6 @@ and provides Barometer information. Start this local demo with:
187
253
  NOTE: This requires the gems &quot;sinatra&quot; and &quot;vegas&quot;.
188
254
  </p>
189
255
  <h3>fail</h3>
190
-
191
256
  <p>
192
257
  What would cause a weather service to fail? The most obvious is that the
193
258
  particular weather service in currently unavailable or not reachable. Other
@@ -202,41 +267,7 @@ supports weather results for USA (at least at the time of writing).
202
267
  Therefore, Barometer would not use Yahoo, just Google and failover to use
203
268
  Wunderground (if needed).
204
269
  </p>
205
- <h3>bootstrapping</h3>
206
- <p>
207
- You can use weather service drivers directly. Below is an example to use
208
- Wunderground, but since the driver interface is abstracted it will be the
209
- same for all supported services.
210
- </p>
211
- <pre>
212
- require 'barometer'
213
- Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
214
-
215
- query = Barometer::Query.new(&quot;Paris&quot;)
216
- weather = Barometer::Service.source(:wunderground).measure(query)
217
-
218
- puts weather.current.temperture
219
-
220
- # OR, even more raw
221
-
222
- measurement = Barometer::Measurement.new
223
- weather = Barometer::Wunderground.measure_all(measurement, &quot;Paris&quot;)
224
-
225
- puts weather.current.temperture
226
- </pre>
227
- <p>
228
- NOTE: The disadvantage to using the drivers directly is that you lose the
229
- advantage of redundancy/failover added by the Module as a whole.
230
- </p>
231
- <p>
232
- NOTE: You still must create the Barometer::Query object with your query
233
- string instead of directly feeding the query string to the service (as in
234
- bootstrap example #1). The Barometer::Query object has behavior required by
235
- the service that a regular String doesn&#8217;t have. Using a driver
236
- directly WILL accept a String (as in bootstrap example #2).
237
- </p>
238
270
  <h2>searching</h2>
239
-
240
271
  <p>
241
272
  After you have measured the data, Barometer provides several methods to
242
273
  help you get the data you are after. All examples assume you already have
@@ -261,7 +292,6 @@ measured the data as shown in the above examples.
261
292
 
262
293
  puts weather.source(:wunderground).current.temperature.c
263
294
  </pre>
264
-
265
295
  <h3>by date</h3>
266
296
  <pre>
267
297
  # note, the date is the date of the locations weather, not the date of the
@@ -283,7 +313,6 @@ measured the data as shown in the above examples.
283
313
  puts weather.source(:wunderground).for(time).low.f
284
314
  </pre>
285
315
  <h2>averages</h2>
286
-
287
316
  <p>
288
317
  If you consume more then one weather service, Barometer can provide
289
318
  averages for the values (currently only for the &#8216;current&#8217;
@@ -300,7 +329,6 @@ values and not the forecasted values).
300
329
  weather = barometer.measure
301
330
 
302
331
  puts weather.temperture
303
-
304
332
  </pre>
305
333
  <p>
306
334
  This will calculate the average temperature as given by :yahoo and
@@ -318,7 +346,6 @@ After you have measured the data, Barometer provides several &quot;simple
318
346
  answer&quot; methods to help you get answers to some basic questions. All
319
347
  examples assume you already have measured the data as shown in the above
320
348
  examples.
321
-
322
349
  </p>
323
350
  <p>
324
351
  All of these questions are ultimately specific to the weather source(s) you
@@ -345,7 +372,6 @@ there will be no answer.
345
372
  weather.wet?(50)
346
373
  </pre>
347
374
  <h3>is it sunny?</h3>
348
-
349
375
  <pre>
350
376
  # 1st parameter is the utc_time for which you want to know the answer,
351
377
  # this defaults to the current time
@@ -367,7 +393,6 @@ there will be no answer.
367
393
  weather.night?
368
394
  </pre>
369
395
  <h1>design</h1>
370
-
371
396
  <ul>
372
397
  <li>create a Barometer instance
373
398
 
@@ -378,27 +403,31 @@ there will be no answer.
378
403
  <li>city, country, specific address (basically anything Google will geocode)
379
404
 
380
405
  </li>
381
- <li>US zip code (skips geocoding if weather service accepts this directly)
406
+ <li>US zip code (skips conversion if weather service accepts this directly)
382
407
 
383
408
  </li>
384
- <li>postal code (skips geocoding if weather service accepts this directly)
409
+ <li>postal code (skips conversion if weather service accepts this directly)
385
410
 
386
411
  </li>
387
- <li>latitude and longitude (skips geocoding if weather service accepts this
412
+ <li>latitude and longitude (skips conversion if weather service accepts this
388
413
  directly)
389
414
 
390
415
  </li>
391
- <li>TODO: international airport code (skips geocoding if weather service
392
- accepts this directly)
416
+ <li>weather.com weather id (even if the service you are using doesn&#8217;t use
417
+ it)
418
+
419
+ </li>
420
+ <li>international airport code (skips conversion if weather service accepts
421
+ this directly)
393
422
 
394
423
  </li>
395
424
  </ul>
396
425
  </li>
397
-
398
- <li>if geocoding required, geocode the query
426
+ <li>determine which weather services will be queried (one or multiple)
399
427
 
400
428
  </li>
401
- <li>determine which weather services will be queried (one or multiple)
429
+ <li>if query conversion required for specific weather service, convert the
430
+ query
402
431
 
403
432
  </li>
404
433
  <li>query the weather services
@@ -417,9 +446,8 @@ Barometer attempts to be a common API to any weather service API. I have
417
446
  included several weather service &#8216;drivers&#8217;, but I know there
418
447
  are many more available. Please use the provided ones as examples to create
419
448
  more.
420
-
421
449
  </p>
422
450
  <h2>copyright</h2>
423
451
  <p>
424
452
  Copyright &#169; 2009 Mark G. See LICENSE for details.
425
- </p>
453
+ </p>