Skip to content

Commit

Permalink
Add support for base plan one_call API.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Oct 19, 2024
1 parent 9e64384 commit 8b69c1f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
### 0.5.1 (Next)
### 0.6.0 (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).
* [#45](https://github.com/dblock/open-weather-ruby-client/pull/45): Added support for One Call 3.0 API on base plan - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.5.0 (2024/07/03)
Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ data.lat # => 33.44
data.lon # => -94.04
data.timezone # => 'America/Chicago'
data.current # => OpenWeather::Models::OneCall::CurrentWeather
data.data # => Array]OpenWeather::Models::OneCall::CurrentWeather] (on base plan)
data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
Expand Down Expand Up @@ -368,19 +369,19 @@ end

The following settings are supported.

setting | description
--------------------|------------
api_key | Required API key.
lang | Default language in API responses.
units | Default units in API responses.
endpoint | Defaults to `https://api.openweathermap.org/data`.
user_agent | User-agent, defaults to _OpenWeather Ruby Client/version_.
proxy | Optional HTTP proxy.
ca_path | Optional SSL certificates path.
ca_file | Optional SSL certificates file.
logger | Optional `Logger` instance that logs HTTP requests.
timeout | Optional open/read timeout in seconds.
open_timeout | Optional connection open timeout in seconds.
| setting | description |
| ------------ | ---------------------------------------------------------- |
| api_key | Required API key. |
| lang | Default language in API responses. |
| units | Default units in API responses. |
| endpoint | Defaults to `https://api.openweathermap.org/data`. |
| user_agent | User-agent, defaults to _OpenWeather Ruby Client/version_. |
| proxy | Optional HTTP proxy. |
| ca_path | Optional SSL certificates path. |
| ca_file | Optional SSL certificates file. |
| logger | Optional `Logger` instance that logs HTTP requests. |
| timeout | Optional open/read timeout in seconds. |
| open_timeout | Optional connection open timeout in seconds. |

### Units

Expand Down
2 changes: 2 additions & 0 deletions lib/open_weather/models/one_call/weather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class Weather < Model
property 'hourly' # hourly forecast weather
property 'daily' # daily forecast weather
property 'alerts' # weather alerts for the location
property 'data' # weather data

def initialize(args = nil, options = {})
super args, options

self.current = OpenWeather::Models::OneCall::CurrentWeather.new(current, options) if current
self.data = data.map { |i| OpenWeather::Models::OneCall::CurrentWeather.new(i, options) } if data
self.minutely = minutely.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i, options) } if minutely
self.hourly = hourly.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i, options) } if hourly
self.daily = daily.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i, options) } if daily
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OpenWeather
VERSION = '0.5.0'
VERSION = '0.6.0'
end
46 changes: 46 additions & 0 deletions spec/fixtures/open_weather/one_call/base_plan.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions spec/open_weather/one_call/one_call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@
expect(data.daily).to be nil
end

it 'base plan', vcr: { cassette_name: 'one_call/base_plan' } 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.4418
expect(data.lon).to eq(-94.0377)
expect(data.timezone).to eq 'America/Chicago'
expect(data.data).to be_a Array
expect(data.data.size).to eq 1
expect(data.data.first).to be_a OpenWeather::Models::OneCall::CurrentWeather
expect(data.data.first.temp).to eq 289.88
expect(data.data.first.temp_c).to eq 16.73
expect(data.data.first.temp_k).to eq 289.88
expect(data.data.first.temp_f).to eq 62.11
end

it 'raises an out of range error', vcr: { cassette_name: 'one_call/error_out_of_range' } do
expect do
client.one_call(
Expand Down

0 comments on commit 8b69c1f

Please sign in to comment.