A multi API consuming weather forecasting superstar.
Barometer provides a common public API to one or more weather services (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.
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. See the "Queries" section for more info.
- works with ruby 1.9.3, 2.x (see Travis CI status to confirm)
- supports 5 weather services, more planned
- the same query can be used with any supported weather service
- provides a powerful data object to hold the weather information
- provides a simple plugin api to allow more weather services to be added
- failover configuration
- multiple services configuration to provide average values
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).
require 'barometer'
barometer = Barometer.new('Paris')
weather = barometer.measure
puts weather.current.temperature
See detailed usage further down.
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 is the case that the same query can only be used for a couple weather services.
Barometer will allow the use of all query formats for all services. It does this by first determining the original query format, then converting the query to a compatible format for each specific weather service.
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.
- zipcode
- icao (international airport code)
- coordinates (latitude and longitude)
- postal code
- weather.com ID
- location name (ie address, city, state, landmark, etc.)
- woeid (where on earth id, by Yahoo!)
- IPv4 address
The current available sources are:
- Wunderground.com (:wunderground) [default]
- Yahoo! Weather (:yahoo) [requires barometer-yahoo gem]]
- WeatherBug.com (:weather_bug) [requires key + barometer-weather_bug gem]]
- NOAA (:noaa) [requires barometer-noaa gem]]
- Forecast.io (:forecast_io) [requires key + barometer-forecast_io gem]
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, :wunderground] }
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}}, :yahoo] }
Weather services, one with keys.
Barometer.config = { 1 => [:yahoo, {weather_bug: {keys: {code: CODE_KEY} }}] }
require 'barometer'
# use yahoo and weather bug, if they both fail, use wunderground
Barometer.config = { 1 => [:yahoo, {weather_bug: {keys: {code: CODE_KEY} }}], 2 => :wunderground }
barometer = Barometer.new('Paris')
weather = barometer.measure
puts weather.current.temperture
Extracted to separate gem: barometer-cli
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.
weather.current # returns the first successful current_measurement
weather.forecast # returns the first successful forecast_measurements
weather.today # returns the first successful forecast_measurement for today
weather.tomorrow # returns the first successful forecast_measurement for tomorrow
puts weather.current.temperature.c
puts weather.tomorrow.high.c
# note, the date is the date of the locations weather, not the date of the
# user measuring the weather
date = Date.parse('01-01-2009')
weather.for(date) # returns the first successful forecast_measurement for the date
puts weather.for(date).high.c
# note, the time is the time of the locations weather, not the time of the
# user measuring the weather
time = Time.parse('13:00 01-01-2009')
weather.for(time) # returns the first successful forecast_measurement for the time
puts weather.for(time).low.f
If you consume more then one weather service, Barometer will provide averages for the values (currently only for the 'current' values and not the forecasted values).
require 'barometer'
# use yahoo and 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
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
Thank you to these developers who have contributed. No contribution is too small.
- nofxx (https://github.com/nofxx)
- floere (https://github.com/floere)
- plukevdh (https://github.com/plukevdh)
- gkop (https://github.com/gkop)
- avit (https://github.com/avit)
- jimjeffers (https://github.com/jimjeffers)
- repo: http://github.com/attack/barometer
- rdoc: http://rdoc.info/projects/attack/barometer
- travis ci: https://travis-ci.org/attack/barometer
- code climate: https://codeclimate.com/github/attack/barometer
Copyright (c) 2009-2014 Mark Gangl. See LICENSE for details.