Simple ruby wrapper for the OpenWeatherMap api. The only hard requirements for this client is to register for an api key. This project intentionally does not implement all of the api endpoints to keep it light. Inspiration came from using it on a raspberry pi to ping the current weather state every 30 seconds.
Add this line to your application's Gemfile:
gem 'openweatherlite'And then execute:
$ bundle
Or install it yourself as:
$ gem install openweatherlite
weather = OpenWeatherLite::Weather.new('api_key')
weather.by_zip_code(60606)This class is the api class for openweather
api_keyunits(metric, imperial)
Provide an optional api_key
# With optional api_key
OpenWeatherLite::Weather.new('api_key')
# Without api key
weather = OpenWeatherLite::Weather.new
weather.api_key = 'api_key'Provide zip_code and optionally country. country defaults to us. Returns OpenWeatherLite::WeatherResponse
weather = OpenWeatherLite::Weather.new('api_key')
# returns OpenWeatherLite::WeatherResponse
response = weather.by_zip_code(60606)Provide a city_id according to openweathermap and returns OpenWeatherLite::WeatherResponse
# returns OpenWeatherLite::WeatherResponse
weather.by_city_id(2172797)Provide latitude and longitude and returns OpenWeatherLite::WeatherResponse
# returns OpenWeatherLite::WeatherResponse
weather.by_coords(35, 139)Returns a hash of the coordinates
response.coords
# { latitude: 123, longitude: 123 }Returns the temperature value from the reponse. Unit is in units provided by to OpenWeatherLite::Weather
response.temperatureReturns the pressure value from the response
response.pressureReturns the humidity value from the response
response.humidityReturns an array with the [min, max] values from the response
response.temperature_rangeReturns the wind details hash with speed and deg from the response
response.windReturns true or false if there are any clouds
response.cloudy?Returns the percentage of clouds in a hash
response.cloudsReturns true or false depending on whether it is, or has rained in the past 3 hours
Returns the amount that it has rained in the last 3 hours in a hash
response.rain
# { '3h' => .445 }Returns true or false depending on whether it is, or has rained in the past 3 hours
response.snowy?Returns the amount that it has snowed in the last 3 hours in a hash
response.snow
# { '3h' => .445 }Returns the time for sunrise today
response.sunriseReturns the time for sunset today
response.sunsetAfter checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Bug reports and pull requests are welcome on GitHub at https://github.com/zsyed91/openweatherlite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.