Skip to content

Implement method for finding current weather by zipcode #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/open_weather/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down