open-weather-ruby-client 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +43 -15
- data/lib/open_weather/client.rb +1 -0
- data/lib/open_weather/endpoints/stations.rb +1 -1
- data/lib/open_weather/endpoints/thirty_day_forecast.rb +16 -0
- data/lib/open_weather/endpoints.rb +1 -0
- data/lib/open_weather/logger.rb +1 -1
- data/lib/open_weather/models/forecast/city.rb +1 -0
- data/lib/open_weather/models/forecast/forecast.rb +1 -1
- data/lib/open_weather/models/forecast/thirty_day/forecast.rb +33 -0
- data/lib/open_weather/models/forecast/thirty_day/temp.rb +18 -0
- data/lib/open_weather/models/forecast/thirty_day/thirty_day.rb +26 -0
- data/lib/open_weather/models/forecast/thirty_day.rb +5 -0
- data/lib/open_weather/models/forecast.rb +1 -0
- data/lib/open_weather/models/mixins/temp.rb +2 -2
- data/lib/open_weather/models/one_call/current_weather.rb +3 -1
- data/lib/open_weather/models/one_call/daily_weather.rb +3 -1
- data/lib/open_weather/models/one_call/hourly_weather.rb +3 -1
- data/lib/open_weather/models/one_call/weather.rb +2 -0
- data/lib/open_weather/models/stations/measurement.rb +1 -1
- data/lib/open_weather/version.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c8876fceee8fa7e6f946be1b82161cfbfc8ef8b4aad00497d62b92eade54d63
|
4
|
+
data.tar.gz: 9ca8ab329c506558cde05eb20c33c29c6a88f9b8f74816d560e23afbeb07e270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 319c7c0dd8477f8ba00efae26150a56a390a7ca15e5522a87d46b80896a16356406df8d07a4a9f79969e0008be79850683aa13bc8e29ee62f42b5892594bc0da
|
7
|
+
data.tar.gz: 7b085b56ec87b9f397b83b49946cc4ed91fe52c24797a8b43dd643d3634285da4cf0fd95b46796c17cb98578e75c5d6928be0b1033fd117e50722706f60a9005
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.6.0 (2024/10/19)
|
2
|
+
|
3
|
+
* [#40](https://github.com/dblock/open-weather-ruby-client/pull/40): Fixing rubocop violations and improved .rubocop.yml - [@troya2](https://github.com/troya2).
|
4
|
+
* [#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).
|
5
|
+
* [#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).
|
6
|
+
* [#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).
|
7
|
+
|
1
8
|
### 0.5.0 (2024/07/03)
|
2
9
|
|
3
10
|
* [#25](https://github.com/dblock/open-weather-ruby-client/pull/25): Exposed the national weather alerts response in the One Call API - [@troya2](https://github.com/troya2).
|
data/README.md
CHANGED
@@ -21,6 +21,7 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o
|
|
21
21
|
- [Current and Forecast Weather](#current-and-forecast-weather)
|
22
22
|
- [Historical Weather](#historical-weather)
|
23
23
|
- [Hourly Forecast (Pro)](#hourly-forecast-pro)
|
24
|
+
- [30 Day Forecast (Pro)](#30-day-forecast-pro)
|
24
25
|
- [Stations](#stations)
|
25
26
|
- [Register a Station](#register-a-station)
|
26
27
|
- [List Stations](#list-stations)
|
@@ -192,6 +193,7 @@ data.lat # => 33.44
|
|
192
193
|
data.lon # => -94.04
|
193
194
|
data.timezone # => 'America/Chicago'
|
194
195
|
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
196
|
+
data.data # => Array]OpenWeather::Models::OneCall::CurrentWeather] (on base plan)
|
195
197
|
data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
|
196
198
|
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
197
199
|
data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
|
@@ -218,12 +220,13 @@ data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
|
218
220
|
|
219
221
|
### Hourly Forecast (Pro)
|
220
222
|
|
221
|
-
The [Hourly Forecast API](https://openweathermap.org/api/hourly-forecast) provides hourly weather forecast for 4 days. Note: This API requires a
|
223
|
+
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).
|
222
224
|
|
223
225
|
```ruby
|
224
|
-
data = client.client.hourly(lat: 33.5312, lon: -111.9426) # => OpenWeather::Models::Forecast::Hourly
|
226
|
+
data = client.client.hourly(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::Hourly
|
225
227
|
|
226
228
|
data.cnt # => 96 (number of entries)
|
229
|
+
data.city # => OpenWeather::Models::Forecast::City
|
227
230
|
data.list.first # => OpenWeather::Models::Forecast::Forecast
|
228
231
|
data.list.first.dt # => Time
|
229
232
|
data.list.first.main # => OpenWeather::Models::Forecast::Main
|
@@ -238,6 +241,31 @@ data.list.first.sys # => OpenWeather::Models::Forecast::Sys or nil
|
|
238
241
|
data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
|
239
242
|
```
|
240
243
|
|
244
|
+
### 30 Day Forecast (Pro)
|
245
|
+
|
246
|
+
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).
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
data = client.client.forecast(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::ThirtyDay::ThirtyDay
|
250
|
+
|
251
|
+
data.cnt # => 30 (number of entries - sometimes this is 29)
|
252
|
+
data.city # => OpenWeather::Models::Forecast::City
|
253
|
+
data.list.first # => OpenWeather::Models::Forecast::ThirtyDay::Forecast
|
254
|
+
data.list.first.dt # => Time - time of data forcasted, UTC
|
255
|
+
data.list.first.sunrise # => Time - Sunrise time, UTC
|
256
|
+
data.list.first.sunset # => Time - Sunset time, UTC
|
257
|
+
data.list.first.temp # => OpenWeather::Models::Forecast::ThirtyDay::Temp
|
258
|
+
data.list.first.feels_like # => OpenWeather::Models::OneCall::FeelsLike
|
259
|
+
data.list.first.pressure # => int - Atmospheric pressure on the sea level, hPa
|
260
|
+
data.list.first.humidity # => int - Humidity, % (e.g. integer 24 means 24% cloudiness)
|
261
|
+
data.list.first.weather # => Array[OpenWeather::Models::Weather]
|
262
|
+
data.list.first.speed # => double - Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
263
|
+
data.list.first.deg # => int - Wind direction, degrees (meteorological)
|
264
|
+
data.list.first.clouds # => int - Cloudiness, % (e.g. integer 78 means 78% cloudiness)
|
265
|
+
data.list.first.rain # => double or nil - Precipitation volume, mm. Please note that only mm as units of measurement are available for this parameter
|
266
|
+
data.list.first.snow # => double or nil - Snow volume, mm. Please note that only mm as units of measurement are available for this parameter
|
267
|
+
```
|
268
|
+
|
241
269
|
### Stations
|
242
270
|
|
243
271
|
The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
|
@@ -341,19 +369,19 @@ end
|
|
341
369
|
|
342
370
|
The following settings are supported.
|
343
371
|
|
344
|
-
setting
|
345
|
-
|
346
|
-
api_key
|
347
|
-
lang
|
348
|
-
units
|
349
|
-
endpoint
|
350
|
-
user_agent
|
351
|
-
proxy
|
352
|
-
ca_path
|
353
|
-
ca_file
|
354
|
-
logger
|
355
|
-
timeout
|
356
|
-
open_timeout
|
372
|
+
| setting | description |
|
373
|
+
| ------------ | ---------------------------------------------------------- |
|
374
|
+
| api_key | Required API key. |
|
375
|
+
| lang | Default language in API responses. |
|
376
|
+
| units | Default units in API responses. |
|
377
|
+
| endpoint | Defaults to `https://api.openweathermap.org/data`. |
|
378
|
+
| user_agent | User-agent, defaults to _OpenWeather Ruby Client/version_. |
|
379
|
+
| proxy | Optional HTTP proxy. |
|
380
|
+
| ca_path | Optional SSL certificates path. |
|
381
|
+
| ca_file | Optional SSL certificates file. |
|
382
|
+
| logger | Optional `Logger` instance that logs HTTP requests. |
|
383
|
+
| timeout | Optional open/read timeout in seconds. |
|
384
|
+
| open_timeout | Optional connection open timeout in seconds. |
|
357
385
|
|
358
386
|
### Units
|
359
387
|
|
data/lib/open_weather/client.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Endpoints
|
5
|
+
module ThirtyDayForecast
|
6
|
+
def thirty_day_forecast(lat, lon = nil, options = {})
|
7
|
+
# default to the pro endpoint if not specified
|
8
|
+
endpoint = options.delete(:endpoint) || pro_endpoint
|
9
|
+
options = options.merge(endpoint: endpoint)
|
10
|
+
|
11
|
+
options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon)
|
12
|
+
OpenWeather::Models::Forecast::ThirtyDay::ThirtyDay.new(get('2.5/forecast/climate', options), options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/open_weather/logger.rb
CHANGED
@@ -11,6 +11,7 @@ module OpenWeather
|
|
11
11
|
property 'timezone' # shift in seconds from UTC
|
12
12
|
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # Sunrise time, UTC
|
13
13
|
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # Sunset time, UTC
|
14
|
+
property 'population' # City population
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -13,7 +13,7 @@ module OpenWeather
|
|
13
13
|
property 'rain'
|
14
14
|
property 'snow'
|
15
15
|
property 'visibility' # Average visibility, metres. The maximum value of the visibility is 10km
|
16
|
-
property 'pop' # Probability of precipitation.
|
16
|
+
property 'pop' # Probability of precipitation. Varies from 0 and 1, where 0 is equal to 0%, 1 is equal to 100%
|
17
17
|
property 'sys'
|
18
18
|
|
19
19
|
def initialize(args = nil, options = {})
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
module ThirtyDay
|
7
|
+
class Forecast < Model
|
8
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data forcasted, UTC
|
9
|
+
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # Sunrise time, UTC
|
10
|
+
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # Sunset time, UTC
|
11
|
+
property 'temp' # Array of OpenWeather::Models::Forecast::ThityDay::Temp
|
12
|
+
property 'feels_like' # OpenWeather::Models::OneCall::FeelsLike
|
13
|
+
property 'pressure' # Atmospheric pressure on the sea level, hPa
|
14
|
+
property 'humidity' # Humidity, % (e.g. integer 24 means 24% cloudiness)
|
15
|
+
property 'weather' # Array of OpenWeather::Models::Weather
|
16
|
+
property 'speed' # Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
17
|
+
property 'deg' # Wind direction, degrees (meteorological)
|
18
|
+
property 'clouds' # Cloudiness, % (e.g. integer 78 means 78% cloudiness)
|
19
|
+
property 'rain' # Precipitation volume, mm. Unit will only be in mm
|
20
|
+
property 'snow' # Snow volume, mm. Unit will only be in mm
|
21
|
+
|
22
|
+
def initialize(args = nil, options = {})
|
23
|
+
super args, options
|
24
|
+
|
25
|
+
self.temp = Temp.new(temp, options) if temp
|
26
|
+
self.feels_like = OpenWeather::Models::OneCall::FeelsLike.new(feels_like, options) if feels_like
|
27
|
+
self.weather = weather.map { |w| OpenWeather::Models::Weather.new(w, options) } if weather
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
module ThirtyDay
|
7
|
+
class Temp < Model
|
8
|
+
temperature_property 'day' # Day temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
9
|
+
temperature_property 'min' # Min daily temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
10
|
+
temperature_property 'max' # Max daily temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
11
|
+
temperature_property 'night' # Night temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
12
|
+
temperature_property 'eve' # Evening temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
13
|
+
temperature_property 'morn' # Morning temperature. Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
module ThirtyDay
|
7
|
+
class ThirtyDay < Model
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
property 'cod' # Internal parameter
|
11
|
+
property 'message' # Internal parameter
|
12
|
+
property 'city'
|
13
|
+
property 'cnt' # Number of items in list
|
14
|
+
property 'list' # List of ??? objects
|
15
|
+
|
16
|
+
def initialize(args = nil, options = {})
|
17
|
+
super args, options
|
18
|
+
|
19
|
+
self.list = list.map { |forecast| Forecast.new(forecast, options) } if list
|
20
|
+
self.city = OpenWeather::Models::Forecast::City.new(city, options) if city
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -31,7 +31,7 @@ module OpenWeather
|
|
31
31
|
when :metric
|
32
32
|
(value.to_f + 273.15).round(2)
|
33
33
|
when :imperial
|
34
|
-
((value.to_f - 32) * 5 / 9 + 273.15).round(2)
|
34
|
+
(((value.to_f - 32) * 5 / 9) + 273.15).round(2)
|
35
35
|
else
|
36
36
|
value
|
37
37
|
end
|
@@ -55,7 +55,7 @@ module OpenWeather
|
|
55
55
|
when :imperial
|
56
56
|
value
|
57
57
|
else
|
58
|
-
((value.to_f - 273.15) * 9 / 5 + 32).round(2)
|
58
|
+
(((value.to_f - 273.15) * 9 / 5) + 32).round(2)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -11,7 +11,9 @@ module OpenWeather
|
|
11
11
|
temperature_property 'feels_like' # temperature, accounts for the human perception of weather
|
12
12
|
property 'pressure' # atmospheric pressure on the sea level, hPa
|
13
13
|
property 'humidity' # humidity, %
|
14
|
-
|
14
|
+
# atmospheric temperature (varying according to pressure and humidity)
|
15
|
+
# below which water droplets begin to condense and dew can form
|
16
|
+
temperature_property 'dew_point'
|
15
17
|
property 'clouds' # cloudiness, %
|
16
18
|
property 'uvi' # UV index
|
17
19
|
property 'visibility' # average visibility, meters
|
@@ -11,7 +11,9 @@ module OpenWeather
|
|
11
11
|
property 'feels_like'
|
12
12
|
property 'pressure' # atmospheric pressure on the sea level, hPa
|
13
13
|
property 'humidity' # humidity, %
|
14
|
-
|
14
|
+
# atmospheric temperature (varying according to pressure and humidity)
|
15
|
+
# below which water droplets begin to condense and dew can form
|
16
|
+
temperature_property 'dew_point'
|
15
17
|
speed_property 'wind_speed' # wind speed
|
16
18
|
speed_property 'wind_gust' # wind gust
|
17
19
|
property 'wind_deg' # wind direction, degrees (meteorological)
|
@@ -9,7 +9,9 @@ module OpenWeather
|
|
9
9
|
temperature_property 'feels_like'
|
10
10
|
property 'pressure' # atmospheric pressure on the sea level, hPa
|
11
11
|
property 'humidity' # humidity, %
|
12
|
-
|
12
|
+
# atmospheric temperature (varying according to pressure and humidity)
|
13
|
+
# below which water droplets begin to condense and dew can form
|
14
|
+
temperature_property 'dew_point'
|
13
15
|
property 'clouds' # cloudiness, %
|
14
16
|
property 'visibility' # average visibility, meters
|
15
17
|
speed_property 'wind_speed' # wind speed.
|
@@ -12,11 +12,13 @@ module OpenWeather
|
|
12
12
|
property 'hourly' # hourly forecast weather
|
13
13
|
property 'daily' # daily forecast weather
|
14
14
|
property 'alerts' # weather alerts for the location
|
15
|
+
property 'data' # weather data
|
15
16
|
|
16
17
|
def initialize(args = nil, options = {})
|
17
18
|
super args, options
|
18
19
|
|
19
20
|
self.current = OpenWeather::Models::OneCall::CurrentWeather.new(current, options) if current
|
21
|
+
self.data = data.map { |i| OpenWeather::Models::OneCall::CurrentWeather.new(i, options) } if data
|
20
22
|
self.minutely = minutely.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i, options) } if minutely
|
21
23
|
self.hourly = hourly.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i, options) } if hourly
|
22
24
|
self.daily = daily.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i, options) } if daily
|
@@ -5,7 +5,7 @@ module OpenWeather
|
|
5
5
|
module Stations
|
6
6
|
class Measurement < Model
|
7
7
|
property 'station_id' # The internal ID of the station
|
8
|
-
property 'type' # Type of the aggregated data - minute, hour or day
|
8
|
+
property 'type' # Type of the aggregated data - minute, hour or day - the letters m, h or d respectively
|
9
9
|
property 'date' # Time of measurement
|
10
10
|
property 'temp'
|
11
11
|
property 'humidity'
|
data/lib/open_weather/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-weather-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- lib/open_weather/endpoints/hourly.rb
|
211
211
|
- lib/open_weather/endpoints/one_call.rb
|
212
212
|
- lib/open_weather/endpoints/stations.rb
|
213
|
+
- lib/open_weather/endpoints/thirty_day_forecast.rb
|
213
214
|
- lib/open_weather/errors.rb
|
214
215
|
- lib/open_weather/errors/fault.rb
|
215
216
|
- lib/open_weather/logger.rb
|
@@ -222,6 +223,10 @@ files:
|
|
222
223
|
- lib/open_weather/models/forecast/city.rb
|
223
224
|
- lib/open_weather/models/forecast/forecast.rb
|
224
225
|
- lib/open_weather/models/forecast/hourly.rb
|
226
|
+
- lib/open_weather/models/forecast/thirty_day.rb
|
227
|
+
- lib/open_weather/models/forecast/thirty_day/forecast.rb
|
228
|
+
- lib/open_weather/models/forecast/thirty_day/temp.rb
|
229
|
+
- lib/open_weather/models/forecast/thirty_day/thirty_day.rb
|
225
230
|
- lib/open_weather/models/list.rb
|
226
231
|
- lib/open_weather/models/main.rb
|
227
232
|
- lib/open_weather/models/mixins.rb
|
@@ -270,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
275
|
- !ruby/object:Gem::Version
|
271
276
|
version: 1.3.6
|
272
277
|
requirements: []
|
273
|
-
rubygems_version: 3.
|
278
|
+
rubygems_version: 3.3.7
|
274
279
|
signing_key:
|
275
280
|
specification_version: 4
|
276
281
|
summary: OpenWeather API Ruby client.
|