barometer 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,90 @@
1
+ body
2
+ { color: #000;
3
+ background: #fff;
4
+ font-size: 85%;
5
+ font-family: Helvetica, sans-serif;
6
+ line-height: 130%;
7
+ margin: 0.5cm; }
8
+
9
+ a
10
+ { color: #000;
11
+ text-decoration: underline; }
12
+
13
+ a img
14
+ { border: none; }
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: #172533;
28
+ font-family: Georgia, "Times New Roman", 'bitstream vera serif', serif;
29
+ font-size: 500%;
30
+ font-weight: normal;
31
+ letter-spacing: -0.1em;
32
+ line-height: 1;
33
+ margin: 0;
34
+ padding: 20px 0 16px 0;
35
+ }
36
+ #head h1 a, #head h1 a:link, #head h1 a:visited, #head h1 a:hover {
37
+ color: #172533;
38
+ text-decoration: none;
39
+ }
40
+ #head ul {
41
+ font-size:1.1em;
42
+ font-family: 'Lucida Grande', 'lucida sans unicade', Verdana, sans-serif;
43
+ font-weight: normal;
44
+ text-transform: uppercase;
45
+ text-align: center;
46
+ margin: 0;
47
+ padding: 0 40px 10px 40px;
48
+ }
49
+ #head ul li {
50
+ display: inline;
51
+ list-style-type: none;
52
+ padding: 0 1.5em 0 0;
53
+ }
54
+ #head ul a, #head ul a:link, #head ul a:visited {
55
+ color: #1d2e40;
56
+ text-decoration: none;
57
+ }
58
+ #head ul a:hover {
59
+ color: #0e1c29;
60
+ text-decoration:underline
61
+ }
62
+
63
+
64
+
65
+ h2 {
66
+ font-size: 1.5em;
67
+ letter-spacing: -0.05em;
68
+ padding: 1.15em 0 0 0;
69
+ margin: 1.25em 0 0.25em 0;
70
+ border-top: 1mm solid #999;
71
+ }
72
+
73
+ h3 {
74
+ font-size: 1.1em;
75
+ font-weight:bold;
76
+ margin: 1.8em 0 0.25em 0;
77
+ letter-spacing: -0.05em;
78
+ }
79
+
80
+ h3 a {
81
+ text-decoration:underline;
82
+ }
83
+
84
+
85
+
86
+ pre {
87
+ border: 1pt solid #ccc;
88
+ padding: 0.5em;
89
+ white-space: pre-wrap; white-space: -moz-pre-wrap !important;
90
+ }
@@ -0,0 +1,60 @@
1
+ .highlight { background: #ffffff; }
2
+ .highlight .c { color: #999988; font-style: italic } /* Comment */
3
+ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4
+ .highlight .k { font-weight: bold; } /* Keyword */
5
+ .highlight .o { font-weight: bold } /* Operator */
6
+ .highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7
+ .highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8
+ .highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
9
+ .highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
10
+ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11
+ .highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
12
+ .highlight .ge { font-style: italic } /* Generic.Emph */
13
+ .highlight .gr { color: #aa0000 } /* Generic.Error */
14
+ .highlight .gh { color: #999999 } /* Generic.Heading */
15
+ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16
+ .highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
17
+ .highlight .go { color: #888888 } /* Generic.Output */
18
+ .highlight .gp { color: #555555 } /* Generic.Prompt */
19
+ .highlight .gs { font-weight: bold } /* Generic.Strong */
20
+ .highlight .gu { color: #aaaaaa } /* Generic.Subheading */
21
+ .highlight .gt { color: #aa0000 } /* Generic.Traceback */
22
+ .highlight .kc { font-weight: bold } /* Keyword.Constant */
23
+ .highlight .kd { font-weight: bold } /* Keyword.Declaration */
24
+ .highlight .kp { font-weight: bold } /* Keyword.Pseudo */
25
+ .highlight .kr { font-weight: bold } /* Keyword.Reserved */
26
+ .highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
27
+ .highlight .m { color: #009999 } /* Literal.Number */
28
+ .highlight .s { color: #444 } /* Literal.String */
29
+ .highlight .na { color: #008080 } /* Name.Attribute */
30
+ .highlight .nb { color: #0086B3 } /* Name.Builtin */
31
+ .highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
32
+ .highlight .no { color: #008080 } /* Name.Constant */
33
+ .highlight .ni { color: #800080 } /* Name.Entity */
34
+ .highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
35
+ .highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
36
+ .highlight .nn { color: #555555 } /* Name.Namespace */
37
+ .highlight .nt { color: #000080 } /* Name.Tag */
38
+ .highlight .nv { color: #008080 } /* Name.Variable */
39
+ .highlight .ow { font-weight: bold } /* Operator.Word */
40
+ .highlight .w { color: #bbbbbb } /* Text.Whitespace */
41
+ .highlight .mf { color: #009999 } /* Literal.Number.Float */
42
+ .highlight .mh { color: #009999 } /* Literal.Number.Hex */
43
+ .highlight .mi { color: #009999 } /* Literal.Number.Integer */
44
+ .highlight .mo { color: #009999 } /* Literal.Number.Oct */
45
+ .highlight .sb { color: #444 } /* Literal.String.Backtick */
46
+ .highlight .sc { color: #444 } /* Literal.String.Char */
47
+ .highlight .sd { color: #444 } /* Literal.String.Doc */
48
+ .highlight .s2 { color: #444 } /* Literal.String.Double */
49
+ .highlight .se { color: #444 } /* Literal.String.Escape */
50
+ .highlight .sh { color: #444 } /* Literal.String.Heredoc */
51
+ .highlight .si { color: #444 } /* Literal.String.Interpol */
52
+ .highlight .sx { color: #444 } /* Literal.String.Other */
53
+ .highlight .sr { color: #009926 } /* Literal.String.Regex */
54
+ .highlight .s1 { color: #444 } /* Literal.String.Single */
55
+ .highlight .ss { color: #990073 } /* Literal.String.Symbol */
56
+ .highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
57
+ .highlight .vc { color: #008080 } /* Name.Variable.Class */
58
+ .highlight .vg { color: #008080 } /* Name.Variable.Global */
59
+ .highlight .vi { color: #008080 } /* Name.Variable.Instance */
60
+ .highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
Binary file
@@ -0,0 +1,32 @@
1
+ <h1 id='contribute'>Contribute</h1>
2
+
3
+ <p>Want to advance Barometer? Help out by contributing!</p>
4
+
5
+ <h2 id='find_a_bug'>Find a bug?</h2>
6
+
7
+ <p>Add it to GitHub by <a href='http://github.com/attack/barometer/issues'>creating a new issue</a>. Be sure to include all relevant information, like the versions of Barometer and Ruby you&#8217;re using. A <a href='http://gist.github.com/'>gist</a> of the code that caused the issue as well as any error messages are also very helpful.</p>
8
+
9
+ <h2 id='have_a_patch'>Have a patch?</h2>
10
+
11
+ <p>Bugs and feature requests that include patches are much more likely to get attention. Here are some guidelines that will help ensure your patch can be applied as quickly as possible:</p>
12
+
13
+ <ol>
14
+ <li>
15
+ <p><strong>Use <a href='http://git-scm.com'>Git</a> and <a href='http://github.com'>GitHub</a>:</strong> The easiest way to get setup is to fork the <a href='http://github.com/attack/barometer/'>attack/barometer repo</a>.
16
+ </p>
17
+
18
+ </li>
19
+
20
+ <li>
21
+ <p><strong>Write spec tests:</strong> If you add or modify functionality, it must include spec tests.</p>
22
+ </li>
23
+
24
+ <li>
25
+ <p><strong>Mind the <code>README</code>:</strong> If the patch adds or modifies a major feature, modify the <code>README.rdoc</code> file to reflect that.</p>
26
+
27
+ </li>
28
+
29
+ <li>
30
+ <p><strong>Push it:</strong> Once you&#8217;re ready, push your changes to a topic branch and add a note to the ticket with the URL to your branch. Or, say something like, &#8220;you can find the patch on johndoe/foobranch&#8221;.</p>
31
+ </li>
32
+ </ol>
@@ -0,0 +1,14 @@
1
+ <h4>for: <%= forecast.date %></h4>
2
+ <p>
3
+ <ul>
4
+ <li>Date: <%= forecast.date %></li>
5
+ <li>Icon: <%= forecast.icon %></li>
6
+ <li>Condition: <%= forecast.condition %></li>
7
+ <li>High: <%= forecast.high %></li>
8
+ <li>Low: <%= forecast.low %></li>
9
+ <li>POP: <%= forecast.pop %></li>
10
+ <% if forecast.sun %>
11
+ <li>Sun: rise - <%= forecast.sun.rise %>, set - <%= forecast.sun.set %></li>
12
+ <% end %>
13
+ </ul>
14
+ </p>
@@ -0,0 +1,66 @@
1
+ <h2 id='demo'>Measure the weather for:</h2>
2
+
3
+ <br/>
4
+ <form action="/" class="" id="" method="post">
5
+ <div class="text-input">
6
+ <input id="query_q" name="query[q]" size="25" type="text" />
7
+ </div>
8
+ <div class="submit-input">
9
+ <input src="/images/go.png" type="image" value="go &rarr;" />
10
+ </div>
11
+ <br/>
12
+ <div class="options-input">
13
+ Metric? :
14
+ <input id="query_metric" name="query[metric]" type="checkbox" value="1" checked="checked" />
15
+ <br/>
16
+ Source :
17
+ <input type="radio" name="query[source]" value="wunderground" checked="checked" /> Wunderground
18
+ <input type="radio" name="query[source]" value="yahoo" /> Yahoo
19
+ <input type="radio" name="query[source]" value="google" /> Google
20
+ <br/>
21
+ Force Geocode? :
22
+ <input id="query_geocode" name="query[geocode]" type="checkbox" value="1" checked="checked" />
23
+ </div>
24
+ </form>
25
+
26
+ <p>&nbsp;</p>
27
+ <br/>
28
+
29
+ <% if params[:query] && !params[:query][:q].empty? %>
30
+ <h2>query: "<%= params[:query][:q] %>"</h2>
31
+ <% end %>
32
+
33
+ <% if @weather %>
34
+
35
+ <h2>Summary</h2>
36
+ <p>
37
+ <ul>
38
+ <li>Day?: <%= @weather.day? %></li>
39
+ <li>Sunny?: <%= @weather.sunny? %></li>
40
+ <li>Windy?: <%= @weather.windy? %></li>
41
+ <li>Wet?: <%= @weather.wet? %></li>
42
+ </ul>
43
+ </p>
44
+
45
+ <% if @barometer.query %>
46
+ <h3>Query</h3>
47
+ <p>
48
+ <ul>
49
+ <li>Format: <%= @barometer.query.format %></li>
50
+ <% if @barometer.query.geo %>
51
+ <li>Locality: <%= @barometer.query.geo.locality %></li>
52
+ <li>Region: <%= @barometer.query.geo.region %></li>
53
+ <li>Country: <%= @barometer.query.geo.country %></li>
54
+ <li>Country Code: <%= @barometer.query.geo.country_code %></li>
55
+ <li>Latitude: <%= @barometer.query.geo.latitude %></li>
56
+ <li>Longitude: <%= @barometer.query.geo.longitude %></li>
57
+ <% end %>
58
+ </ul>
59
+ </p>
60
+ <% end %>
61
+
62
+ <% @weather.measurements.each do |measurement| %>
63
+ <%= erb(:measurement, :locals => { :measurement => measurement }, :layout => false) %>
64
+ <% end %>
65
+
66
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <title>Barometer</title>
6
+ <link rel='stylesheet' href='/css/master.css' type='text/css' media="screen, projection">
7
+ <link rel='stylesheet' href='/css/syntax.css' type='text/css' media="screen, projection">
8
+ <link rel='stylesheet' href='/css/print.css' type='text/css' media="print">
9
+ <link rel='shortcut icon' href='/images/favicon.ico'>
10
+ <link rel='alternate' href='http://attack.github.com/feed.xml' type='application/atom+xml' title='Sinatra Blog'>
11
+
12
+ </head>
13
+ <body id=''>
14
+
15
+ <div id='wrap'>
16
+
17
+ <div id='head'>
18
+ <h1><a href='/'>Barometer</a></h1>
19
+ <ul>
20
+ <li><a href='/'>Demo</a></li>
21
+ <li><a href='/readme.html'>README</a></li>
22
+ <li><a href='/contributing.html'>Contribute</a></li>
23
+ <li><a class="out" href='http://github.com/attack/barometer'>Code</a></li>
24
+ </ul>
25
+ </div>
26
+
27
+ <div id='content'>
28
+ <%= yield %>
29
+ </div>
30
+
31
+ <div id='foot'>
32
+ </div>
33
+
34
+ </div>
35
+
36
+ <a href="http://github.com/attack/barometer"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" /></a>
37
+ </body>
38
+ </html>
@@ -0,0 +1,88 @@
1
+ <h2><%= measurement.source.to_s.capitalize %></h2>
2
+ <p>
3
+ <ul>
4
+ <li>Source: <%= measurement.source %></li>
5
+ <li>Time: <%= measurement.time %></li>
6
+ <li>Metric: <%= measurement.metric? %></li>
7
+ <li>Success: <%= measurement.success? %></li>
8
+ </ul>
9
+ </p>
10
+
11
+ <% if measurement.location %>
12
+ <h3>Location</h3>
13
+ <p>
14
+ <ul>
15
+ <li>id: <%= measurement.location.id %></li>
16
+ <li>Name: <%= measurement.location.name %></li>
17
+ <li>City: <%= measurement.location.city %> %</li>
18
+ <li>State Name: <%= measurement.location.state_name %></li>
19
+ <li>State Code: <%= measurement.location.state_code %></li>
20
+ <li>Country: <%= measurement.location.country %></li>
21
+ <li>Country Code: <%= measurement.location.country_code %></li>
22
+ <li>Zip Code: <%= measurement.location.zip_code %></li>
23
+ <li>Latitude: <%= measurement.location.latitude %></li>
24
+ <li>Longitude: <%= measurement.location.longitude %></li>
25
+ </ul>
26
+ </p>
27
+ <% end %>
28
+
29
+ <% if measurement.station %>
30
+ <h3>Station</h3>
31
+ <p>
32
+ <ul>
33
+ <li>id: <%= measurement.station.id %></li>
34
+ <li>Name: <%= measurement.station.name %></li>
35
+ <li>City: <%= measurement.station.city %> %</li>
36
+ <li>State Name: <%= measurement.station.state_name %></li>
37
+ <li>State Code: <%= measurement.station.state_code %></li>
38
+ <li>Country: <%= measurement.station.country %></li>
39
+ <li>Country Code: <%= measurement.station.country_code %></li>
40
+ <li>Zip Code: <%= measurement.station.zip_code %></li>
41
+ <li>Latitude: <%= measurement.station.latitude %></li>
42
+ <li>Longitude: <%= measurement.station.longitude %></li>
43
+ </ul>
44
+ </p>
45
+ <% end %>
46
+
47
+ <% if measurement.timezone %>
48
+ <h3>Timezone</h3>
49
+ <p>
50
+ <ul>
51
+ <li>Long: <%= measurement.timezone.timezone %></li>
52
+ <li>Code: <%= measurement.timezone.code %></li>
53
+ <li>DST?: <%= measurement.timezone.dst? %></li>
54
+ </ul>
55
+ </p>
56
+ <% end %>
57
+
58
+ <% if measurement.current %>
59
+ <h3>Current</h3>
60
+ <p>
61
+ <ul>
62
+ <li>Time: <%= measurement.current.time %></li>
63
+ <li>Local Time: <%= measurement.current.local_time %></li>
64
+ <li>Humidity: <%= measurement.current.humidity %> %</li>
65
+ <li>Icon: <%= measurement.current.icon %></li>
66
+ <li>Condition: <%= measurement.current.condition %></li>
67
+ <li>Temperature: <%= measurement.current.temperature %></li>
68
+ <li>Dew Point: <%= measurement.current.dew_point %></li>
69
+ <li>Heat Index: <%= measurement.current.heat_index %></li>
70
+ <li>Wind Chill: <%= measurement.current.wind_chill %></li>
71
+ <li>Wind: <%= measurement.current.wind %> @ <%= measurement.current.wind.direction %> [<%= measurement.current.wind.degrees %> degrees]</li>
72
+ <li>Pressure: <%= measurement.current.pressure %></li>
73
+ <li>Visibility: <%= measurement.current.visibility %></li>
74
+ <% if measurement.current.sun %>
75
+ <li>Sun: rise - <%= measurement.current.sun.rise %>, set - <%= measurement.current.sun.set %></li>
76
+ <% end %>
77
+ </ul>
78
+ </p>
79
+ <% end %>
80
+
81
+ <% if measurement.forecast %>
82
+ <h3>Forecast</h3>
83
+
84
+ <% measurement.forecast.each do |forecast| %>
85
+ <%= erb(:forecast, :locals => { :forecast => forecast }, :layout => false) %>
86
+ <% end %>
87
+
88
+ <% end %>
@@ -0,0 +1,338 @@
1
+ <h1>barometer</h1>
2
+ <p>
3
+ A multi API consuming weather forecasting superstar.
4
+
5
+ </p>
6
+ <p>
7
+ Barometer provides a common public API to one or more weather services
8
+ (APIs) of your choice. Weather services can co-exist to retrieve extensive
9
+ information, or they can be used in a hierarchical configuration where
10
+ lower preferred weather services are only used if previous services are
11
+ unavailable.
12
+ </p>
13
+ <h2>status</h2>
14
+ <p>
15
+ Currently this project is in development and will only work for a few
16
+ weather services (wunderground, google, yahoo).
17
+ </p>
18
+ <p>
19
+ Features to be added before first release:
20
+ </p>
21
+ <ul>
22
+ <li>gem setup/config, apply to rubyforge
23
+
24
+ </li>
25
+ </ul>
26
+ <p>
27
+
28
+ Features to be added in future releases:
29
+ </p>
30
+ <ul>
31
+ <li>even more weather service drivers (noaa, weather.com, weatherbug)
32
+
33
+ </li>
34
+ <li>ability to query multiple services and combine/average the results
35
+
36
+ </li>
37
+ <li>support iaco as a query format
38
+
39
+ </li>
40
+ </ul>
41
+ <h1>dependencies</h1>
42
+ <h3>HTTParty</h3>
43
+ <p>
44
+ Why? HTTParty was created and designed specifically for consuming web
45
+ services. I choose to use this over using the Net::HTTP library directly to
46
+ allow for faster development of this project.
47
+ </p>
48
+
49
+ <p>
50
+ HTTParty is also extended to include configurable Timoout support.
51
+ </p>
52
+ <h3>tzinfo</h3>
53
+ <p>
54
+ Why? Barometer deals with time information for locations all over the
55
+ world. This information doesn&#8217;t mean that much if it can&#8217;t be
56
+ converted to times that don&#8217;t correspond to the applicable timezone.
57
+ Tzinfo handles this time zone manipulation.
58
+ </p>
59
+ <h3>graticule (very soft dependency)</h3>
60
+ <p>
61
+ Why? Barometer returns the weather for a given location. Most weather
62
+ service APIs are somewhat restricted on the query format they receive. To
63
+ bridge this gap and allow for maximum flexibility on the
64
+ &#8216;barometer&#8217; query format, the query will be geo-coded using the
65
+ Google geocoding service, if required. Graticule can provide this geocoding
66
+ interface.
67
+
68
+ </p>
69
+ <p>
70
+ Using Graticule requires a free Google API key for geocoding. It is
71
+ possible to use barometer without geocoding, though your query format will
72
+ be limited to that of the weather service API.
73
+ </p>
74
+ <p>
75
+ ALTERNATE: If you supply a Google API key but don&#8217;t install the
76
+ Graticule gem, HTTParty will be used instead to provide the same geocoding.
77
+ Basically Graticule is only used if it exists.
78
+ </p>
79
+ <p>
80
+ NOTE: you can force Barometer not to use Graticule, even if you have it
81
+ installed using the following:
82
+ </p>
83
+ <pre>
84
+ Barometer.skip_graticule = true
85
+ </pre>
86
+ <h1>usage</h1>
87
+
88
+ <p>
89
+ You can use barometer right out of the box, as it is configured to use one
90
+ register-less (no API key required) international weather service
91
+ (wunderground.com).
92
+ </p>
93
+ <p>
94
+ For better results, signup for a google-map key and enhance your barometer
95
+ with geo-coding.
96
+ </p>
97
+ <pre>
98
+ require 'barometer'
99
+
100
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
101
+ barometer = Barometer.new(&quot;Paris&quot;)
102
+ weather = barometer.measure
103
+
104
+ puts weather.current.temperture
105
+ </pre>
106
+ <h2>multiple weather API, with hierarchy</h2>
107
+
108
+ <pre>
109
+ require 'barometer'
110
+
111
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
112
+ # use yahoo and google, if they both fail, use wunderground
113
+ Barometer.selection = { 1 =&gt; [:yahoo, :google], 2 =&gt; :wunderground }
114
+
115
+ barometer = Barometer.new(&quot;Paris&quot;)
116
+ weather = barometer.measure
117
+
118
+ puts weather.current.temperture
119
+ </pre>
120
+ <h2>command line</h2>
121
+ <p>
122
+
123
+ You can use barometer from the command line.
124
+ </p>
125
+ <pre>
126
+ # barometer berlin
127
+ </pre>
128
+ <p>
129
+ This will output the weather information for the given query.
130
+ </p>
131
+ <h3>fail</h3>
132
+ <p>
133
+ What would cause a weather service to fail? The most obvious is that the
134
+ particular weather service in currently unavailable or not reachable. Other
135
+ possible reasons would include not having the API (or a valid API key for
136
+ the particular weather service, if required), not providing a valid query,
137
+ or providing a query for a location not supported by the weather service.
138
+ </p>
139
+ <p>
140
+ For example, if you look at the example above, the query of
141
+ &quot;Paris&quot; refers to a city in France. Yahoo weather services only
142
+ supports weather results for USA (at least at the time of writing).
143
+ Therefore, Barometer would not use Yahoo, just Google and failover to use
144
+ Wunderground (if needed).
145
+
146
+ </p>
147
+ <h3>bootstrapping</h3>
148
+ <p>
149
+ You can use weather service drivers directly. Below is an example to use
150
+ Wunderground, but since the driver interface is abstracted it will be the
151
+ same for all supported services.
152
+ </p>
153
+ <pre>
154
+ require 'barometer'
155
+ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot;
156
+
157
+ query = Barometer::Query.new(&quot;Paris&quot;)
158
+ weather = Barometer::Service.source(:wunderground).measure(query)
159
+
160
+ puts weather.current.temperture
161
+
162
+ # OR, even more raw
163
+
164
+ measurement = Barometer::Measurement.new
165
+ weather = Barometer::Wunderground.measure_all(measurement, &quot;Paris&quot;)
166
+
167
+ puts weather.current.temperture
168
+
169
+ </pre>
170
+ <p>
171
+ NOTE: The disadvantage to using the drivers directly is that you lose the
172
+ advantage of redundancy/failover added by the Module as a whole.
173
+ </p>
174
+ <p>
175
+ NOTE: You still must create the Barometer::Query object with your query
176
+ string instead of directly feeding the query string to the service (as in
177
+ bootstrap example #1). The Barometer::Query object has behavior required by
178
+ the service that a regular String doesn&#8217;t have. Using a driver
179
+ directly WILL accept a String (as in bootstrap example #2).
180
+ </p>
181
+ <h2>searching</h2>
182
+ <p>
183
+ After you have measured the data, Barometer provides several methods to
184
+ help you get the data you are after. All examples assume you already have
185
+ measured the data as shown in the above examples.
186
+ </p>
187
+ <h3>by preference (default service)</h3>
188
+ <pre>
189
+ weather.default # returns measurement for default source
190
+ weather.current # returns current_measurement for default
191
+ weather.now # returns current_measurement for default
192
+ weather.forecast # returns all forecast_measurements for default
193
+ weather.today # returns forecast_measurement for default today
194
+ weather.tomorrow # returns forecast_measurement for default tomorrow
195
+
196
+ puts weather.now.temperature.c
197
+ puts weather.tomorrow.high.c
198
+
199
+ </pre>
200
+ <h3>by source</h3>
201
+ <pre>
202
+ weather.source(:wunderground) # returns measurement for specified source
203
+ weather.sources # lists all successful sources
204
+
205
+ puts weather.source(:wunderground).current.temperature.c
206
+ </pre>
207
+ <h3>by date</h3>
208
+ <pre>
209
+ # note, the date is the date of the locations weather, not the date of the
210
+ # user measuring the weather
211
+ date = Date.parse(&quot;01-01-2009&quot;)
212
+ weather.for(date) # returns forecast_measurement for default on date
213
+ weather.source(:wunderground).for(date) # same as above but specific source
214
+
215
+ puts weather.source(:wunderground).for(date).high.c
216
+ </pre>
217
+ <h3>by time</h3>
218
+
219
+ <pre>
220
+ # note, the time is the time of the locations weather, not the time of the
221
+ # user measuring the weather
222
+ time = Time.parse(&quot;13:00 01-01-2009&quot;)
223
+ weather.for(time) # returns forecast_measurement for default at time
224
+ weather.source(:wunderground).for(time) # same as above but specific source
225
+
226
+ puts weather.source(:wunderground).for(time).low.f
227
+ </pre>
228
+ <h2>simple answers</h2>
229
+ <p>
230
+ After you have measured the data, Barometer provides several &quot;simple
231
+ answer&quot; methods to help you get answers to some basic questions. All
232
+ examples assume you already have measured the data as shown in the above
233
+ examples.
234
+ </p>
235
+ <p>
236
+ All of these questions are ultimately specific to the weather source(s) you
237
+ are configured to use. All sources that have successfully measured data
238
+ will be asked, but if there is no data that can answer the question then
239
+ there will be no answer.
240
+ </p>
241
+
242
+ <h3>is it windy?</h3>
243
+ <pre>
244
+ # 1st parameter is the threshold wind speed for being windy
245
+ # 2nd parameter is the utc_time for which you want to know the answer,
246
+ # this defaults to the current time
247
+ # NOTE: in my example the values are metric, so the threshold is 10 kph
248
+
249
+ weather.windy?(10)
250
+ </pre>
251
+ <h3>is it wet?</h3>
252
+ <pre>
253
+ # 1st parameter is the threshold pop (%) for being wet
254
+ # 2nd parameter is the utc_time for which you want to know the answer,
255
+ # this defaults to the current time
256
+ # NOTE: in my example the threshold is 50 %
257
+
258
+ weather.wet?(50)
259
+ </pre>
260
+ <h3>is it sunny?</h3>
261
+ <pre>
262
+ # 1st parameter is the utc_time for which you want to know the answer,
263
+ # this defaults to the current time
264
+
265
+ weather.sunny?
266
+
267
+ </pre>
268
+ <h3>is it day?</h3>
269
+ <pre>
270
+ # 1st parameter is the utc_time for which you want to know the answer,
271
+ # this defaults to the current time
272
+
273
+ weather.day?
274
+ </pre>
275
+ <h3>is it night?</h3>
276
+ <pre>
277
+ # 1st parameter is the utc_time for which you want to know the answer,
278
+ # this defaults to the current time
279
+
280
+ weather.night?
281
+ </pre>
282
+ <h1>design</h1>
283
+ <ul>
284
+ <li>create a Barometer instance
285
+
286
+
287
+ </li>
288
+ <li>supply a query, there are very little restrictions on the format:
289
+
290
+ <ul>
291
+ <li>city, country, specific address (basically anything Google will geocode)
292
+
293
+ </li>
294
+ <li>US zip code (skips geocoding if weather service accepts this directly)
295
+
296
+ </li>
297
+ <li>postal code (skips geocoding if weather service accepts this directly)
298
+
299
+ </li>
300
+ <li>latitude and longitude (skips geocoding if weather service accepts this
301
+ directly)
302
+
303
+ </li>
304
+ <li>TODO: international airport code (skips geocoding if weather service
305
+ accepts this directly)
306
+
307
+ </li>
308
+ </ul>
309
+ </li>
310
+ <li>if geocoding required, geocode the query
311
+
312
+ </li>
313
+
314
+ <li>determine which weather services will be queried (one or multiple)
315
+
316
+ </li>
317
+ <li>query the weather services
318
+
319
+ </li>
320
+ <li>save the data
321
+
322
+ </li>
323
+ <li>repeat weather service queries as needed
324
+
325
+ </li>
326
+ </ul>
327
+ <h1>extending</h1>
328
+ <p>
329
+ Barometer attempts to be a common API to any weather service API. I have
330
+ included several weather service &#8216;drivers&#8217;, but I know there
331
+ are many more available. Please use the provided ones as examples to create
332
+ more.
333
+ </p>
334
+ <h2>copyright</h2>
335
+
336
+ <p>
337
+ Copyright &#169; 2009 Mark G. See LICENSE for details.
338
+ </p>