Skip to content
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 @@ -58,6 +58,9 @@ 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)

# get current weather by zip code (zip,country_code)
OpenWeather::Current.zip("33704,US", 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)
Expand Down Expand Up @@ -117,7 +120,7 @@ OpenWeather::History.city_id("1273874", options)
OpenWeather::History.geocode(9.94, 76.26, options)
```

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


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 @@ -17,6 +17,12 @@ def city_id(id, options = {})
def geocode(lat, lon, options = {})
new(options.merge(lat: lat, lon: lon)).retrieve
end

# Zip code format: '33704,US'
# Usage: OpenWeather::Current.zip('33704,US')
def zip(zip_code, options = {})
new(options.merge(zip: zip_code)).retrieve
end
end

module SeveralCitiesClassMethods
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, :q, :type, :start, :end]

options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }
Expand Down
47 changes: 47 additions & 0 deletions spec/fixtures/cassettes/api/current_zip_invalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions spec/fixtures/cassettes/api/current_zip_valid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions spec/open_weather/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
end
end

context '.zip' do
it 'returns current weather for a valid zip code' do
response = VCR.use_cassette('api/current_zip_valid') do
OpenWeather::Current.zip('33704,US')
end
response['cod'].should eq(200)
end

it 'returns error if the zip code is invalid' do
response = VCR.use_cassette('api/current_zip_invalid') do
OpenWeather::Current.zip('00000,US')
end
response['cod'].should eq('404')
end
end

context '.geocode' do
it 'return current weather for geocode of cochi' do
response = VCR.use_cassette('api/current_geocode_valid') do
Expand Down