README.rdoc in barometer-0.3.2 vs README.rdoc in barometer-0.5.0
- old
+ new
@@ -6,76 +6,76 @@
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.
+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't
+support the query directly.
+
+For example, Yahoo! only accepts US Zip Code or Weather.com ID. With Barometer
+you can query Yahoo! with a simple location (ie: Paris) and it will return the
+weather.
+
== version
-Version 0.3.2 is the current release of this gem.
+Version 0.5.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).
+It is fully functional (for four weather service APIs).
== status
Currently this project is in development and will only work for a few weather
-services (wunderground, google, yahoo).
+services (wunderground, google, yahoo, weather.com).
Features to be added next:
-- even more weather service drivers (noaa, weather.com, weatherbug)
+- even more weather service drivers (noaa, weatherbug)
+- icon support
= dependencies
-=== Google API key
+== Google API key
In most cases you will need to have a free google geocode api key.
Get one here: http://code.google.com/apis/maps/signup.html
-Then put it in the file '~/.barometer' by adding the line:
-geocode_google: YOUR_KEY_HERE
+Then put it in the file '~/.barometer' by adding the lines:
+ google:
+ geocode: YOUR_KEY_HERE
+
You will need this for:
- using the Barometer gem (unless you use queries that are directly supported
by the weather source API, ie yahoo will take a zip code directly and doesn't
require any geocoding)
- running the Barometer binary
- running the Barometer Web Demo
-=== HTTParty
+=== other keys
+The same file can hold all your weather service API keys.
+
+eg. weather.com
+
+ weather:
+ partner: YOUR_PARTNER_KEY
+ license: YOUR_LICENSE_KEY
+
+== HTTParty
+
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.
HTTParty is also extended to include configurable Timeout support.
-=== tzinfo
+== tzinfo
Why? Barometer deals with time information for locations all over the world.
This information doesn't mean that much if it can't be converted to times
that don't correspond to the applicable timezone.
Tzinfo handles this time zone manipulation.
-=== graticule (very soft dependency)
-
-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 'barometer' query format,
-the query will be geo-coded using the Google geocoding service, if required.
-Graticule can provide this geocoding interface.
-
-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.
-
-ALTERNATE: If you supply a Google API key but don't install the Graticule gem,
-HTTParty will be used instead to provide the same geocoding. Basically
-Graticule is only used if it exists.
-
-NOTE: you can force Barometer not to use Graticule, even if you have it installed
-using the following:
-
- Barometer.skip_graticule = true
-
= usage
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).
@@ -89,17 +89,49 @@
barometer = Barometer.new("Paris")
weather = barometer.measure
puts weather.current.temperture
-== multiple weather API, with hierarchy
+== sources
+The available sources are:
+
+ Wunderground.com (:wunderground) [default]
+ Yahoo! Weather (:yahoo)
+ Google Weather (:google)
+ Weather.com (:weather_dot_com)
+
+== source configuration
+
+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.
+
+Weather services in parallel
+
+ Barometer.config = { 1 => [:yahoo, :google] }
+
+Weather services in primary/failover
+
+ Barometer.config = { 1 => [:yahoo], 2 => :wunderground }
+
+Weather services, one with some configuration. In this case we are setting
+a weight value, this weight is respected when calculating averages.
+
+ Barometer.config = { 1 => [{:wunderground => {:weight => 2}}, :google] }
+
+Weather services, one with keys.
+
+ Barometer.config = { 1 => [:yahoo, {:weather_dot_com => {:keys => {:partner => PARTNER_KEY, :license => LICENSE_KEY } }}] }
+
+=== multiple weather API, with hierarchy
+
require 'barometer'
Barometer.google_geocode_key = "THE_GOOGLE_API_KEY"
# use yahoo and google, if they both fail, use wunderground
- Barometer.selection = { 1 => [:yahoo, :google], 2 => :wunderground }
+ Barometer.config = { 1 => [:yahoo, :google], 2 => :wunderground }
barometer = Barometer.new("Paris")
weather = barometer.measure
puts weather.current.temperture
@@ -137,41 +169,10 @@
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).
-=== bootstrapping
-
-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.
-
- require 'barometer'
- Barometer.google_geocode_key = "THE_GOOGLE_API_KEY"
-
- query = Barometer::Query.new("Paris")
- 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, "Paris")
-
- puts weather.current.temperture
-
-
-NOTE: The disadvantage to using the drivers directly is that you lose the
-advantage of redundancy/failover added by the Module as a whole.
-
-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't have. Using a driver directly
-WILL accept a String (as in bootstrap example #2).
-
== searching
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.
@@ -223,18 +224,24 @@
require 'barometer'
Barometer.google_geocode_key = "THE_GOOGLE_API_KEY"
# use yahoo and wunderground
- Barometer.selection = { 1 => [:yahoo, :wunderground] }
+ Barometer.config = { 1 => [:yahoo, :wunderground] }
barometer = Barometer.new("90210")
weather = barometer.measure
puts weather.temperture
This will calculate the average temperature as given by :yahoo and :wunderground
+
+=== weights
+
+You can weight the values from a weather service so that the values from that
+web service have more influence then other values. The weights are set in the
+config ... see the config section
== simple answers
After you have measured the data, Barometer provides several "simple answer"
methods to help you get answers to some basic questions. All examples assume
@@ -287,17 +294,18 @@
= design
- create a Barometer instance
- supply a query, there are very little restrictions on the format:
- city, country, specific address (basically anything Google will geocode)
- - US zip code (skips geocoding if weather service accepts this directly)
- - postal code (skips geocoding if weather service accepts this directly)
- - latitude and longitude (skips geocoding if weather service accepts this
+ - US zip code (skips conversion if weather service accepts this directly)
+ - postal code (skips conversion if weather service accepts this directly)
+ - latitude and longitude (skips conversion if weather service accepts this
directly)
- - TODO: international airport code (skips geocoding if weather service
+ - weather.com weather id (even if the service you are using doesn't use it)
+ - international airport code (skips conversion if weather service
accepts this directly)
-- if geocoding required, geocode the query
-- determine which weather services will be queried (one or multiple)
+- determine which weather services will be queried (one or multiple)
+- if query conversion required for specific weather service, convert the query
- query the weather services
- save the data
- repeat weather service queries as needed
= extending