Skip to content

Commit 058ea52

Browse files
committed
Merge pull request #16 from iamdeuterium/master
Added daily forecast support.
2 parents 57dd8f6 + cd874da commit 058ea52

15 files changed

+575
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ OpenWeather::Forecast.city_id("1273874")
5151

5252
# get weather forecast by geocode. (lat, lon)
5353
OpenWeather::Forecast.geocode(9.94, 76.26)
54+
55+
# get daily weather forecast by city name
56+
OpenWeather::ForecastDaily.city("Cochin, IN")
57+
58+
# get daily weather forecast by city name in fahrenheit
59+
OpenWeather::ForecastDaily.city("Cochin, IN", units: 'imperial')
60+
61+
# get daily weather forecast by city id
62+
OpenWeather::ForecastDaily.city_id("1273874")
63+
64+
# get daily weather forecast by geocode. (lat, lon)
65+
OpenWeather::ForecastDaily.geocode(9.94, 76.26)
66+
67+
# get daily weather forecast for 6 days
68+
OpenWeather::ForecastDaily.city_id("1273874", cnt: 6)
5469
```
5570

5671
Doucumentation about the weather forecast end-point:

lib/open_weather.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module OpenWeather
44
autoload :Base, "open_weather/base"
55
autoload :Current, "open_weather/current"
66
autoload :Forecast, "open_weather/forecast"
7+
autoload :ForecastDaily, "open_weather/forecast_daily"
78
autoload :VERSION, "open_weather/version"
89

910
require "open_weather/api.rb"

lib/open_weather/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def success?
2424
private
2525

2626
def extract_options!(options)
27-
valid_options = [:lat, :lon, :city, :country, :id, :units, :APPID, :lang]
27+
valid_options = [:lat, :lon, :city, :country, :id, :units, :cnt, :APPID, :lang]
2828
options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }
2929

3030
if options[:city] || options[:country]

lib/open_weather/forecast_daily.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module OpenWeather
2+
class ForecastDaily < Base
3+
def initialize options = {}
4+
super('http://api.openweathermap.org/data/2.5/forecast/daily', options)
5+
end
6+
end
7+
end

spec/fixtures/cassettes/api/forecast_daily_city_id_invalid.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/cassettes/api/forecast_daily_city_id_valid.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/cassettes/api/forecast_daily_city_imperial_valid.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/cassettes/api/forecast_daily_city_metric_valid.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/cassettes/api/forecast_daily_city_valid.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/cassettes/api/forecast_daily_cnt_6.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)