Giter Site home page Giter Site logo

ruby_open_weather_map's Introduction

Inviting maintainers

Kindly create an issue and tag me if you wish to become a maintainer.

A ruby wrapper for Open Weather Map API.

Build Status

Installation

Latest version 0.12.0

Add the following to your Gemfile

gem 'open-weather'

or

$ gem install open-weather

Usage

Getting and using the API key

How to get an API key and tips for an effective usage of the API: http://openweathermap.org/appid

# get current weather by city name
options = { units: "metric", APPID: "1111111111" }
OpenWeather::Current.city("Berlin, DE", options)

Current weather information API

require 'open_weather'

# get current weather by city name
OpenWeather::Current.city("Cochin, IN", options)

# get current weather by city id
OpenWeather::Current.city_id("1273874", options)

# get current weather by geocode. (lat, lon)
OpenWeather::Current.geocode(9.94, 76.26 , options)

# get current weather for a list of city ids
OpenWeather::Current.cities([524901, 703448, 2643743], options)

# get current weather for a bounding box
OpenWeather::Current.rectangle_zone(12, 32, 15, 37, 10, options)

# get current weather for cities around a point
OpenWeather::Current.circle_zone(55.5, 37.5, 10, options)

# By default temperature is returned in fahrenheit to get the current weather in degrees celsius use unit as follows.
options = { units: "metric", APPID: "1111111111" }
OpenWeather::Current.city("Cochin, IN", options)

Documentation about the current weather end-point: http://openweathermap.org/current

Weather forecast API

require 'open_weather'

# get weather forecast by city name
OpenWeather::Forecast.city("Cochin, IN", options)

# get weather forecast by city name in fahrenheit
OpenWeather::Forecast.city("Cochin, IN", options)

# get weather forecast by city id
OpenWeather::Forecast.city_id("1273874", options)

# get weather forecast by geocode. (lat, lon)
OpenWeather::Forecast.geocode(9.94, 76.26, options)

# get daily weather forecast by city name
OpenWeather::ForecastDaily.city("Cochin, IN", options)

# get daily weather forecast by city name in fahrenheit
OpenWeather::ForecastDaily.city("Cochin, IN", options)

# get daily weather forecast by city id
OpenWeather::ForecastDaily.city_id("1273874", options)

# get daily weather forecast by geocode. (lat, lon)
OpenWeather::ForecastDaily.geocode(9.94, 76.26, options)

# get daily weather forecast for 6 days
options[:cnt] = 6
OpenWeather::ForecastDaily.city_id("1273874", options)

Weather history API

require 'open_weather'

# get weather history by city name
OpenWeather::History.city("Cochin, IN", options)

# get weather history by city id
OpenWeather::History.city_id("1273874", options)

# get weather history by geocode. (lat, lon)
OpenWeather::History.geocode(9.94, 76.26, options)

Doucumentation about the weather forecast end-point: http://openweathermap.org/forecast

Multilingual support

# get current weather in german
options[:lang] = "de"
OpenWeather::Current.city("Berlin, DE",options)

Available languages are listed at: http://openweathermap.org/current#multi

Contributing

Fork it

Create your feature branch (git checkout -b my-new-feature)

Commit your changes (git commit -am 'Added some feature')

Push to the branch (git push origin my-new-feature)

Create new Pull Request


This gem was created during the Hacker Saturdays hosted by Kerala/Kochi Ruby Users Group

ruby_open_weather_map's People

Contributors

coderhs avatar deepakkumarnd avatar dileepnandanam avatar dnitza avatar iamdeuterium avatar jesseemond avatar nithinbekal avatar phitherekreborn avatar sanipym avatar ssendev avatar tachyons avatar yonelacort 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

Watchers

 avatar  avatar  avatar  avatar  avatar

ruby_open_weather_map's Issues

Now work on OSX 10.14

OpenWeather::Forecast.city("Cochin")
objc[1871]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[1871]: +[__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.

Handle current weather queries for multiple cities

See http://openweathermap.org/current#cities for the documentation.

3 calls are needed:

It appears to me that this would fit in the Current class, but the URLs are different (i.e. the URL for normal current weather differs from the one for rectangle/circle/cities). Maybe retrive could take an optional parameter to force a URL only for that request?

I will work on it and hopefully submit a PR in the following days.

response code is string on 404, but an Integer on 200

On a 404, the response code is a string.
On a 200, the response code is an Integer.

2.3.0 :042 > hayward = OpenWeather::Current.city("Hayward, CA", options)
 => {"coord"=>{"lon"=>-122.08, "lat"=>37.67}, "weather"=>[{"id"=>800, "main"=>"Clear", "description"=>"clear sky", "icon"=>"01n"}], "base"=>"stations", "main"=>{"temp"=>22.64, "pressure"=>1017, "humidity"=>52, "temp_min"=>17, "temp_max"=>28}, "visibility"=>16093, "wind"=>{"speed"=>7.7, "deg"=>290}, "clouds"=>{"all"=>1}, "dt"=>1473905437, "sys"=>{"type"=>1, "id"=>397, "message"=>0.0403, "country"=>"US", "sunrise"=>1473947449, "sunset"=>1473992102}, "id"=>5355933, "name"=>"Hayward", "cod"=>200} 
2.3.0 :043 > hayward['cod']
 => 200 
2.3.0 :044 > hayward['cod'].is_a? Integer
 => true 
2.3.0 :045 > bad_data = OpenWeather::Current.city("99999999999", options)
 => {"cod"=>"404", "message"=>"Error: Not found city"} 
2.3.0 :046 > bad_data['cod']
 => "404" 
2.3.0 :047 > bad_data['cod'].is_a? String
 => true 

Fix following warning generated during gem build

open_weather.gemspec:12: warning: Insecure world writable dir /Users/coderhs/.rvm/gems in PATH, mode 040777
WARNING:  licenses is empty, but is recommended.  Use a license abbreviation from:
http://opensource.org/licenses/alphabetical
WARNING:  open-ended dependency on rspec (>= 0, development) is not recommended
  if rspec is semantically versioned, use:
    add_development_dependency 'rspec', '~> 0'
WARNING:  open-ended dependency on vcr (>= 0, development) is not recommended
  if vcr is semantically versioned, use:
    add_development_dependency 'vcr', '~> 0'
WARNING:  open-ended dependency on webmock (>= 0, development) is not recommended
  if webmock is semantically versioned, use:
    add_development_dependency 'webmock', '~> 0'
WARNING:  open-ended dependency on json (>= 0) is not recommended
  if json is semantically versioned, use:
    add_runtime_dependency 'json', '~> 0'
WARNING:  See http://guides.rubygems.org/specification-reference/ for help

merge! leaving options dirty

merge! usage in find.rb seem to be leaving the options with the request parameters, affecting subsequent api calls

release new gem version

Thanks for the gem. I installed it vie gem 'open-weather' and got v0.10.0.
When i added lang: 'de' nothing changed. The reason is that v0.10.0 doesn't have the lang option.
Would be great if you cut a new release.

better error handling

JSON::ParserError: 757: unexpected token at '500
/proxy/data/2.5/forecast?q=%2ccoimbra%2c+pt&
'
/app/vendor/bundle/ruby/2.0.0/gems/json-1.8.2/lib/json/common.rb:155:in parse' /app/vendor/bundle/ruby/2.0.0/gems/json-1.8.2/lib/json/common.rb:155:inparse'
/app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/base.rb:40:in parse_response' /app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/base.rb:17:inretrive'
/app/vendor/bundle/ruby/2.0.0/gems/open-weather-0.11.0/lib/open_weather/api.rb:7:in `city'

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.