pirate_weather_forecast_ruby
Pirate Weather forecast.io API wrapper in Ruby, forked from Dark Sky's forecast.io.
Pirate Weather aims to be a drop-in replacement for Apple's (now) removed Dark Sky API. Similarly, this project's goal is to provide a drop-in replacement for the Ruby Dark Sky API wrapper.
Installation
gem install pirate_weather_forecast_ruby
or in your Gemfile
gem 'pirate_weather_forecast_ruby'
Usage
Make sure you require the library.
require 'pirate_weather_forecast_ruby'
You need to set an API key before you can make requests to the API. Grab one from Pirate Weather.
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 Dark Sky's 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
Contributing
⏳
Copyright (c) 2023 Alex Cochran