Git Product home page Git Product logo

forecast-ruby's Introduction

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.

forecast-ruby's People

Contributors

alepore avatar czarneckid avatar dallarosa avatar norbert avatar pat avatar strikemike2k avatar sutra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

forecast-ruby's Issues

API requests hang indefinitely

We received this from an API user:

I'm using your forecast_io ruby gem in Rails: https://rubygems.org/gems/forecast_io

When I call the API, it hangs indefinitely:

ForecastIO.forecast(latitude, longitude, time: start_time, params: { exclude: 'flags,minutely,hourly,alert' })

Let me know if I can do anything else to provide more info, or if you know what the problem is.

We're not experiencing any issues directly with the API. Is there any cause that might be specific to the library or to the client that I should request from them?

Not work on macOS Mojave: may have been in progress in another thread when fork() was called.

forecast = ForecastIO.forecast(37.8267, -122.423)
objc[1684]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[1684]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.