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 ce8e0c4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
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
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 ce8e0c4

Please sign in to comment.