Skip to content
Ruby gem for retrieving data from the Forecast Weather API.
Branch: master
Clone or download
Latest commit cb007ac Jan 30, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Bump version to 2.0.2 Jan 30, 2018
spec Bump version to 2.0.2 Jan 30, 2018
.gitignore Initial commit Mar 11, 2013
.rspec Support to rspec > 2 Oct 9, 2014
.ruby-gemset Updating copyright for 2014. Use double instead of stub to remove dep… Jan 14, 2014
.ruby-version updating ruby version to 2.3.1. Jul 30, 2016
Gemfile Initial commit Mar 11, 2013
LICENSE.txt Update copyright year Jan 30, 2018 Update copyright year Jan 30, 2018
Rakefile Initial commit Mar 11, 2013
forecast_io.gemspec Forecast::IO is now ForecastIO. Jul 4, 2013

forecast_io API wrapper in Ruby.


gem install forecast_io

or in your Gemfile

gem 'forecast_io'


Make sure you require the library.

require 'forecast_io'

You will need to set your API key before you can make requests to the API.

ForecastIO.configure do |configuration|
  configuration.api_key = 'this-is-your-api-key'


ForecastIO.api_key = 'this-is-your-api-key'

You can then make requests to the ForecastIO.forecast(latitude, longitude, options = {}) method.

Valid options in the options hash are:

  • :time - Unix time in seconds.
  • :params - Query parameters that can contain the following:
    • :jsonp - JSONP callback.
    • :units - Return the API response in SI units, rather than the default Imperial units.
    • :exclude - "Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space. [blocks] should be a comma-delimeted list (without spaces) of any of the following: currently, minutely, hourly, daily, alerts, flags." (via v2 docs)

Get the current forecast:

forecast = ForecastIO.forecast(37.8267, -122.423)

Get the current forecast at a given time:

forecast = ForecastIO.forecast(37.8267, -122.423, time:, 3, 11).to_i)

Get the current forecast and use SI units:

forecast = ForecastIO.forecast(37.8267, -122.423, params: { units: 'si' })

The forecast(...) method will return a response that you can interact with in a more-friendly way, such as:

forecast = ForecastIO.forecast(37.8267, -122.423)

Please refer to the API documentation for more information on the full response properties.

The HTTP requests are made with Faraday, which uses Net::HTTP by default. Changing the adapter is easy. We will use typhoeus as an example.

Make sure to include the typhoeus gem in your Gemfile:

gem 'typhoeus'
require 'typhoeus/adapters/faraday'

Faraday.default_adapter = :typhoeus


require 'typhoeus/adapters/faraday'

ForecastIO.connection = do |builder|
  builder.adapter :typhoeus

You can also customise the default parameters passed through on each API call:

ForecastIO.default_params = {units: 'si'}

# or

ForecastIO.configure do |configuration|
  configuration.default_params = {units: 'si'}

Contributing to forecast_io

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2013-2018 David Czarnecki. See LICENSE.txt for further details.

You can’t perform that action at this time.