-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
204 additions
and
0 deletions.
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
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 Hourly | ||
def hourly(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::Hourly.new(get('2.5/forecast/hourly', 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
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 'forecast/hourly' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
class City < Model | ||
property 'id' # City ID | ||
property 'name' # City name | ||
property 'coord', transform_with: ->(v) { OpenWeather::Models::Coord.new(v) } # City geo location | ||
property 'country' # Country code (GB, JP etc.). | ||
property 'timezone' # shift in seconds from 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 | ||
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
class Forecast < Model | ||
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data forcasted, UTC | ||
property 'dt_txt' # Time of data forecasted, ISO, UTC | ||
property 'main' | ||
property 'weather' | ||
property 'clouds' | ||
property 'wind' | ||
property 'rain' | ||
property 'snow' | ||
property 'visibility' # Average visibility, metres. The maximum value of the visibility is 10km | ||
property 'pop' # Probability of precipitation. The values of the parameter vary between 0 and 1, where 0 is equal to 0%, 1 is equal to 100% | ||
property 'sys' | ||
|
||
def initialize(args = nil, options = {}) | ||
super args, options | ||
|
||
self.main = OpenWeather::Models::Main.new(main, options) if main | ||
self.weather = weather.map { |w| OpenWeather::Models::Weather.new(w, options) } if weather | ||
self.clouds = OpenWeather::Models::Clouds.new(clouds, options) if clouds | ||
self.wind = OpenWeather::Models::Wind.new(wind, options) if wind | ||
self.rain = OpenWeather::Models::Rain.new(rain, options) if rain | ||
self.snow = OpenWeather::Models::Snow.new(snow, options) if snow | ||
self.sys = OpenWeather::Models::Sys.new(sys, options) if sys | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module OpenWeather | ||
module Models | ||
module Forecast | ||
class Hourly < Model | ||
include Enumerable | ||
|
||
property 'cod' | ||
property 'calctime' | ||
property 'cnt', from: 'count' | ||
property 'list' | ||
property 'message' | ||
property 'city' | ||
|
||
def initialize(args = nil, options = {}) | ||
super args, options | ||
|
||
self.list = list.map { |forecast| OpenWeather::Models::Forecast::Forecast.new(forecast, options) } if list | ||
self.city = OpenWeather::Models::Forecast::City.new(city, options) if city | ||
end | ||
end | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'hourly forecast' do | ||
include_context 'API client' | ||
|
||
it 'hourly', vcr: { cassette_name: 'forecast/hourly' } do | ||
data = client.hourly(lat: 33.5312, lon: -111.9426) | ||
|
||
expect(data).to be_a OpenWeather::Models::Forecast::Hourly | ||
expect(data.cnt).to eq 96 | ||
expect(data.city).to be_a OpenWeather::Models::Forecast::City | ||
|
||
expect(data.list).to be_a Array | ||
data.list.first.tap do |forecast| | ||
expect(forecast).to be_a OpenWeather::Models::Forecast::Forecast | ||
expect(forecast.dt).to eq Time.at(1661875200) | ||
expect(forecast.main).to be_a OpenWeather::Models::Main | ||
expect(forecast.weather).to be_a Array | ||
expect(forecast.weather.first).to be_a OpenWeather::Models::Weather | ||
expect(forecast.clouds).to be_a OpenWeather::Models::Clouds | ||
expect(forecast.wind).to be_a OpenWeather::Models::Wind | ||
expect(forecast.rain).to be_a OpenWeather::Models::Rain | ||
expect(forecast.snow).to be_nil | ||
expect(forecast.visibility).to eq 10000 | ||
expect(forecast.pop).to eq 0.32 | ||
expect(forecast.sys).to be_a OpenWeather::Models::Sys | ||
expect(forecast.dt_txt).to eq '2022-08-30 16:00:00' | ||
end | ||
end | ||
end |