diff --git a/README.md b/README.md index 71ff053..25adeef 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ OpenWeather::Forecast.city("Cochin, IN") # get weather forecast by city name in fahrenheit OpenWeather::Forecast.city("Cochin, IN", units: 'imperial') +# get weather forecast by zip code +OpenWeather::Forecast.zip("33704,US") + # get weather forecast by city id OpenWeather::Forecast.city_id("1273874") @@ -81,7 +84,7 @@ OpenWeather::ForecastDaily.geocode(9.94, 76.26) OpenWeather::ForecastDaily.city_id("1273874", cnt: 6) ``` -Doucumentation about the weather forecast end-point: +Documentation about the weather forecast end-point: http://openweathermap.org/forecast #### Using the API key diff --git a/lib/open_weather/api.rb b/lib/open_weather/api.rb index 52b8e18..18323ad 100644 --- a/lib/open_weather/api.rb +++ b/lib/open_weather/api.rb @@ -7,6 +7,12 @@ def city(city, options = {}) new(options.merge(city: city)).retrieve end + #Zip format : 33704,US + #Usage: OpenWeather::Current.zip('33704,Us') + def zip(zip, options ={}) + new(options.merge(zip: zip)).retrieve + end + # City Id, an integer value. Eg, 2172797 # Usage: OpenWeather::Current.city_id(2172797) def city_id(id, options = {}) diff --git a/lib/open_weather/base.rb b/lib/open_weather/base.rb index ae64c5f..c4ef585 100644 --- a/lib/open_weather/base.rb +++ b/lib/open_weather/base.rb @@ -24,7 +24,7 @@ def success? private def extract_options!(options) - valid_options = [ :id, :lat, :lon, :cnt, :city, :lang, :units, :APPID, + valid_options = [ :id, :zip, :lat, :lon, :cnt, :city, :lang, :units, :APPID, :country, :bbox] options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }