From eafab09a7a02b9e68f15c8b408f13ff21a3d99b6 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 13 May 2020 23:58:23 -0400 Subject: [PATCH] Added support for one-call API. --- .rubocop_todo.yml | 4 +- CHANGELOG.md | 1 + README.md | 37 +++++++ lib/open_weather/client.rb | 1 + lib/open_weather/endpoints.rb | 1 + lib/open_weather/endpoints/one_call.rb | 15 +++ lib/open_weather/models.rb | 1 + lib/open_weather/models/model.rb | 2 +- lib/open_weather/models/one_call.rb | 9 ++ .../models/one_call/current_weather.rb | 27 +++++ .../models/one_call/daily_weather.rb | 26 +++++ .../models/one_call/feels_like.rb | 14 +++ .../models/one_call/hourly_weather.rb | 24 +++++ .../models/one_call/minutely_weather.rb | 12 +++ lib/open_weather/models/one_call/temp.rb | 16 +++ lib/open_weather/models/one_call/weather.rb | 17 +++ lib/open_weather/models/sys.rb | 1 + .../one_call/error_out_of_range.yml | 45 ++++++++ .../open_weather/one_call/lat_lon.yml | 101 ++++++++++++++++++ .../lat_lon_exclude_minutely_hourly.yml | 53 +++++++++ .../one_call/lat_lon_yesterday.yml | 69 ++++++++++++ spec/open_weather/one_call/one_call_spec.rb | 69 ++++++++++++ 22 files changed, 542 insertions(+), 3 deletions(-) create mode 100644 lib/open_weather/endpoints/one_call.rb create mode 100644 lib/open_weather/models/one_call.rb create mode 100644 lib/open_weather/models/one_call/current_weather.rb create mode 100644 lib/open_weather/models/one_call/daily_weather.rb create mode 100644 lib/open_weather/models/one_call/feels_like.rb create mode 100644 lib/open_weather/models/one_call/hourly_weather.rb create mode 100644 lib/open_weather/models/one_call/minutely_weather.rb create mode 100644 lib/open_weather/models/one_call/temp.rb create mode 100644 lib/open_weather/models/one_call/weather.rb create mode 100644 spec/fixtures/open_weather/one_call/error_out_of_range.yml create mode 100644 spec/fixtures/open_weather/one_call/lat_lon.yml create mode 100644 spec/fixtures/open_weather/one_call/lat_lon_exclude_minutely_hourly.yml create mode 100644 spec/fixtures/open_weather/one_call/lat_lon_yesterday.yml create mode 100644 spec/open_weather/one_call/one_call_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49c1879..6c91262 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-05-01 09:30:27 -0400 using RuboCop version 0.81.0. +# on 2020-05-14 00:06:00 -0400 using RuboCop version 0.81.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -13,7 +13,7 @@ Naming/FileName: Exclude: - 'lib/open-weather-ruby-client.rb' -# Offense count: 38 +# Offense count: 84 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/CHANGELOG.md b/CHANGELOG.md index 6317c0b..c7e2c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 0.2.0 (Next) +* [#14](https://github.com/dblock/open-weather-ruby-client/pull/14): Added support for One Call API - [@dblock](https://github.com/dblock). * [#12](https://github.com/dblock/open-weather-ruby-client/pull/12): Cache `Faraday::Connection` for persistent adapters - [@dblock](https://github.com/dblock). * [#13](https://github.com/dblock/open-weather-ruby-client/pull/13): Require Faraday >= 1.0 - [@dblock](https://github.com/dblock). * Your contribution here. diff --git a/README.md b/README.md index 3494ccc..96e072e 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o - [Cities Within a Rectangle Zone](#cities-within-a-rectangle-zone) - [Cities Within a Circle](#cities-within-a-circle) - [Multiple Cities by Id](#multiple-cities-by-id) + - [One Call](#one-call) + - [Current and Forecast Weather](#current-and-forecast-weather) + - [Historical Weather](#historical-weather) - [Configuration](#configuration) - [Units](#units) - [Language](#language) @@ -149,6 +152,40 @@ data.first.name # 'Moscow' data.main.temp # => 285.15 ``` +### One Call + +[One Call API](https://openweathermap.org/api/one-call-api) provides current weather, minute forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 7 days, and historical weather data for 5 previous days for any geographical coordinate. + +#### Current and Forecast Weather + +```ruby +data = client.one_call(lat: 33.441792, lon: -94.037689) # => OpenWeather::Models::OneCall::Weather +data.lat # => 33.44 +data.lon # => -94.04 +data.timezone # => 'America/Chicago' +data.current # => OpenWeather::Models::OneCall::CurrentWeather +data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather] +data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather] +data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather] +``` + +Exclude minutely and hourly data. + +```ruby +client.one_call(lat: 33.441792, lon: -94.037689, exclude: ['minutely', 'hourly']) +``` + +#### Historical Weather + +```ruby +data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.now - 24 * 60 * 60) # => OpenWeather::Models::OneCall::Weather +data.lat # => 33.44 +data.lon # => -94.04 +data.timezone # => 'America/Chicago' +data.current # => OpenWeather::Models::OneCall::CurrentWeather +data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather] +``` + ## Configuration You can configure client options, globally. diff --git a/lib/open_weather/client.rb b/lib/open_weather/client.rb index 4a0cef6..faddfaf 100644 --- a/lib/open_weather/client.rb +++ b/lib/open_weather/client.rb @@ -5,6 +5,7 @@ class Client include Connection include Request include Endpoints::Current + include Endpoints::OneCall attr_accessor(*Config::ATTRIBUTES) diff --git a/lib/open_weather/endpoints.rb b/lib/open_weather/endpoints.rb index f057324..4aef6fa 100644 --- a/lib/open_weather/endpoints.rb +++ b/lib/open_weather/endpoints.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true require_relative 'endpoints/current' +require_relative 'endpoints/one_call' diff --git a/lib/open_weather/endpoints/one_call.rb b/lib/open_weather/endpoints/one_call.rb new file mode 100644 index 0000000..5a04530 --- /dev/null +++ b/lib/open_weather/endpoints/one_call.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module OpenWeather + module Endpoints + module OneCall + def one_call(lat, lon = nil, options = {}) + options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon) + options[:exclude] = options[:exclude].join(',') if options[:exclude].is_a?(Array) + options[:dt] = options[:dt].to_i if options[:dt].is_a?(Time) + path = options.key?(:dt) ? 'onecall/timemachine' : 'onecall' + OpenWeather::Models::OneCall::Weather.new(get(path, options)) + end + end + end +end diff --git a/lib/open_weather/models.rb b/lib/open_weather/models.rb index 0c0682e..62c06c2 100644 --- a/lib/open_weather/models.rb +++ b/lib/open_weather/models.rb @@ -11,3 +11,4 @@ require_relative 'models/rain' require_relative 'models/snow' require_relative 'models/list' +require_relative 'models/one_call' diff --git a/lib/open_weather/models/model.rb b/lib/open_weather/models/model.rb index aa1c27a..889f47c 100644 --- a/lib/open_weather/models/model.rb +++ b/lib/open_weather/models/model.rb @@ -3,7 +3,7 @@ module OpenWeather module Models class Model < Hashie::Trash - include Hashie::Extensions::IgnoreUndeclared + # include Hashie::Extensions::IgnoreUndeclared end end end diff --git a/lib/open_weather/models/one_call.rb b/lib/open_weather/models/one_call.rb new file mode 100644 index 0000000..e4dc09c --- /dev/null +++ b/lib/open_weather/models/one_call.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require_relative 'one_call/temp' +require_relative 'one_call/feels_like' +require_relative 'one_call/current_weather' +require_relative 'one_call/daily_weather' +require_relative 'one_call/hourly_weather' +require_relative 'one_call/minutely_weather' +require_relative 'one_call/weather' diff --git a/lib/open_weather/models/one_call/current_weather.rb b/lib/open_weather/models/one_call/current_weather.rb new file mode 100644 index 0000000..a5789d7 --- /dev/null +++ b/lib/open_weather/models/one_call/current_weather.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class CurrentWeather < Model + property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data 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' # temperature + property 'feels_like' # temperature, accounts for the human perception of weather + property 'pressure' # atmospheric pressure on the sea level, hPa + property 'humidity' # humidity, % + property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + property 'clouds' # cloudiness, % + property 'uvi' # UV index + property 'visibility' # average visibility, meters + property 'wind_speed' # wind speed + property 'wind_gust' # wind gust + property 'wind_deg' # wind direction, degrees (meteorological) + property 'rain', transform_with: ->(v) { OpenWeather::Models::Rain.new(v) } + property 'snow', transform_with: ->(v) { OpenWeather::Models::Snow.new(v) } + property 'weather', transform_with: ->(v) { v.map { |i| OpenWeather::Models::Weather.new(i) } } + end + end + end +end diff --git a/lib/open_weather/models/one_call/daily_weather.rb b/lib/open_weather/models/one_call/daily_weather.rb new file mode 100644 index 0000000..fa85d8c --- /dev/null +++ b/lib/open_weather/models/one_call/daily_weather.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class DailyWeather < Model + property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data 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', transform_with: ->(v) { OpenWeather::Models::OneCall::Temp.new(v) } + property 'feels_like', transform_with: ->(v) { OpenWeather::Models::OneCall::FeelsLike.new(v) } + property 'pressure' # atmospheric pressure on the sea level, hPa + property 'humidity' # humidity, % + property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + property 'wind_speed' # wind speed + property 'wind_gust' # wind gust + property 'wind_deg' # wind direction, degrees (meteorological) + property 'clouds' # cloudiness, % + property 'uvi' # UV index + property 'rain' # precipitation volume, mm + property 'snow' # snow volume, mm + property 'weather', transform_with: ->(v) { v.map { |i| OpenWeather::Models::Weather.new(i) } } + end + end + end +end diff --git a/lib/open_weather/models/one_call/feels_like.rb b/lib/open_weather/models/one_call/feels_like.rb new file mode 100644 index 0000000..4b39dca --- /dev/null +++ b/lib/open_weather/models/one_call/feels_like.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class FeelsLike < Model + property 'morn' + property 'day' + property 'eve' + property 'night' + end + end + end +end diff --git a/lib/open_weather/models/one_call/hourly_weather.rb b/lib/open_weather/models/one_call/hourly_weather.rb new file mode 100644 index 0000000..72520f0 --- /dev/null +++ b/lib/open_weather/models/one_call/hourly_weather.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class HourlyWeather < Model + property 'dt', transform_with: ->(v) { Time.at(v).utc } # Time of the forecasted data UTC + property 'temp' + property 'feels_like' + property 'pressure' # atmospheric pressure on the sea level, hPa + property 'humidity' # humidity, % + property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + property 'clouds' # cloudiness, % + property 'visibility' # average visibility, meters + property 'wind_speed' # wind speed. + property 'wind_gust' # wind gust. + property 'wind_deg' # wind direction, degrees (meteorological) + property 'rain', transform_with: ->(v) { OpenWeather::Models::Rain.new(v) } + property 'snow', transform_with: ->(v) { OpenWeather::Models::Snow.new(v) } + property 'weather', transform_with: ->(v) { v.map { |i| OpenWeather::Models::Weather.new(i) } } + end + end + end +end diff --git a/lib/open_weather/models/one_call/minutely_weather.rb b/lib/open_weather/models/one_call/minutely_weather.rb new file mode 100644 index 0000000..dd20b69 --- /dev/null +++ b/lib/open_weather/models/one_call/minutely_weather.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class MinutelyWeather < Model + property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data UTC + property 'precipitation' + end + end + end +end diff --git a/lib/open_weather/models/one_call/temp.rb b/lib/open_weather/models/one_call/temp.rb new file mode 100644 index 0000000..591fbef --- /dev/null +++ b/lib/open_weather/models/one_call/temp.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class Temp < Model + property 'morn' + property 'day' + property 'eve' + property 'night' + property 'min' + property 'max' + end + end + end +end diff --git a/lib/open_weather/models/one_call/weather.rb b/lib/open_weather/models/one_call/weather.rb new file mode 100644 index 0000000..3ce332d --- /dev/null +++ b/lib/open_weather/models/one_call/weather.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module OpenWeather + module Models + module OneCall + class Weather < Model + property 'lat' # geographical coordinates of the location (latitude) + property 'lon' # geographical coordinates of the location (longitude) + property 'timezone' # timezone name for the requested location + property 'current', transform_with: ->(v) { OpenWeather::Models::OneCall::CurrentWeather.new(v) } + property 'minutely', transform_with: ->(v) { v.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i) } } + property 'hourly', transform_with: ->(v) { v.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i) } } + property 'daily', transform_with: ->(v) { v.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i) } } + end + end + end +end diff --git a/lib/open_weather/models/sys.rb b/lib/open_weather/models/sys.rb index c437e94..aedc494 100644 --- a/lib/open_weather/models/sys.rb +++ b/lib/open_weather/models/sys.rb @@ -3,6 +3,7 @@ module OpenWeather module Models class Sys < Model + property 'timezone' # shift in seconds from UTC property 'type' # internal parameter property 'id' # internal parameter property 'message' # internal parameter diff --git a/spec/fixtures/open_weather/one_call/error_out_of_range.yml b/spec/fixtures/open_weather/one_call/error_out_of_range.yml new file mode 100644 index 0000000..bfb8a15 --- /dev/null +++ b/spec/fixtures/open_weather/one_call/error_out_of_range.yml @@ -0,0 +1,45 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.openweathermap.org/data/2.5/onecall/timemachine?appid=api-key&dt=1583902800&lat=33.441792&lon=-94.037689 + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - OpenWeather Ruby Client/0.2.0 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 400 + message: Bad Request + headers: + Server: + - openresty + Date: + - Thu, 14 May 2020 03:47:07 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '79' + Connection: + - keep-alive + X-Cache-Key: + - "/data/2.5/onecall/timemachine?dt=1583902800&lat=33.44&lon=-94.04" + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST + body: + encoding: UTF-8 + string: '{"cod":"400","message":"requested time is out of allowed range of 5 + days back"}' + http_version: null + recorded_at: Thu, 14 May 2020 03:47:07 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/open_weather/one_call/lat_lon.yml b/spec/fixtures/open_weather/one_call/lat_lon.yml new file mode 100644 index 0000000..1a2a92b --- /dev/null +++ b/spec/fixtures/open_weather/one_call/lat_lon.yml @@ -0,0 +1,101 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.openweathermap.org/data/2.5/onecall?appid=api-key&lat=33.441792&lon=-94.037689 + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - OpenWeather Ruby Client/0.2.0 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Server: + - openresty + Date: + - Thu, 14 May 2020 03:09:08 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '16841' + Connection: + - keep-alive + X-Cache-Key: + - "/data/2.5/onecall?lat=33.44&lon=-94.04" + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST + body: + encoding: UTF-8 + string: '{"lat":33.44,"lon":-94.04,"timezone":"America/Chicago","current":{"dt":1589425748,"sunrise":1589368621,"sunset":1589418488,"temp":295.55,"feels_like":296.21,"pressure":1015,"humidity":64,"dew_point":288.41,"uvi":10.31,"clouds":1,"visibility":16093,"wind_speed":1.5,"wind_deg":130,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},"minutely":[{"dt":1589425800,"precipitation":0},{"dt":1589425860,"precipitation":0},{"dt":1589425920,"precipitation":0},{"dt":1589425980,"precipitation":0},{"dt":1589426040,"precipitation":0},{"dt":1589426100,"precipitation":0},{"dt":1589426160,"precipitation":0},{"dt":1589426220,"precipitation":0},{"dt":1589426280,"precipitation":0},{"dt":1589426340,"precipitation":0},{"dt":1589426400,"precipitation":0},{"dt":1589426460,"precipitation":0},{"dt":1589426520,"precipitation":0},{"dt":1589426580,"precipitation":0},{"dt":1589426640,"precipitation":0},{"dt":1589426700,"precipitation":0},{"dt":1589426760,"precipitation":0},{"dt":1589426820,"precipitation":0},{"dt":1589426880,"precipitation":0},{"dt":1589426940,"precipitation":0},{"dt":1589427000,"precipitation":0},{"dt":1589427060,"precipitation":0},{"dt":1589427120,"precipitation":0},{"dt":1589427180,"precipitation":0},{"dt":1589427240,"precipitation":0},{"dt":1589427300,"precipitation":0},{"dt":1589427360,"precipitation":0},{"dt":1589427420,"precipitation":0},{"dt":1589427480,"precipitation":0},{"dt":1589427540,"precipitation":0},{"dt":1589427600,"precipitation":0},{"dt":1589427660,"precipitation":0},{"dt":1589427720,"precipitation":0},{"dt":1589427780,"precipitation":0},{"dt":1589427840,"precipitation":0},{"dt":1589427900,"precipitation":0},{"dt":1589427960,"precipitation":0},{"dt":1589428020,"precipitation":0},{"dt":1589428080,"precipitation":0},{"dt":1589428140,"precipitation":0},{"dt":1589428200,"precipitation":0},{"dt":1589428260,"precipitation":0},{"dt":1589428320,"precipitation":0},{"dt":1589428380,"precipitation":0},{"dt":1589428440,"precipitation":0},{"dt":1589428500,"precipitation":0},{"dt":1589428560,"precipitation":0},{"dt":1589428620,"precipitation":0},{"dt":1589428680,"precipitation":0},{"dt":1589428740,"precipitation":0},{"dt":1589428800,"precipitation":0},{"dt":1589428860,"precipitation":0},{"dt":1589428920,"precipitation":0},{"dt":1589428980,"precipitation":0},{"dt":1589429040,"precipitation":0},{"dt":1589429100,"precipitation":0},{"dt":1589429160,"precipitation":0},{"dt":1589429220,"precipitation":0},{"dt":1589429280,"precipitation":0},{"dt":1589429340,"precipitation":0},{"dt":1589429400,"precipitation":0}],"hourly":[{"dt":1589425200,"temp":295.55,"feels_like":293.69,"pressure":1015,"humidity":64,"dew_point":288.41,"clouds":1,"wind_speed":5.1,"wind_deg":134,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589428800,"temp":294.13,"feels_like":293.31,"pressure":1015,"humidity":78,"dew_point":290.15,"clouds":5,"wind_speed":4.56,"wind_deg":144,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589432400,"temp":292.91,"feels_like":292.73,"pressure":1015,"humidity":87,"dew_point":290.69,"clouds":6,"wind_speed":3.97,"wind_deg":155,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589436000,"temp":291.94,"feels_like":292.1,"pressure":1016,"humidity":94,"dew_point":290.95,"clouds":7,"wind_speed":3.64,"wind_deg":162,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589439600,"temp":291.61,"feels_like":291.6,"pressure":1016,"humidity":95,"dew_point":290.79,"clouds":0,"wind_speed":3.79,"wind_deg":173,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589443200,"temp":291.62,"feels_like":291.45,"pressure":1015,"humidity":94,"dew_point":290.76,"clouds":2,"wind_speed":3.93,"wind_deg":169,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589446800,"temp":291.41,"feels_like":291.8,"pressure":1015,"humidity":95,"dew_point":290.7,"clouds":34,"wind_speed":3.1,"wind_deg":182,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03n"}]},{"dt":1589450400,"temp":291,"feels_like":291.67,"pressure":1015,"humidity":97,"dew_point":290.54,"clouds":51,"wind_speed":2.65,"wind_deg":165,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589454000,"temp":290.8,"feels_like":290.97,"pressure":1015,"humidity":97,"dew_point":290.46,"clouds":52,"wind_speed":3.25,"wind_deg":156,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589457600,"temp":291.14,"feels_like":291.35,"pressure":1015,"humidity":97,"dew_point":290.82,"clouds":60,"wind_speed":3.39,"wind_deg":156,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04d"}]},{"dt":1589461200,"temp":292.99,"feels_like":292.89,"pressure":1016,"humidity":93,"dew_point":291.87,"clouds":100,"wind_speed":4.55,"wind_deg":159,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589464800,"temp":294.7,"feels_like":294.49,"pressure":1016,"humidity":88,"dew_point":292.8,"clouds":100,"wind_speed":5.23,"wind_deg":161,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589468400,"temp":295.66,"feels_like":295.92,"pressure":1016,"humidity":86,"dew_point":293.23,"clouds":100,"wind_speed":4.94,"wind_deg":169,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589472000,"temp":296.04,"feels_like":296.44,"pressure":1016,"humidity":84,"dew_point":293.38,"clouds":100,"wind_speed":4.74,"wind_deg":169,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589475600,"temp":296.63,"feels_like":296.71,"pressure":1016,"humidity":83,"dew_point":293.62,"clouds":100,"wind_speed":5.46,"wind_deg":165,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589479200,"temp":297.63,"feels_like":297.87,"pressure":1015,"humidity":79,"dew_point":293.94,"clouds":100,"wind_speed":5.34,"wind_deg":169,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589482800,"temp":298.45,"feels_like":299.14,"pressure":1015,"humidity":79,"dew_point":294.65,"clouds":72,"wind_speed":5.27,"wind_deg":172,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.35}},{"dt":1589486400,"temp":298.99,"feels_like":299.98,"pressure":1014,"humidity":78,"dew_point":295,"clouds":62,"wind_speed":5.08,"wind_deg":172,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.67}},{"dt":1589490000,"temp":299.9,"feels_like":301.24,"pressure":1013,"humidity":73,"dew_point":294.85,"clouds":44,"wind_speed":4.42,"wind_deg":168,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.2}},{"dt":1589493600,"temp":299.82,"feels_like":301.25,"pressure":1012,"humidity":74,"dew_point":295.01,"clouds":41,"wind_speed":4.4,"wind_deg":171,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.16}},{"dt":1589497200,"temp":299.25,"feels_like":300.7,"pressure":1012,"humidity":77,"dew_point":294.98,"clouds":35,"wind_speed":4.45,"wind_deg":163,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03d"}]},{"dt":1589500800,"temp":298.17,"feels_like":300.39,"pressure":1012,"humidity":83,"dew_point":295.13,"clouds":29,"wind_speed":3.49,"wind_deg":153,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03d"}]},{"dt":1589504400,"temp":296.07,"feels_like":298.12,"pressure":1012,"humidity":90,"dew_point":294.44,"clouds":0,"wind_speed":3.18,"wind_deg":137,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589508000,"temp":294.83,"feels_like":296.14,"pressure":1012,"humidity":93,"dew_point":293.78,"clouds":0,"wind_speed":3.75,"wind_deg":135,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589511600,"temp":294.39,"feels_like":295.42,"pressure":1013,"humidity":94,"dew_point":293.42,"clouds":0,"wind_speed":3.97,"wind_deg":145,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589515200,"temp":294.05,"feels_like":294.96,"pressure":1013,"humidity":93,"dew_point":293.02,"clouds":0,"wind_speed":3.8,"wind_deg":150,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589518800,"temp":293.75,"feels_like":294.6,"pressure":1013,"humidity":94,"dew_point":292.83,"clouds":8,"wind_speed":3.8,"wind_deg":158,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589522400,"temp":293.76,"feels_like":294.38,"pressure":1013,"humidity":93,"dew_point":292.76,"clouds":23,"wind_speed":4.02,"wind_deg":162,"weather":[{"id":801,"main":"Clouds","description":"few + clouds","icon":"02n"}]},{"dt":1589526000,"temp":293.68,"feels_like":294.52,"pressure":1013,"humidity":94,"dew_point":292.73,"clouds":98,"wind_speed":3.76,"wind_deg":174,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04n"}]},{"dt":1589529600,"temp":293.44,"feels_like":294.16,"pressure":1013,"humidity":95,"dew_point":292.69,"clouds":84,"wind_speed":3.89,"wind_deg":172,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589533200,"temp":293.09,"feels_like":293.98,"pressure":1012,"humidity":96,"dew_point":292.54,"clouds":80,"wind_speed":3.53,"wind_deg":172,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589536800,"temp":292.76,"feels_like":293.74,"pressure":1012,"humidity":97,"dew_point":292.41,"clouds":80,"wind_speed":3.3,"wind_deg":170,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589540400,"temp":292.61,"feels_like":293.63,"pressure":1012,"humidity":98,"dew_point":292.31,"clouds":77,"wind_speed":3.25,"wind_deg":174,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]},{"dt":1589544000,"temp":293.02,"feels_like":293.88,"pressure":1013,"humidity":97,"dew_point":292.69,"clouds":73,"wind_speed":3.64,"wind_deg":166,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04d"}]},{"dt":1589547600,"temp":294.49,"feels_like":295.16,"pressure":1013,"humidity":93,"dew_point":293.42,"clouds":84,"wind_speed":4.43,"wind_deg":174,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04d"}]},{"dt":1589551200,"temp":295.09,"feels_like":296.1,"pressure":1014,"humidity":91,"dew_point":293.63,"clouds":92,"wind_speed":4.12,"wind_deg":180,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589554800,"temp":295.59,"feels_like":296.69,"pressure":1014,"humidity":89,"dew_point":293.82,"clouds":94,"wind_speed":4.07,"wind_deg":175,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589558400,"temp":296.25,"feels_like":297.57,"pressure":1015,"humidity":88,"dew_point":294.18,"clouds":96,"wind_speed":4.09,"wind_deg":173,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589562000,"temp":296.9,"feels_like":298.63,"pressure":1015,"humidity":86,"dew_point":294.47,"clouds":97,"wind_speed":3.7,"wind_deg":172,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589565600,"temp":297.07,"feels_like":298.99,"pressure":1014,"humidity":86,"dew_point":294.65,"clouds":98,"wind_speed":3.55,"wind_deg":169,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589569200,"temp":297.55,"feels_like":299.62,"pressure":1013,"humidity":84,"dew_point":294.81,"clouds":100,"wind_speed":3.39,"wind_deg":168,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589572800,"temp":299.4,"feels_like":301.94,"pressure":1012,"humidity":76,"dew_point":294.87,"clouds":100,"wind_speed":2.84,"wind_deg":171,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589576400,"temp":300.79,"feels_like":303.46,"pressure":1012,"humidity":70,"dew_point":294.91,"clouds":99,"wind_speed":2.64,"wind_deg":170,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589580000,"temp":300.91,"feels_like":303.83,"pressure":1011,"humidity":71,"dew_point":295.19,"clouds":99,"wind_speed":2.55,"wind_deg":152,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589583600,"temp":301.01,"feels_like":303.85,"pressure":1011,"humidity":71,"dew_point":295.35,"clouds":97,"wind_speed":2.74,"wind_deg":141,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589587200,"temp":299.64,"feels_like":302.77,"pressure":1010,"humidity":80,"dew_point":295.96,"clouds":91,"wind_speed":2.83,"wind_deg":121,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.11}},{"dt":1589590800,"temp":297.47,"feels_like":299.59,"pressure":1010,"humidity":86,"dew_point":295.11,"clouds":100,"wind_speed":3.56,"wind_deg":112,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"rain":{"1h":0.11}},{"dt":1589594400,"temp":295.95,"feels_like":297.2,"pressure":1010,"humidity":90,"dew_point":294.31,"clouds":83,"wind_speed":4.24,"wind_deg":117,"weather":[{"id":803,"main":"Clouds","description":"broken + clouds","icon":"04n"}]}],"daily":[{"dt":1589392800,"sunrise":1589368621,"sunset":1589418488,"temp":{"day":295.55,"min":293.67,"max":295.55,"night":293.67,"eve":295.55,"morn":295.55},"feels_like":{"day":293.69,"night":293.48,"eve":293.69,"morn":293.69},"pressure":1015,"humidity":64,"dew_point":288.41,"wind_speed":5.1,"wind_deg":134,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}],"clouds":1,"uvi":10.31},{"dt":1589479200,"sunrise":1589454978,"sunset":1589504933,"temp":{"day":297.63,"min":291.42,"max":299.9,"night":293.76,"eve":298.17,"morn":291.42},"feels_like":{"day":297.87,"night":294.38,"eve":300.39,"morn":291.61},"pressure":1015,"humidity":79,"dew_point":293.94,"wind_speed":5.34,"wind_deg":169,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"clouds":100,"rain":1.52,"uvi":9.98},{"dt":1589565600,"sunrise":1589541336,"sunset":1589591378,"temp":{"day":297.07,"min":293.02,"max":300.79,"night":293.8,"eve":299.64,"morn":293.02},"feels_like":{"day":298.99,"night":295.65,"eve":302.77,"morn":293.88},"pressure":1014,"humidity":86,"dew_point":294.65,"wind_speed":3.55,"wind_deg":169,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"clouds":98,"rain":0.58,"uvi":10.53},{"dt":1589652000,"sunrise":1589627695,"sunset":1589677822,"temp":{"day":301.62,"min":292.14,"max":301.62,"night":292.14,"eve":294.72,"morn":293.44},"feels_like":{"day":303.51,"night":294.71,"eve":296.86,"morn":295.29},"pressure":1011,"humidity":64,"dew_point":294.16,"wind_speed":3.27,"wind_deg":166,"weather":[{"id":502,"main":"Rain","description":"heavy + intensity rain","icon":"10d"}],"clouds":96,"rain":16.78,"uvi":10.3},{"dt":1589738400,"sunrise":1589714056,"sunset":1589764267,"temp":{"day":298.29,"min":292.07,"max":298.6,"night":292.4,"eve":296.96,"morn":292.07},"feels_like":{"day":300.64,"night":293.17,"eve":300.43,"morn":293.94},"pressure":1012,"humidity":74,"dew_point":293.36,"wind_speed":2.04,"wind_deg":70,"weather":[{"id":501,"main":"Rain","description":"moderate + rain","icon":"10d"}],"clouds":99,"rain":8.01,"uvi":10.95},{"dt":1589824800,"sunrise":1589800419,"sunset":1589850710,"temp":{"day":298.65,"min":289.07,"max":300.81,"night":289.49,"eve":297.92,"morn":289.07},"feels_like":{"day":298.14,"night":288.35,"eve":298.74,"morn":288.15},"pressure":1015,"humidity":56,"dew_point":289.47,"wind_speed":3.6,"wind_deg":21,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03d"}],"clouds":49,"uvi":10.91},{"dt":1589911200,"sunrise":1589886783,"sunset":1589937154,"temp":{"day":296.27,"min":286.83,"max":298.28,"night":288.9,"eve":297.35,"morn":286.83},"feels_like":{"day":295.57,"night":288.28,"eve":299.19,"morn":286.03},"pressure":1015,"humidity":56,"dew_point":287.09,"wind_speed":2.73,"wind_deg":40,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}],"clouds":0,"uvi":10.01},{"dt":1589997600,"sunrise":1589973148,"sunset":1590023597,"temp":{"day":298.21,"min":287.71,"max":299.71,"night":290.03,"eve":298.59,"morn":287.71},"feels_like":{"day":299.68,"night":289.89,"eve":301.62,"morn":287.74},"pressure":1014,"humidity":61,"dew_point":290.18,"wind_speed":1.3,"wind_deg":71,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}],"clouds":0,"uvi":10.16}]}' + http_version: null + recorded_at: Thu, 14 May 2020 03:09:08 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/open_weather/one_call/lat_lon_exclude_minutely_hourly.yml b/spec/fixtures/open_weather/one_call/lat_lon_exclude_minutely_hourly.yml new file mode 100644 index 0000000..c39472c --- /dev/null +++ b/spec/fixtures/open_weather/one_call/lat_lon_exclude_minutely_hourly.yml @@ -0,0 +1,53 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.openweathermap.org/data/2.5/onecall?appid=api-key&exclude=minutely,hourly&lat=33.441792&lon=-94.037689 + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - OpenWeather Ruby Client/0.2.0 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Server: + - openresty + Date: + - Thu, 14 May 2020 03:38:57 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '3648' + Connection: + - keep-alive + X-Cache-Key: + - "/data/2.5/onecall?exclude=minutely%2Chourly&lat=33.44&lon=-94.04" + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST + body: + encoding: UTF-8 + string: '{"lat":33.44,"lon":-94.04,"timezone":"America/Chicago","current":{"dt":1589427537,"sunrise":1589368621,"sunset":1589418488,"temp":295.03,"feels_like":294.9,"pressure":1015,"humidity":78,"dew_point":291.02,"uvi":10.31,"clouds":1,"visibility":16093,"wind_speed":4.1,"wind_deg":140,"wind_gust":8.2,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},"daily":[{"dt":1589392800,"sunrise":1589368621,"sunset":1589418488,"temp":{"day":295.03,"min":293.4,"max":295.03,"night":293.4,"eve":295.03,"morn":295.03},"feels_like":{"day":294.2,"night":293.65,"eve":294.2,"morn":294.2},"pressure":1015,"humidity":78,"dew_point":291.02,"wind_speed":5.1,"wind_deg":134,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}],"clouds":1,"uvi":10.31},{"dt":1589479200,"sunrise":1589454978,"sunset":1589504933,"temp":{"day":297.63,"min":291.39,"max":299.9,"night":293.76,"eve":298.17,"morn":291.39},"feels_like":{"day":297.87,"night":294.38,"eve":300.39,"morn":291.64},"pressure":1015,"humidity":79,"dew_point":293.94,"wind_speed":5.34,"wind_deg":169,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"clouds":100,"rain":1.52,"uvi":9.98},{"dt":1589565600,"sunrise":1589541336,"sunset":1589591378,"temp":{"day":297.07,"min":293.02,"max":300.79,"night":293.8,"eve":299.64,"morn":293.02},"feels_like":{"day":298.99,"night":295.65,"eve":302.77,"morn":293.88},"pressure":1014,"humidity":86,"dew_point":294.65,"wind_speed":3.55,"wind_deg":169,"weather":[{"id":500,"main":"Rain","description":"light + rain","icon":"10d"}],"clouds":98,"rain":0.58,"uvi":10.53},{"dt":1589652000,"sunrise":1589627695,"sunset":1589677822,"temp":{"day":301.62,"min":292.14,"max":301.62,"night":292.14,"eve":294.72,"morn":293.44},"feels_like":{"day":303.51,"night":294.71,"eve":296.86,"morn":295.29},"pressure":1011,"humidity":64,"dew_point":294.16,"wind_speed":3.27,"wind_deg":166,"weather":[{"id":502,"main":"Rain","description":"heavy + intensity rain","icon":"10d"}],"clouds":96,"rain":16.78,"uvi":10.3},{"dt":1589738400,"sunrise":1589714056,"sunset":1589764267,"temp":{"day":298.29,"min":292.07,"max":298.6,"night":292.4,"eve":296.96,"morn":292.07},"feels_like":{"day":300.64,"night":293.17,"eve":300.43,"morn":293.94},"pressure":1012,"humidity":74,"dew_point":293.36,"wind_speed":2.04,"wind_deg":70,"weather":[{"id":501,"main":"Rain","description":"moderate + rain","icon":"10d"}],"clouds":99,"rain":8.01,"uvi":10.95},{"dt":1589824800,"sunrise":1589800419,"sunset":1589850710,"temp":{"day":298.65,"min":289.07,"max":300.81,"night":289.49,"eve":297.92,"morn":289.07},"feels_like":{"day":298.14,"night":288.35,"eve":298.74,"morn":288.15},"pressure":1015,"humidity":56,"dew_point":289.47,"wind_speed":3.6,"wind_deg":21,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03d"}],"clouds":49,"uvi":10.91},{"dt":1589911200,"sunrise":1589886783,"sunset":1589937154,"temp":{"day":296.27,"min":286.83,"max":298.28,"night":288.9,"eve":297.35,"morn":286.83},"feels_like":{"day":295.57,"night":288.28,"eve":299.19,"morn":286.03},"pressure":1015,"humidity":56,"dew_point":287.09,"wind_speed":2.73,"wind_deg":40,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}],"clouds":0,"uvi":10.01},{"dt":1589997600,"sunrise":1589973148,"sunset":1590023597,"temp":{"day":298.21,"min":287.71,"max":299.71,"night":290.03,"eve":298.59,"morn":287.71},"feels_like":{"day":299.68,"night":289.89,"eve":301.62,"morn":287.74},"pressure":1014,"humidity":61,"dew_point":290.18,"wind_speed":1.3,"wind_deg":71,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}],"clouds":0,"uvi":10.16}]}' + http_version: null + recorded_at: Thu, 14 May 2020 03:38:57 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/open_weather/one_call/lat_lon_yesterday.yml b/spec/fixtures/open_weather/one_call/lat_lon_yesterday.yml new file mode 100644 index 0000000..0929ea0 --- /dev/null +++ b/spec/fixtures/open_weather/one_call/lat_lon_yesterday.yml @@ -0,0 +1,69 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.openweathermap.org/data/2.5/onecall/timemachine?appid=api-key&dt=1589173200&lat=33.441792&lon=-94.037689 + body: + encoding: US-ASCII + string: '' + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - OpenWeather Ruby Client/0.2.0 + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Server: + - openresty + Date: + - Thu, 14 May 2020 03:45:55 GMT + Content-Type: + - application/json; charset=utf-8 + Content-Length: + - '6187' + Connection: + - keep-alive + X-Cache-Key: + - "/data/2.5/onecall/timemachine?dt=1589173200&lat=33.44&lon=-94.04" + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET, POST + body: + encoding: UTF-8 + string: '{"lat":33.44,"lon":-94.04,"timezone":"America/Chicago","current":{"dt":1589173200,"sunrise":1589195911,"sunset":1589245597,"temp":289.54,"feels_like":288.71,"pressure":1023,"humidity":82,"dew_point":286.46,"uvi":9.38,"clouds":20,"visibility":16093,"wind_speed":2.66,"wind_deg":16,"weather":[{"id":801,"main":"Clouds","description":"few + clouds","icon":"02n"}]},"hourly":[{"dt":1589155200,"temp":295.79,"feels_like":294.21,"pressure":1020,"humidity":43,"dew_point":282.59,"clouds":20,"visibility":16093,"wind_speed":2.1,"wind_deg":330,"weather":[{"id":801,"main":"Clouds","description":"few + clouds","icon":"02d"}]},{"dt":1589158800,"temp":294.43,"feels_like":293.79,"pressure":1021,"humidity":53,"dew_point":284.47,"clouds":90,"visibility":16093,"wind_speed":1.5,"wind_deg":330,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589162400,"temp":291.23,"feels_like":291,"pressure":1021,"humidity":77,"dew_point":287.14,"clouds":40,"visibility":16093,"wind_speed":2.13,"wind_deg":333,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03n"}]},{"dt":1589166000,"temp":290.06,"feels_like":289.45,"pressure":1022,"humidity":77,"dew_point":286.01,"clouds":90,"visibility":16093,"wind_speed":2.13,"wind_deg":333,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04n"}]},{"dt":1589169600,"temp":290.03,"feels_like":289.54,"pressure":1023,"humidity":72,"dew_point":284.96,"clouds":1,"visibility":16093,"wind_speed":1.5,"wind_deg":20,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589173200,"temp":289.54,"feels_like":288.71,"pressure":1023,"humidity":82,"dew_point":286.46,"clouds":20,"visibility":16093,"wind_speed":2.66,"wind_deg":16,"weather":[{"id":801,"main":"Clouds","description":"few + clouds","icon":"02n"}]},{"dt":1589176800,"temp":289.13,"feels_like":288.17,"pressure":1023,"humidity":82,"dew_point":286.06,"clouds":1,"visibility":16093,"wind_speed":2.66,"wind_deg":16,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589180400,"temp":288.61,"feels_like":286.55,"pressure":1023,"humidity":59,"dew_point":280.64,"clouds":1,"visibility":16093,"wind_speed":2.1,"wind_deg":40,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589184000,"temp":287.13,"feels_like":285.6,"pressure":1023,"humidity":67,"dew_point":281.11,"clouds":1,"visibility":16093,"wind_speed":1.5,"wind_deg":50,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589187600,"temp":286.9,"feels_like":285.11,"pressure":1023,"humidity":71,"dew_point":281.74,"clouds":1,"visibility":16093,"wind_speed":2.1,"wind_deg":50,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589191200,"temp":286.63,"feels_like":284.17,"pressure":1024,"humidity":66,"dew_point":280.41,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":60,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589194800,"temp":285.63,"feels_like":282.96,"pressure":1024,"humidity":66,"dew_point":279.46,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":60,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01n"}]},{"dt":1589198400,"temp":286.02,"feels_like":284.02,"pressure":1024,"humidity":71,"dew_point":280.9,"clouds":1,"visibility":16093,"wind_speed":2.1,"wind_deg":70,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589202000,"temp":286.91,"feels_like":284.3,"pressure":1025,"humidity":62,"dew_point":279.77,"clouds":90,"visibility":16093,"wind_speed":2.6,"wind_deg":70,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589205600,"temp":289.14,"feels_like":284.9,"pressure":1025,"humidity":44,"dew_point":276.91,"clouds":40,"visibility":16093,"wind_speed":4.1,"wind_deg":70,"wind_gust":9.3,"weather":[{"id":802,"main":"Clouds","description":"scattered + clouds","icon":"03d"}]},{"dt":1589209200,"temp":290.49,"feels_like":287.06,"pressure":1024,"humidity":42,"dew_point":277.47,"clouds":1,"visibility":16093,"wind_speed":3.1,"wind_deg":0,"wind_gust":8.2,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589212800,"temp":291.02,"feels_like":286.78,"pressure":1024,"humidity":39,"dew_point":276.89,"clouds":1,"visibility":16093,"wind_speed":4.1,"wind_deg":90,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589216400,"temp":293.4,"feels_like":290.24,"pressure":1025,"humidity":34,"dew_point":277.05,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":0,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589220000,"temp":294.31,"feels_like":291.73,"pressure":1024,"humidity":35,"dew_point":278.26,"clouds":90,"visibility":16093,"wind_speed":2.1,"wind_deg":0,"weather":[{"id":804,"main":"Clouds","description":"overcast + clouds","icon":"04d"}]},{"dt":1589223600,"temp":294.9,"feels_like":292.25,"pressure":1023,"humidity":37,"dew_point":279.59,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":60,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589227200,"temp":295.26,"feels_like":291.81,"pressure":1022,"humidity":35,"dew_point":279.1,"clouds":1,"visibility":16093,"wind_speed":3.6,"wind_deg":70,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589230800,"temp":295.41,"feels_like":292.86,"pressure":1021,"humidity":37,"dew_point":280.04,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":0,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589234400,"temp":295.43,"feels_like":292.62,"pressure":1021,"humidity":38,"dew_point":280.44,"clouds":1,"visibility":16093,"wind_speed":3.1,"wind_deg":70,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]},{"dt":1589238000,"temp":294.85,"feels_like":292.7,"pressure":1019,"humidity":43,"dew_point":281.74,"clouds":1,"visibility":16093,"wind_speed":2.6,"wind_deg":70,"weather":[{"id":800,"main":"Clear","description":"clear + sky","icon":"01d"}]}]}' + http_version: null + recorded_at: Thu, 14 May 2020 03:45:55 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/open_weather/one_call/one_call_spec.rb b/spec/open_weather/one_call/one_call_spec.rb new file mode 100644 index 0000000..e8935e5 --- /dev/null +++ b/spec/open_weather/one_call/one_call_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'one_call' do + include_context 'API client' + + it 'lat, lon', vcr: { cassette_name: 'one_call/lat_lon' } do + data = client.one_call(lat: 33.441792, lon: -94.037689) + expect(data).to be_a OpenWeather::Models::OneCall::Weather + expect(data.lat).to eq 33.44 + expect(data.lon).to eq(-94.04) + expect(data.timezone).to eq 'America/Chicago' + expect(data.current).to be_a OpenWeather::Models::OneCall::CurrentWeather + expect(data.minutely).to be_a Array + expect(data.minutely.size).to eq 61 + expect(data.minutely.first).to be_a OpenWeather::Models::OneCall::MinutelyWeather + expect(data.minutely.first.precipitation).to eq 0 + expect(data.hourly).to be_a Array + expect(data.hourly.size).to eq 48 + expect(data.hourly.first).to be_a OpenWeather::Models::OneCall::HourlyWeather + expect(data.hourly.first.temp).to eq 295.55 + expect(data.daily).to be_a Array + expect(data.daily.size).to eq 8 + expect(data.daily.first).to be_a OpenWeather::Models::OneCall::DailyWeather + expect(data.daily.first.temp.night).to eq 293.67 + end + + it 'lat, lon, excluding minutely and hourly', vcr: { cassette_name: 'one_call/lat_lon_exclude_minutely_hourly' } do + data = client.one_call(lat: 33.441792, lon: -94.037689, exclude: %w[minutely hourly]) + expect(data).to be_a OpenWeather::Models::OneCall::Weather + expect(data.lat).to eq 33.44 + expect(data.lon).to eq(-94.04) + expect(data.timezone).to eq 'America/Chicago' + expect(data.current).to be_a OpenWeather::Models::OneCall::CurrentWeather + expect(data.minutely).to be nil + expect(data.hourly).to be nil + expect(data.daily).to be_a Array + expect(data.daily.size).to eq 8 + expect(data.daily.first).to be_a OpenWeather::Models::OneCall::DailyWeather + expect(data.daily.first.temp.night).to eq 293.4 + end + + it 'lat, lon, yesterday', vcr: { cassette_name: 'one_call/lat_lon_yesterday' } do + data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.at(1589173200)) + expect(data).to be_a OpenWeather::Models::OneCall::Weather + expect(data.lat).to eq 33.44 + expect(data.lon).to eq(-94.04) + expect(data.timezone).to eq 'America/Chicago' + expect(data.current).to be_a OpenWeather::Models::OneCall::CurrentWeather + expect(data.current.temp).to eq 289.54 + expect(data.hourly).to be_a Array + expect(data.hourly.size).to eq 24 + expect(data.hourly.first).to be_a OpenWeather::Models::OneCall::HourlyWeather + expect(data.hourly.first.temp).to eq 295.79 + expect(data.minutely).to be nil + expect(data.daily).to be nil + end + + it 'raises an out of range error', vcr: { cassette_name: 'one_call/error_out_of_range' } do + expect do + client.one_call( + lat: 33.441792, + lon: -94.037689, + dt: Time.at(1583902800) + ) + end.to raise_error OpenWeather::Errors::Fault, 'requested time is out of allowed range of 5 days back' + end +end