Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added additional VCR responses from openweather that includes all dat… #41

Merged
merged 9 commits into from
Jul 7, 2024
181 changes: 176 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,184 @@
Style/NumericLiterals:
AllCops:
SuggestExtensions: false

Gemspec/RequiredRubyVersion:
Exclude:
- 'open-weather-ruby-client.gemspec'

Naming/FileName:
Exclude:
- 'lib/open-weather-ruby-client.rb'

Gemspec/DevelopmentDependencies:
Enabled: false
Gemspec/RequireMFA:
Enabled: false
Gemspec/DeprecatedAttributeAssignment:
Enabled: true

Style/NumericLiterals:
Enabled: false
Style/ModuleFunction:
Enabled: false

Style/Documentation:
Enabled: false

Metrics:
Enabled: false

inherit_from: .rubocop_todo.yml
Layout/LineContinuationLeadingSpace:
Enabled: true
Layout/LineContinuationSpacing:
Enabled: true
Layout/LineEndStringConcatenationIndentation:
Enabled: true
Layout/SpaceBeforeBrackets:
Enabled: true
Lint/AmbiguousAssignment:
Enabled: true
Lint/AmbiguousOperatorPrecedence:
Enabled: true
Lint/AmbiguousRange:
Enabled: true
Lint/ConstantOverwrittenInRescue:
Enabled: true
Lint/DeprecatedConstants:
Enabled: true
Lint/DuplicateBranch:
Enabled: true
Lint/DuplicateMagicComment:
Enabled: true
Lint/DuplicateRegexpCharacterClassElement:
Enabled: true
Lint/EmptyBlock:
Enabled: true
Lint/EmptyClass:
Enabled: true
Lint/EmptyInPattern:
Enabled: true
Lint/IncompatibleIoSelectWithFiberScheduler:
Enabled: true
Lint/LambdaWithoutLiteralBlock:
Enabled: true
Lint/NoReturnInBeginEndBlocks:
Enabled: true
Lint/NonAtomicFileOperation:
Enabled: true
Lint/NumberedParameterAssignment:
Enabled: true
Lint/OrAssignmentToConstant:
Enabled: true
Lint/RedundantDirGlobSort:
Enabled: true
Lint/RefinementImportMethods:
Enabled: true
Lint/RequireRangeParentheses:
Enabled: true
Lint/RequireRelativeSelfPath:
Enabled: true
Lint/SymbolConversion:
Enabled: true
Lint/ToEnumArguments:
Enabled: true
Lint/TripleQuotes:
Enabled: true
Lint/UnexpectedBlockArity:
Enabled: true
Lint/UnmodifiedReduceAccumulator:
Enabled: true
Lint/UselessRescue:
Enabled: true
Lint/UselessRuby2Keywords:
Enabled: true
Naming/BlockForwarding:
Enabled: true
Security/CompoundHash:
Enabled: true
Security/IoMethods:
Enabled: true
Style/ArgumentsForwarding:
Enabled: true
Style/ArrayIntersect:
Enabled: true
Style/CollectionCompact:
Enabled: true
Style/ComparableClamp:
Enabled: true
Style/ConcatArrayLiterals:
Enabled: true
Style/DirEmpty:
Enabled: true
Style/DocumentDynamicEvalDefinition:
Enabled: true
Style/EmptyHeredoc:
Enabled: true
Style/EndlessMethod:
Enabled: true
Style/EnvHome:
Enabled: true
Style/FetchEnvVar:
Enabled: true
Style/FileEmpty:
Enabled: true
Style/FileRead:
Enabled: true
Style/FileWrite:
Enabled: true
Style/HashConversion:
Enabled: true
Style/HashExcept:
Enabled: true
Style/IfWithBooleanLiteralBranches:
Enabled: true
Style/InPatternThen:
Enabled: true
Style/MagicCommentFormat:
Enabled: true
Style/MapCompactWithConditionalBlock:
Enabled: true
Style/MapToHash:
Enabled: true
Style/MapToSet:
Enabled: true
Style/MinMaxComparison:
Enabled: true
Style/MultilineInPatternThen:
Enabled: true
Style/NegatedIfElseCondition:
Enabled: true
Style/NestedFileDirname:
Enabled: true
Style/NilLambda:
Enabled: true
Style/NumberedParameters:
Enabled: true
Style/NumberedParametersLimit:
Enabled: true
Style/ObjectThen:
Enabled: true
Style/OpenStructUse:
Enabled: true
Style/OperatorMethodCall:
Enabled: true
Style/QuotedSymbols:
Enabled: true
Style/RedundantArgument:
Enabled: true
Style/RedundantConstantBase:
Enabled: true
Style/RedundantDoubleSplatHashBraces:
Enabled: true
Style/RedundantEach:
Enabled: true
Style/RedundantHeredocDelimiterQuotes:
Enabled: true
Style/RedundantInitialize:
Enabled: true
Style/RedundantSelfAssignmentBranch:
Enabled: true
Style/RedundantStringEscape:
Enabled: true
Style/SelectByRegexp:
Enabled: true
Style/StringChars:
Enabled: true
Style/SwapValues:
Enabled: true
44 changes: 0 additions & 44 deletions .rubocop_todo.yml

