• This repository has been archived on 25/Apr/2020
  • Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby gem for retrieving data from the Forecast Weather API.

forecast_io

forecast.io API wrapper in Ruby.

Installation

gem install forecast_io

or in your Gemfile

gem 'forecast_io'

Usage

Make sure you require the library.

require 'forecast_io'

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

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

Alternatively:

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: Time.new(2013, 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)
forecast.latitude
forecast.longitude

Please refer to the forecast.io 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

Alternatively:

require 'typhoeus/adapters/faraday'

ForecastIO.connection = Faraday.new do |builder|
  builder.adapter :typhoeus
end

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'}
end

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

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

More Repositories

1

skycons

JavaScript
1,249
star
2

delaunay-fast

Fast Delaunay Triangulation in JavaScript.
JavaScript
778
star
3

string-hash

Fast string hashing function for Node.JS.
JavaScript
309
star
4

tz-lookup-oss

JavaScript Library for Timezone Lookup by Location
JavaScript
208
star
5

translations

translate Dark Sky API summaries into any language
JavaScript
139
star
6

sphere-knn

Find the k nearest neighbors for points on a sphere.
JavaScript
121
star
7

binary-search

Tiny binary search library for Node.JS.
JavaScript
85
star
8

pngparse

100%-JavaScript PNG Parser for Node.JS
JavaScript
78
star
9

darksky-ruby

Ruby gem for retrieving data from the Dark Sky API
Ruby
48
star
10

astro

JavaScript
30
star
11

delaunay

Delaunay triangulation in arbitrary dimensions.
JavaScript
23
star
12

inhabited

quickly determine if a lat/lon may be inhabited or not
JavaScript
18
star
13

node-sarra

consume data from Environment and Climate Change Canada
JavaScript
13
star
14

metaregexp

A simple way to keep long regexes organized.
JavaScript
9
star
15

lowres-rgeo

low resolution reverse geocoder for Node.JS
JavaScript
9
star
16

elevation

Finds the elevation of a lat/lon with low-to-moderate resolution
JavaScript
7
star
17

pbj

tiny, stupid bitmap image format
JavaScript
6
star
18

cache

An in-memory, promise-backed cache
JavaScript
5
star
19

bounding

calculate bounding areas of points
JavaScript
4
star
20

zqueue

A little redis-backed queue dingus.
JavaScript
4
star
21

cache-helpers

Caching helper functions for Node.JS.
JavaScript
4
star
22

regression

A tiny Javascript toolkit for regression analysis.
JavaScript
4
star
23

shape

spherical geometry library
JavaScript
1
star