barometer 0.5.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +51 -9
- data/VERSION.yml +2 -2
- data/bin/barometer +57 -7
- data/lib/barometer.rb +11 -0
- data/lib/barometer/base.rb +3 -0
- data/lib/barometer/data.rb +11 -6
- data/lib/barometer/data/sun.rb +10 -0
- data/lib/barometer/data/zone.rb +79 -188
- data/lib/barometer/formats/coordinates.rb +4 -1
- data/lib/barometer/formats/geocode.rb +9 -7
- data/lib/barometer/formats/icao.rb +2 -2
- data/lib/barometer/formats/weather_id.rb +2 -2
- data/lib/barometer/measurements/common.rb +113 -0
- data/lib/barometer/{data → measurements}/current.rb +17 -42
- data/lib/barometer/measurements/forecast.rb +62 -0
- data/lib/barometer/measurements/forecast_array.rb +72 -0
- data/lib/barometer/{data → measurements}/measurement.rb +57 -45
- data/lib/barometer/measurements/night.rb +27 -0
- data/lib/barometer/query.rb +55 -5
- data/lib/barometer/services.rb +3 -1
- data/lib/barometer/translations/icao_country_codes.yml +274 -1
- data/lib/barometer/translations/weather_country_codes.yml +189 -6
- data/lib/barometer/translations/zone_codes.yml +360 -0
- data/lib/barometer/weather.rb +5 -4
- data/lib/barometer/weather_services/google.rb +19 -35
- data/lib/barometer/weather_services/service.rb +113 -255
- data/lib/barometer/weather_services/weather_bug.rb +291 -2
- data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
- data/lib/barometer/weather_services/wunderground.rb +83 -89
- data/lib/barometer/weather_services/yahoo.rb +44 -91
- data/lib/barometer/web_services/geocode.rb +1 -0
- data/lib/barometer/web_services/timezone.rb +40 -0
- data/lib/barometer/web_services/weather_id.rb +17 -2
- data/lib/demometer/demometer.rb +28 -0
- data/lib/demometer/public/css/master.css +259 -1
- data/lib/demometer/public/css/print.css +94 -0
- data/lib/demometer/public/css/syntax.css +64 -0
- data/lib/demometer/public/images/link-out.gif +0 -0
- data/lib/demometer/views/about.erb +10 -0
- data/lib/demometer/views/index.erb +2 -0
- data/lib/demometer/views/layout.erb +3 -2
- data/lib/demometer/views/measurement.erb +4 -1
- data/lib/demometer/views/readme.erb +116 -88
- data/spec/data/sun_spec.rb +53 -0
- data/spec/data/zone_spec.rb +330 -100
- data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
- data/spec/formats/weather_id_spec.rb +10 -5
- data/spec/measurements/common_spec.rb +352 -0
- data/spec/{data → measurements}/current_spec.rb +40 -103
- data/spec/measurements/forecast_array_spec.rb +165 -0
- data/spec/measurements/forecast_spec.rb +135 -0
- data/spec/{data → measurements}/measurement_spec.rb +86 -107
- data/spec/measurements/night_measurement_spec.rb +49 -0
- data/spec/query_spec.rb +12 -2
- data/spec/spec_helper.rb +28 -1
- data/spec/weather_services/google_spec.rb +27 -117
- data/spec/weather_services/services_spec.rb +49 -1024
- data/spec/weather_services/weather_bug_spec.rb +274 -0
- data/spec/weather_services/weather_dot_com_spec.rb +45 -125
- data/spec/weather_services/wunderground_spec.rb +42 -136
- data/spec/weather_services/yahoo_spec.rb +26 -116
- data/spec/weather_spec.rb +45 -45
- metadata +27 -11
- data/lib/barometer/data/forecast.rb +0 -84
- data/lib/barometer/data/night.rb +0 -69
- data/lib/barometer/extensions/graticule.rb +0 -51
- data/spec/data/forecast_spec.rb +0 -192
- data/spec/data/night_measurement_spec.rb +0 -136
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
Copyright: Blake Mizerany, www.sinatrarb.com
|
3
|
+
Permission Pending
|
4
|
+
*/
|
5
|
+
.highlight { background: #ffffff; }
|
6
|
+
.highlight .c { color: #999988; font-style: italic } /* Comment */
|
7
|
+
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
8
|
+
.highlight .k { font-weight: bold; } /* Keyword */
|
9
|
+
.highlight .o { font-weight: bold } /* Operator */
|
10
|
+
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
11
|
+
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
|
12
|
+
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
13
|
+
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
|
14
|
+
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
15
|
+
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
|
16
|
+
.highlight .ge { font-style: italic } /* Generic.Emph */
|
17
|
+
.highlight .gr { color: #aa0000 } /* Generic.Error */
|
18
|
+
.highlight .gh { color: #999999 } /* Generic.Heading */
|
19
|
+
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
20
|
+
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
|
21
|
+
.highlight .go { color: #888888 } /* Generic.Output */
|
22
|
+
.highlight .gp { color: #555555 } /* Generic.Prompt */
|
23
|
+
.highlight .gs { font-weight: bold } /* Generic.Strong */
|
24
|
+
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
|
25
|
+
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
|
26
|
+
.highlight .kc { font-weight: bold } /* Keyword.Constant */
|
27
|
+
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
|
28
|
+
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
|
29
|
+
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
|
30
|
+
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
|
31
|
+
.highlight .m { color: #009999 } /* Literal.Number */
|
32
|
+
.highlight .s { color: #444 } /* Literal.String */
|
33
|
+
.highlight .na { color: #008080 } /* Name.Attribute */
|
34
|
+
.highlight .nb { color: #0086B3 } /* Name.Builtin */
|
35
|
+
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
|
36
|
+
.highlight .no { color: #008080 } /* Name.Constant */
|
37
|
+
.highlight .ni { color: #800080 } /* Name.Entity */
|
38
|
+
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
39
|
+
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
|
40
|
+
.highlight .nn { color: #555555 } /* Name.Namespace */
|
41
|
+
.highlight .nt { color: #000080 } /* Name.Tag */
|
42
|
+
.highlight .nv { color: #008080 } /* Name.Variable */
|
43
|
+
.highlight .ow { font-weight: bold } /* Operator.Word */
|
44
|
+
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
|
45
|
+
.highlight .mf { color: #009999 } /* Literal.Number.Float */
|
46
|
+
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
|
47
|
+
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
|
48
|
+
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
|
49
|
+
.highlight .sb { color: #444 } /* Literal.String.Backtick */
|
50
|
+
.highlight .sc { color: #444 } /* Literal.String.Char */
|
51
|
+
.highlight .sd { color: #444 } /* Literal.String.Doc */
|
52
|
+
.highlight .s2 { color: #444 } /* Literal.String.Double */
|
53
|
+
.highlight .se { color: #444 } /* Literal.String.Escape */
|
54
|
+
.highlight .sh { color: #444 } /* Literal.String.Heredoc */
|
55
|
+
.highlight .si { color: #444 } /* Literal.String.Interpol */
|
56
|
+
.highlight .sx { color: #444 } /* Literal.String.Other */
|
57
|
+
.highlight .sr { color: #009926 } /* Literal.String.Regex */
|
58
|
+
.highlight .s1 { color: #444 } /* Literal.String.Single */
|
59
|
+
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
|
60
|
+
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
61
|
+
.highlight .vc { color: #008080 } /* Name.Variable.Class */
|
62
|
+
.highlight .vg { color: #008080 } /* Name.Variable.Global */
|
63
|
+
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
|
64
|
+
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1 id='about'>About</h1>
|
2
|
+
|
3
|
+
<p>Barometer was designed and developed by <strong>Mark G</strong> (attack).</p>
|
4
|
+
|
5
|
+
<p>Special thanks to the following individuals:</p>
|
6
|
+
|
7
|
+
<ul>
|
8
|
+
<li><a href='http://sinatra.github.com/'>Blake Mizerany</a> (bmizerany) for Sinatra and
|
9
|
+
the layout for this demo app (permission pending).</li>
|
10
|
+
</ul>
|
@@ -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
|
-
|
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
|
-
|
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.
|
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’t
|
15
|
+
support the query directly. See the "Query" section for more
|
16
|
+
information on this.
|
17
|
+
</p>
|
12
18
|
<h2>version</h2>
|
13
19
|
<p>
|
14
|
-
Version 0.
|
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
|
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
|
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
|
-
<
|
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 ’~/.barometer’ by adding the line:
|
39
|
-
geocode_google: YOUR_KEY_HERE
|
45
|
+
Then put it in the file ’~/.barometer’ 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’t require any geocoding)
|
|
54
64
|
|
55
65
|
</li>
|
56
66
|
</ul>
|
57
|
-
|
58
|
-
<
|
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
|
-
<
|
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’t mean that much if it can’t be
|
71
99
|
converted to times that don’t correspond to the applicable timezone.
|
72
100
|
Tzinfo handles this time zone manipulation.
|
73
101
|
</p>
|
74
|
-
<
|
75
|
-
|
102
|
+
<h1>queries</h1>
|
76
103
|
<p>
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
96
|
-
|
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 "denver", this will require a conversion from
|
153
|
+
"denver" 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 => [:yahoo], 2 => :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 => [{:wunderground => {:weight => 2}}, :google] }
|
147
|
-
|
210
|
+
</pre>
|
211
|
+
<p>
|
212
|
+
Weather services, one with keys.
|
213
|
+
</p>
|
214
|
+
<pre>
|
215
|
+
Barometer.config = { 1 => [:yahoo, {:weather_dot_com => {:keys => {:partner => PARTNER_KEY, :license => 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 "sinatra" and "vegas".
|
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 = "THE_GOOGLE_API_KEY"
|
214
|
-
|
215
|
-
query = Barometer::Query.new("Paris")
|
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, "Paris")
|
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’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 ‘current’
|
@@ -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 "simple
|
|
318
346
|
answer" 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
|
406
|
+
<li>US zip code (skips conversion if weather service accepts this directly)
|
382
407
|
|
383
408
|
</li>
|
384
|
-
<li>postal code (skips
|
409
|
+
<li>postal code (skips conversion if weather service accepts this directly)
|
385
410
|
|
386
411
|
</li>
|
387
|
-
<li>latitude and longitude (skips
|
412
|
+
<li>latitude and longitude (skips conversion if weather service accepts this
|
388
413
|
directly)
|
389
414
|
|
390
415
|
</li>
|
391
|
-
<li>
|
392
|
-
|
416
|
+
<li>weather.com weather id (even if the service you are using doesn’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>
|
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 ‘drivers’, 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 © 2009 Mark G. See LICENSE for details.
|
425
|
-
</p>
|
453
|
+
</p>
|