This file was deleted.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 0.5.1 (Next)

* [#40](https://github.com/dblock/open-weather-ruby-client/pull/40): Fixing rubocop violations and improved .rubocop.yml - [@troya2](https://github.com/troya2).
* [#41](https://github.com/dblock/open-weather-ruby-client/pull/41): Added additional tests for hourly forecast that include all data types - i.e. rain and snow - [@troya2](https://github.com/troya2).
* [#42](https://github.com/dblock/open-weather-ruby-client/pull/42): Added support for the thirty day forecast in the pro 2.5 API - [@troya2](https://github.com/troya2).
* Your contribution here.

### 0.5.0 (2024/07/03)
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o
- [Current and Forecast Weather](#current-and-forecast-weather)
- [Historical Weather](#historical-weather)
- [Hourly Forecast (Pro)](#hourly-forecast-pro)
- [30 Day Forecast (Pro)](#30-day-forecast-pro)
- [Stations](#stations)
- [Register a Station](#register-a-station)
- [List Stations](#list-stations)
Expand Down Expand Up @@ -221,9 +222,10 @@ data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
The [Hourly Forecast API](https://openweathermap.org/api/hourly-forecast) provides hourly weather forecast for 4 days. Note: This API requires a paid api-key from [OpenWeather.org](https://openweathermap.org/full-price#current).

```ruby
data = client.client.hourly(lat: 33.5312, lon: -111.9426) # => OpenWeather::Models::Forecast::Hourly
data = client.client.hourly(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::Hourly

data.cnt # => 96 (number of entries)
data.city # => OpenWeather::Models::Forecast::City
data.list.first # => OpenWeather::Models::Forecast::Forecast
data.list.first.dt # => Time
data.list.first.main # => OpenWeather::Models::Forecast::Main
Expand All @@ -238,6 +240,31 @@ data.list.first.sys # => OpenWeather::Models::Forecast::Sys or nil
data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
```

### 30 Day Forecast (Pro)

The [30 Day Forecast API](https://openweathermap.org/api/forecast30) provides daily weather forecast for 30 days. Note: This API requires a paid api-key from [OpenWeather.org](https://openweathermap.org/full-price#current).

```ruby
data = client.client.forecast(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::ThirtyDay::ThirtyDay

data.cnt # => 30 (number of entries - sometimes this is 29)
data.city # => OpenWeather::Models::Forecast::City
data.list.first # => OpenWeather::Models::Forecast::ThirtyDay::Forecast
data.list.first.dt # => Time - time of data forcasted, UTC
data.list.first.sunrise # => Time - Sunrise time, UTC
data.list.first.sunset # => Time - Sunset time, UTC
data.list.first.temp # => OpenWeather::Models::Forecast::ThirtyDay::Temp
data.list.first.feels_like # => OpenWeather::Models::OneCall::FeelsLike
data.list.first.pressure # => int - Atmospheric pressure on the sea level, hPa
data.list.first.humidity # => int - Humidity, % (e.g. integer 24 means 24% cloudiness)
data.list.first.weather # => Array[OpenWeather::Models::Weather]
data.list.first.speed # => double - Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
data.list.first.deg # => int - Wind direction, degrees (meteorological)
data.list.first.clouds # => int - Cloudiness, % (e.g. integer 78 means 78% cloudiness)
data.list.first.rain # => double or nil - Precipitation volume, mm. Please note that only mm as units of measurement are available for this parameter
data.list.first.snow # => double or nil - Snow volume, mm. Please note that only mm as units of measurement are available for this parameter
```

### Stations

The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
Expand Down
1 change: 1 addition & 0 deletions lib/open_weather/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Client
include Request
include Endpoints::Current
include Endpoints::Hourly
include Endpoints::ThirtyDayForecast
include Endpoints::OneCall
include Endpoints::Stations

Expand Down
1 change: 1 addition & 0 deletions lib/open_weather/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require_relative 'endpoints/one_call'
require_relative 'endpoints/stations'
require_relative 'endpoints/hourly'
require_relative 'endpoints/thirty_day_forecast'
2 changes: 1 addition & 1 deletion lib/open_weather/endpoints/stations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_measurements(options)
private

def validate_id(id)
raise ArgumentError, 'Invalid ID' unless id&.is_a?(String)
raise ArgumentError, 'Invalid ID' unless id.is_a?(String)
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions lib/open_weather/endpoints/thirty_day_forecast.rb
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
2 changes: 1 addition & 1 deletion lib/open_weather/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module OpenWeather
class Logger < ::Logger
def self.logger
@logger ||= begin
logger = new STDOUT
logger = new $stdout
logger.level = Logger::WARN
logger
end
Expand Down
1 change: 1 addition & 0 deletions lib/open_weather/models/forecast.rb
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'
1 change: 1 addition & 0 deletions lib/open_weather/models/forecast/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class City < Model
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
property 'population' # City population
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/models/forecast/forecast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Forecast < Model
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 'pop' # Probability of precipitation. Varies from 0 and 1, where 0 is equal to 0%, 1 is equal to 100%
property 'sys'

def initialize(args = nil, options = {})
Expand Down
5 changes: 5 additions & 0 deletions lib/open_weather/models/forecast/thirty_day.rb
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'
Loading
Loading