lib/demometer/views/readme.erb in attack-barometer-0.5.0 vs lib/demometer/views/readme.erb in attack-barometer-0.6.0

- old
+ new

@@ -7,39 +7,49 @@ (APIs) of your choice. Weather services can co-exist to retrieve extensive information, or they can be used in a hierarchical configuration where lower preferred weather services are only used if previous services are unavailable. </p> +<p> +Barometer handles all conversions of the supplied query, so that the same +query can be used for all (or most) services, even if they don&#8217;t +support the query directly. See the &quot;Query&quot; section for more +information on this. +</p> <h2>version</h2> <p> -Version 0.3.3 is the current release of this gem. The gem is available from +Version 0.6.0 is the current release of this gem. The gem is available from github (attack-barometer) or rubyforge (barometer). It is fully functional -(for three weather service APIs). +(for five weather service APIs). </p> <h2>status</h2> - <p> Currently this project is in development and will only work for a few -weather services (wunderground, google, yahoo). +weather services (wunderground, google, yahoo, weather.com, weather_bug). </p> <p> Features to be added next: </p> <ul> -<li>even more weather service drivers (noaa, weather.com, weatherbug) +<li>even more weather service drivers (noaa) </li> +<li>icon support + +</li> </ul> <h1>dependencies</h1> -<h3>Google API key</h3> +<h2>Google API key</h2> <p> In most cases you will need to have a free google geocode api key. Get one here: <a href="http://code.google.com/apis/maps/signup.html">code.google.com/apis/maps/signup.html</a> - -Then put it in the file &#8217;~/.barometer&#8217; by adding the line: -geocode_google: YOUR_KEY_HERE +Then put it in the file &#8217;~/.barometer&#8217; by adding the lines: </p> +<pre> + google: + geocode: YOUR_KEY_HERE +</pre> <p> You will need this for: </p> <ul> <li>using the Barometer gem (unless you use queries that are directly supported @@ -52,55 +62,99 @@ </li> <li>running the Barometer Web Demo </li> </ul> - -<h3>HTTParty</h3> +<h3>other keys</h3> <p> +The same file can hold all your weather service API keys. +</p> +<p> +eg. weather.com +</p> +<pre> + weather: + partner: YOUR_PARTNER_KEY + license: YOUR_LICENSE_KEY +</pre> +<p> +eg. weatherbug.com +</p> +<pre> + weather_bug: + code: YOUR_API_CODE +</pre> +<h2>HTTParty</h2> +<p> Why? HTTParty was created and designed specifically for consuming web services. I choose to use this over using the Net::HTTP library directly to allow for faster development of this project. </p> <p> HTTParty is also extended to include configurable Timeout support. </p> -<h3>tzinfo</h3> +<h2>tzinfo</h2> <p> Why? Barometer deals with time information for locations all over the world. This information doesn&#8217;t mean that much if it can&#8217;t be converted to times that don&#8217;t correspond to the applicable timezone. Tzinfo handles this time zone manipulation. </p> -<h3>graticule (very soft dependency)</h3> - +<h1>queries</h1> <p> -Why? Barometer returns the weather for a given location. Most weather -service APIs are somewhat restricted on the query format they receive. To -bridge this gap and allow for maximum flexibility on the -&#8216;barometer&#8217; query format, the query will be geo-coded using the -Google geocoding service, if required. Graticule can provide this geocoding -interface. +The query handling is one of the most beneficial and powerful features of +Barometer. Every weather service accepts a different set of possible +queries, so it usually the case that the same query can only be used for a +couple weather services. </p> <p> -Using Graticule requires a free Google API key for geocoding. It is -possible to use barometer without geocoding, though your query format will -be limited to that of the weather service API. +Barometer will allow the use of all query formats for all services +(mostly). It does this by first determining the original query format, then +converting the query to a compatible format for each specific weather +service. </p> <p> -ALTERNATE: If you supply a Google API key but don&#8217;t install the -Graticule gem, HTTParty will be used instead to provide the same geocoding. -Basically Graticule is only used if it exists. +For example, Yahoo! only accepts US Zip Code or Weather.com ID. With +Barometer you can query Yahoo! with a simple location (ie: Paris) or even +an Airport code (ICAO) and it will return the weather as expected. </p> +<h2>acceptable formats</h2> +<ul> +<li>zipcode + +</li> +<li>icao (international airport code) + +</li> +<li>coordinates (latitude and longitude) + +</li> +<li>postal code + +</li> +<li>weather.com ID + +</li> +<li>location name (ie address, city, state, landmark, etc.) + +</li> +<li>if the query is of the formats zipcode or postal code it may not support +conversion to other formats. + +</li> +</ul> +<h2>conversion caching</h2> <p> -NOTE: you can force Barometer not to use Graticule, even if you have it -installed using the following: +Barometer has internal conversion caching. No conversion will be repeated +during a measurement, thus limiting the number of web queries needed. </p> -<pre> - - Barometer.skip_graticule = true -</pre> +<p> +Example: If you configure Barometer to use both Yahoo and Weather.com, then +use a query like &quot;denver&quot;, this will require a conversion from +&quot;denver&quot; to its weather.com weather_id. This conversion is needed +for both web services but will only happen once and be cached. +</p> <h1>usage</h1> <p> You can use barometer right out of the box, as it is configured to use one register-less (no API key required) international weather service (wunderground.com). @@ -115,12 +169,22 @@ Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot; barometer = Barometer.new(&quot;Paris&quot;) weather = barometer.measure puts weather.current.temperture - </pre> +<h2>sources</h2> +<p> +The available sources are: +</p> +<pre> + Wunderground.com (:wunderground) [default] + Yahoo! Weather (:yahoo) + Google Weather (:google) + Weather.com (:weather_dot_com) + WeatherBug.com (:weather_bug) +</pre> <h2>source configuration</h2> <p> Barometer can be configured to use multiple weather service APIs (either in a primary/failover config or in parallel). Each weather service can also have its own config. @@ -131,23 +195,27 @@ <pre> Barometer.config = { 1 =&gt; [:yahoo, :google] } </pre> <p> Weather services in primary/failover - </p> <pre> Barometer.config = { 1 =&gt; [:yahoo], 2 =&gt; :wunderground } </pre> <p> Weather services, one with some configuration. In this case we are setting a weight value, this weight is respected when calculating averages. </p> <pre> Barometer.config = { 1 =&gt; [{:wunderground =&gt; {:weight =&gt; 2}}, :google] } - </pre> +<p> +Weather services, one with keys. +</p> +<pre> + Barometer.config = { 1 =&gt; [:yahoo, {:weather_dot_com =&gt; {:keys =&gt; {:partner =&gt; PARTNER_KEY, :license =&gt; LICENSE_KEY } }}] } +</pre> <h3>multiple weather API, with hierarchy</h3> <pre> require 'barometer' Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot; @@ -157,11 +225,10 @@ barometer = Barometer.new(&quot;Paris&quot;) weather = barometer.measure puts weather.current.temperture </pre> - <h2>command line</h2> <p> You can use barometer from the command line. </p> <pre> @@ -173,11 +240,10 @@ </p> <pre> # barometer -h </pre> <h3>web demo</h3> - <p> There is a Sinatra application that demos the functionality of Barometer, and provides Barometer information. Start this local demo with: </p> <pre> @@ -185,11 +251,10 @@ </pre> <p> NOTE: This requires the gems &quot;sinatra&quot; and &quot;vegas&quot;. </p> <h3>fail</h3> - <p> What would cause a weather service to fail? The most obvious is that the particular weather service in currently unavailable or not reachable. Other possible reasons would include not having the API (or a valid API key for the particular weather service, if required), not providing a valid query, @@ -200,45 +265,11 @@ &quot;Paris&quot; refers to a city in France. Yahoo weather services only supports weather results for USA (at least at the time of writing). Therefore, Barometer would not use Yahoo, just Google and failover to use Wunderground (if needed). </p> -<h3>bootstrapping</h3> -<p> -You can use weather service drivers directly. Below is an example to use -Wunderground, but since the driver interface is abstracted it will be the -same for all supported services. -</p> -<pre> - require 'barometer' - Barometer.google_geocode_key = &quot;THE_GOOGLE_API_KEY&quot; - - query = Barometer::Query.new(&quot;Paris&quot;) - weather = Barometer::Service.source(:wunderground).measure(query) - - puts weather.current.temperture - - # OR, even more raw - - measurement = Barometer::Measurement.new - weather = Barometer::Wunderground.measure_all(measurement, &quot;Paris&quot;) - - puts weather.current.temperture -</pre> -<p> -NOTE: The disadvantage to using the drivers directly is that you lose the -advantage of redundancy/failover added by the Module as a whole. -</p> -<p> -NOTE: You still must create the Barometer::Query object with your query -string instead of directly feeding the query string to the service (as in -bootstrap example #1). The Barometer::Query object has behavior required by -the service that a regular String doesn&#8217;t have. Using a driver -directly WILL accept a String (as in bootstrap example #2). -</p> <h2>searching</h2> - <p> After you have measured the data, Barometer provides several methods to help you get the data you are after. All examples assume you already have measured the data as shown in the above examples. </p> @@ -259,11 +290,10 @@ weather.source(:wunderground) # returns measurement for specified source weather.sources # lists all successful sources puts weather.source(:wunderground).current.temperature.c </pre> - <h3>by date</h3> <pre> # note, the date is the date of the locations weather, not the date of the # user measuring the weather date = Date.parse(&quot;01-01-2009&quot;) @@ -281,11 +311,10 @@ weather.source(:wunderground).for(time) # same as above but specific source puts weather.source(:wunderground).for(time).low.f </pre> <h2>averages</h2> - <p> If you consume more then one weather service, Barometer can provide averages for the values (currently only for the &#8216;current&#8217; values and not the forecasted values). </p> @@ -298,11 +327,10 @@ barometer = Barometer.new(&quot;90210&quot;) weather = barometer.measure puts weather.temperture - </pre> <p> This will calculate the average temperature as given by :yahoo and :wunderground </p> @@ -316,11 +344,10 @@ <p> After you have measured the data, Barometer provides several &quot;simple answer&quot; methods to help you get answers to some basic questions. All examples assume you already have measured the data as shown in the above examples. - </p> <p> All of these questions are ultimately specific to the weather source(s) you are configured to use. All sources that have successfully measured data will be asked, but if there is no data that can answer the question then @@ -343,11 +370,10 @@ # NOTE: in my example the threshold is 50 % weather.wet?(50) </pre> <h3>is it sunny?</h3> - <pre> # 1st parameter is the utc_time for which you want to know the answer, # this defaults to the current time weather.sunny? @@ -365,42 +391,45 @@ # this defaults to the current time weather.night? </pre> <h1>design</h1> - <ul> <li>create a Barometer instance </li> <li>supply a query, there are very little restrictions on the format: <ul> <li>city, country, specific address (basically anything Google will geocode) </li> -<li>US zip code (skips geocoding if weather service accepts this directly) +<li>US zip code (skips conversion if weather service accepts this directly) </li> -<li>postal code (skips geocoding if weather service accepts this directly) +<li>postal code (skips conversion if weather service accepts this directly) </li> -<li>latitude and longitude (skips geocoding if weather service accepts this +<li>latitude and longitude (skips conversion if weather service accepts this directly) </li> -<li>TODO: international airport code (skips geocoding if weather service -accepts this directly) +<li>weather.com weather id (even if the service you are using doesn&#8217;t use +it) </li> +<li>international airport code (skips conversion if weather service accepts +this directly) + +</li> </ul> </li> +<li>determine which weather services will be queried (one or multiple) -<li>if geocoding required, geocode the query - </li> -<li>determine which weather services will be queried (one or multiple) +<li>if query conversion required for specific weather service, convert the +query </li> <li>query the weather services </li> @@ -415,11 +444,10 @@ <p> Barometer attempts to be a common API to any weather service API. I have included several weather service &#8216;drivers&#8217;, but I know there are many more available. Please use the provided ones as examples to create more. - </p> <h2>copyright</h2> <p> Copyright &#169; 2009 Mark G. See LICENSE for details. -</p> +</p> \ No newline at end of file