forked from dblock/open-weather-ruby-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dblock#42 from alliedcode/feature/30-day-forecast
Added support for the thirty day forecast in the pro 2.5 API
- Loading branch information
Showing
13 changed files
with
436 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Endpoints | ||
module ThirtyDayForecast | ||
def thirty_day_forecast(lat, lon = nil, options = {}) | ||
# default to the pro endpoint if not specified | ||
endpoint = options.delete(:endpoint) || pro_endpoint | ||
options = options.merge(endpoint: endpoint) | ||
|
||
options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon) | ||
OpenWeather::Models::Forecast::ThirtyDay::ThirtyDay.new(get('2.5/forecast/climate', options), options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'forecast/hourly' | ||
require_relative 'forecast/thirty_day' | ||
require_relative 'forecast/forecast' | ||
require_relative 'forecast/city' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'thirty_day/thirty_day' | ||
require_relative 'thirty_day/forecast' | ||
require_relative 'thirty_day/temp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
module ThirtyDay | ||
class Forecast < Model | ||
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data forcasted, UTC | ||
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # Sunrise time, UTC | ||
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # Sunset time, UTC | ||
property 'temp' # Array of OpenWeather::Models::Forecast::ThityDay::Temp | ||
property 'feels_like' # OpenWeather::Models::OneCall::FeelsLike | ||
property 'pressure' # Atmospheric pressure on the sea level, hPa | ||
property 'humidity' # Humidity, % (e.g. integer 24 means 24% cloudiness) | ||
property 'weather' # Array of OpenWeather::Models::Weather | ||
property 'speed' # Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour | ||
property 'deg' # Wind direction, degrees (meteorological) | ||
property 'clouds' # Cloudiness, % (e.g. integer 78 means 78% cloudiness) | ||
property 'rain' # Precipitation volume, mm. Unit will only be in mm | ||
property 'snow' # Snow volume, mm. Unit will only be in mm | ||
|
||
def initialize(args = nil, options = {}) | ||
super args, options | ||
|
||
self.temp = Temp.new(temp, options) if temp | ||
self.feels_like = OpenWeather::Models::OneCall::FeelsLike.new(feels_like, options) if feels_like | ||
self.weather = weather.map { |w| OpenWeather::Models::Weather.new(w, options) } if weather | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
module ThirtyDay | ||
class Temp < Model | ||
temperature_property 'day' # Day temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
temperature_property 'min' # Min daily temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
temperature_property 'max' # Max daily temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
temperature_property 'night' # Night temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
temperature_property 'eve' # Evening temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
temperature_property 'morn' # Morning temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
module ThirtyDay | ||
class ThirtyDay < Model | ||
include Enumerable | ||
|
||
property 'cod' # Internal parameter | ||
property 'message' # Internal parameter | ||
property 'city' | ||
property 'cnt' # Number of items in list | ||
property 'list' # List of ??? objects | ||
|
||
def initialize(args = nil, options = {}) | ||
super args, options | ||
|
||
self.list = list.map { |forecast| Forecast.new(forecast, options) } if list | ||
self.city = OpenWeather::Models::Forecast::City.new(city, options) if city | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.