open-weather-ruby-client 0.4.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 +13 -0
- data/README.md +81 -16
- data/lib/open_weather/client.rb +2 -0
- data/lib/open_weather/config.rb +2 -0
- data/lib/open_weather/endpoints/hourly.rb +16 -0
- data/lib/open_weather/endpoints/one_call.rb +1 -1
- 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 +2 -0
- data/lib/open_weather/logger.rb +1 -1
- data/lib/open_weather/models/forecast/city.rb +18 -0
- data/lib/open_weather/models/forecast/forecast.rb +33 -0
- data/lib/open_weather/models/forecast/hourly.rb +25 -0
- 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 +6 -0
- data/lib/open_weather/models/mixins/temp.rb +2 -2
- data/lib/open_weather/models/one_call/alert.rb +15 -0
- data/lib/open_weather/models/one_call/current_weather.rb +3 -1
- data/lib/open_weather/models/one_call/daily_weather.rb +4 -1
- data/lib/open_weather/models/one_call/hourly_weather.rb +3 -1
- data/lib/open_weather/models/one_call/weather.rb +4 -0
- data/lib/open_weather/models/one_call.rb +1 -0
- data/lib/open_weather/models/stations/measurement.rb +1 -1
- data/lib/open_weather/models.rb +1 -0
- data/lib/open_weather/version.rb +1 -1
- metadata +13 -2
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,16 @@
|
|
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
|
+
|
8
|
+
### 0.5.0 (2024/07/03)
|
9
|
+
|
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).
|
11
|
+
* [#38](https://github.com/dblock/open-weather-ruby-client/pull/38): Migrated to One Call 3.0 API - [@jeanmartin](https://github.com/jeanmartin).
|
12
|
+
* [#39](https://github.com/dblock/open-weather-ruby-client/pull/39): Added support for the hourly forecast in the pro 2.5 API - [@troya2](https://github.com/troya2).
|
13
|
+
|
1
14
|
### 0.4.0 (2023/08/13)
|
2
15
|
|
3
16
|
* [#33](https://github.com/dblock/open-weather-ruby-client/pull/33): Upgrade Faraday to 2.x - [@dgarwood](https://github.com/dgarwood).
|
data/README.md
CHANGED
@@ -20,6 +20,8 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o
|
|
20
20
|
- [One Call](#one-call)
|
21
21
|
- [Current and Forecast Weather](#current-and-forecast-weather)
|
22
22
|
- [Historical Weather](#historical-weather)
|
23
|
+
- [Hourly Forecast (Pro)](#hourly-forecast-pro)
|
24
|
+
- [30 Day Forecast (Pro)](#30-day-forecast-pro)
|
23
25
|
- [Stations](#stations)
|
24
26
|
- [Register a Station](#register-a-station)
|
25
27
|
- [List Stations](#list-stations)
|
@@ -87,10 +89,21 @@ data.main.temp # => 12
|
|
87
89
|
```
|
88
90
|
|
89
91
|
Returns weather by city, optional state (in the US) and optional ISO 3166 country code.
|
92
|
+
Names that cannot be resolved will cause the API call to raise a `Faraday::ResourceNotFound` error.
|
90
93
|
|
91
94
|
```ruby
|
92
|
-
client.current_city('
|
93
|
-
client.
|
95
|
+
client.current_city('Sydney')
|
96
|
+
client.current_city('London, UK')
|
97
|
+
client.current_city('London', 'UK')
|
98
|
+
client.current_city('Albany')
|
99
|
+
client.current_city('Albany, New York')
|
100
|
+
client.current_city('Albany, New York', 'US')
|
101
|
+
client.current_city('Albany, NY', 'US')
|
102
|
+
client.current_city('Albany', 'New York', 'US')
|
103
|
+
client.current_city('Albany', 'NY', 'US')
|
104
|
+
client.current_city('Albany', 'NY') # 2-letter state abbreviation w/o country will raise Faraday::ResourceNotFound
|
105
|
+
|
106
|
+
client.current_weather(city: 'Albany', state: 'NY', country: 'US')
|
94
107
|
```
|
95
108
|
|
96
109
|
Returns weather by city ID.
|
@@ -167,7 +180,7 @@ data.main.temp # => 285.15
|
|
167
180
|
|
168
181
|
### One Call
|
169
182
|
|
170
|
-
[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,
|
183
|
+
[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, historical weather data for 5 previous days for any geographical coordinate, and national weather alerts.
|
171
184
|
|
172
185
|
See [OpenWeather::Models::OneCall](lib/open_weather/models/one_call) for all available models and properties.
|
173
186
|
|
@@ -175,13 +188,16 @@ See [OpenWeather::Models::OneCall](lib/open_weather/models/one_call) for all ava
|
|
175
188
|
|
176
189
|
```ruby
|
177
190
|
data = client.one_call(lat: 33.441792, lon: -94.037689) # => OpenWeather::Models::OneCall::Weather
|
191
|
+
|
178
192
|
data.lat # => 33.44
|
179
193
|
data.lon # => -94.04
|
180
194
|
data.timezone # => 'America/Chicago'
|
181
195
|
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
196
|
+
data.data # => Array]OpenWeather::Models::OneCall::CurrentWeather] (on base plan)
|
182
197
|
data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
|
183
198
|
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
184
199
|
data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
|
200
|
+
data.alerts # => Array[OpenWeather::Models::OneCall::Alert]
|
185
201
|
```
|
186
202
|
|
187
203
|
Exclude minutely and hourly data.
|
@@ -194,6 +210,7 @@ client.one_call(lat: 33.441792, lon: -94.037689, exclude: ['minutely', 'hourly']
|
|
194
210
|
|
195
211
|
```ruby
|
196
212
|
data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.now - 24 * 60 * 60) # => OpenWeather::Models::OneCall::Weather
|
213
|
+
|
197
214
|
data.lat # => 33.44
|
198
215
|
data.lon # => -94.04
|
199
216
|
data.timezone # => 'America/Chicago'
|
@@ -201,6 +218,54 @@ data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
|
201
218
|
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
202
219
|
```
|
203
220
|
|
221
|
+
### Hourly Forecast (Pro)
|
222
|
+
|
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).
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
data = client.client.hourly(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::Hourly
|
227
|
+
|
228
|
+
data.cnt # => 96 (number of entries)
|
229
|
+
data.city # => OpenWeather::Models::Forecast::City
|
230
|
+
data.list.first # => OpenWeather::Models::Forecast::Forecast
|
231
|
+
data.list.first.dt # => Time
|
232
|
+
data.list.first.main # => OpenWeather::Models::Forecast::Main
|
233
|
+
data.list.first.weather # => Array[OpenWeather::Models::Forecast::Weather]
|
234
|
+
data.list.first.clouds # => OpenWeather::Models::Forecast::Clouds or nil
|
235
|
+
data.list.first.wind # => OpenWeather::Models::Forecast::Wind or nil
|
236
|
+
data.list.first.visibility # => 10000
|
237
|
+
data.list.first.pop # => 0.1 (probability of precipitation from 0.0 to 1.0 (0% to 100%))
|
238
|
+
data.list.first.rain # => OpenWeather::Models::Forecast::Rain or nil
|
239
|
+
data.list.first.snow # => OpenWeather::Models::Forecast::Snow or nil
|
240
|
+
data.list.first.sys # => OpenWeather::Models::Forecast::Sys or nil
|
241
|
+
data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
|
242
|
+
```
|
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
|
+
|
204
269
|
### Stations
|
205
270
|
|
206
271
|
The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
|
@@ -304,19 +369,19 @@ end
|
|
304
369
|
|
305
370
|
The following settings are supported.
|
306
371
|
|
307
|
-
setting
|
308
|
-
|
309
|
-
api_key
|
310
|
-
lang
|
311
|
-
units
|
312
|
-
endpoint
|
313
|
-
user_agent
|
314
|
-
proxy
|
315
|
-
ca_path
|
316
|
-
ca_file
|
317
|
-
logger
|
318
|
-
timeout
|
319
|
-
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. |
|
320
385
|
|
321
386
|
### Units
|
322
387
|
|
data/lib/open_weather/client.rb
CHANGED
data/lib/open_weather/config.rb
CHANGED
@@ -6,6 +6,7 @@ module OpenWeather
|
|
6
6
|
|
7
7
|
ATTRIBUTES = %i[
|
8
8
|
endpoint
|
9
|
+
pro_endpoint
|
9
10
|
api_key
|
10
11
|
proxy
|
11
12
|
user_agent
|
@@ -22,6 +23,7 @@ module OpenWeather
|
|
22
23
|
|
23
24
|
def reset
|
24
25
|
self.endpoint = 'https://api.openweathermap.org/data'
|
26
|
+
self.pro_endpoint = 'https://pro.openweathermap.org/data'
|
25
27
|
self.api_key = nil
|
26
28
|
self.user_agent = "OpenWeather Ruby Client/#{OpenWeather::VERSION}"
|
27
29
|
self.ca_path = nil
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Endpoints
|
5
|
+
module Hourly
|
6
|
+
def hourly(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::Hourly.new(get('2.5/forecast/hourly', options), options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -7,7 +7,7 @@ module OpenWeather
|
|
7
7
|
options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon)
|
8
8
|
options[:exclude] = options[:exclude].join(',') if options[:exclude].is_a?(Array)
|
9
9
|
options[:dt] = options[:dt].to_i if options[:dt].is_a?(Time)
|
10
|
-
path = options.key?(:dt) ? '
|
10
|
+
path = options.key?(:dt) ? '3.0/onecall/timemachine' : '3.0/onecall'
|
11
11
|
OpenWeather::Models::OneCall::Weather.new(get(path, options), options)
|
12
12
|
end
|
13
13
|
end
|
@@ -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
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
class City < Model
|
7
|
+
property 'id' # City ID
|
8
|
+
property 'name' # City name
|
9
|
+
property 'coord', transform_with: ->(v) { OpenWeather::Models::Coord.new(v) } # City geo location
|
10
|
+
property 'country' # Country code (GB, JP etc.).
|
11
|
+
property 'timezone' # shift in seconds from UTC
|
12
|
+
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # Sunrise time, UTC
|
13
|
+
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # Sunset time, UTC
|
14
|
+
property 'population' # City population
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
class Forecast < Model
|
7
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data forcasted, UTC
|
8
|
+
property 'dt_txt' # Time of data forecasted, ISO, UTC
|
9
|
+
property 'main'
|
10
|
+
property 'weather'
|
11
|
+
property 'clouds'
|
12
|
+
property 'wind'
|
13
|
+
property 'rain'
|
14
|
+
property 'snow'
|
15
|
+
property 'visibility' # Average visibility, metres. The maximum value of the visibility is 10km
|
16
|
+
property 'pop' # Probability of precipitation. Varies from 0 and 1, where 0 is equal to 0%, 1 is equal to 100%
|
17
|
+
property 'sys'
|
18
|
+
|
19
|
+
def initialize(args = nil, options = {})
|
20
|
+
super args, options
|
21
|
+
|
22
|
+
self.main = OpenWeather::Models::Main.new(main, options) if main
|
23
|
+
self.weather = weather.map { |w| OpenWeather::Models::Weather.new(w, options) } if weather
|
24
|
+
self.clouds = OpenWeather::Models::Clouds.new(clouds, options) if clouds
|
25
|
+
self.wind = OpenWeather::Models::Wind.new(wind, options) if wind
|
26
|
+
self.rain = OpenWeather::Models::Rain.new(rain, options) if rain
|
27
|
+
self.snow = OpenWeather::Models::Snow.new(snow, options) if snow
|
28
|
+
self.sys = OpenWeather::Models::Sys.new(sys, options) if sys
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Forecast
|
6
|
+
class Hourly < Model
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
property 'cod'
|
10
|
+
property 'calctime'
|
11
|
+
property 'cnt', from: 'count'
|
12
|
+
property 'list'
|
13
|
+
property 'message'
|
14
|
+
property 'city'
|
15
|
+
|
16
|
+
def initialize(args = nil, options = {})
|
17
|
+
super args, options
|
18
|
+
|
19
|
+
self.list = list.map { |forecast| OpenWeather::Models::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
|
@@ -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
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class Alert < Model
|
7
|
+
property 'sender_name'
|
8
|
+
property 'event'
|
9
|
+
property 'start', transform_with: ->(v) { Time.at(v).utc } # UTC
|
10
|
+
property 'end', transform_with: ->(v) { Time.at(v).utc } # UTC
|
11
|
+
property 'description'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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)
|
@@ -20,6 +22,7 @@ module OpenWeather
|
|
20
22
|
property 'rain' # precipitation volume, mm
|
21
23
|
property 'snow' # snow volume, mm
|
22
24
|
property 'weather'
|
25
|
+
property 'summary'
|
23
26
|
|
24
27
|
def initialize(args = nil, options = {})
|
25
28
|
super args, options
|
@@ -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.
|
@@ -11,14 +11,18 @@ module OpenWeather
|
|
11
11
|
property 'minutely' # minute forecast weather
|
12
12
|
property 'hourly' # hourly forecast weather
|
13
13
|
property 'daily' # daily forecast weather
|
14
|
+
property 'alerts' # weather alerts for the location
|
15
|
+
property 'data' # weather data
|
14
16
|
|
15
17
|
def initialize(args = nil, options = {})
|
16
18
|
super args, options
|
17
19
|
|
18
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
|
19
22
|
self.minutely = minutely.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i, options) } if minutely
|
20
23
|
self.hourly = hourly.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i, options) } if hourly
|
21
24
|
self.daily = daily.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i, options) } if daily
|
25
|
+
self.alerts = alerts.map { |i| OpenWeather::Models::OneCall::Alert.new(i, options) } if alerts
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -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/models.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative 'models/snow'
|
|
13
13
|
require_relative 'models/list'
|
14
14
|
require_relative 'models/city'
|
15
15
|
require_relative 'models/one_call'
|
16
|
+
require_relative 'models/forecast'
|
16
17
|
require_relative 'models/station'
|
17
18
|
require_relative 'models/stations/measurement'
|
18
19
|
require_relative 'models/stations/temp'
|
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:
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -207,8 +207,10 @@ files:
|
|
207
207
|
- lib/open_weather/connection.rb
|
208
208
|
- lib/open_weather/endpoints.rb
|
209
209
|
- lib/open_weather/endpoints/current.rb
|
210
|
+
- lib/open_weather/endpoints/hourly.rb
|
210
211
|
- lib/open_weather/endpoints/one_call.rb
|
211
212
|
- lib/open_weather/endpoints/stations.rb
|
213
|
+
- lib/open_weather/endpoints/thirty_day_forecast.rb
|
212
214
|
- lib/open_weather/errors.rb
|
213
215
|
- lib/open_weather/errors/fault.rb
|
214
216
|
- lib/open_weather/logger.rb
|
@@ -217,6 +219,14 @@ files:
|
|
217
219
|
- lib/open_weather/models/city/weather.rb
|
218
220
|
- lib/open_weather/models/clouds.rb
|
219
221
|
- lib/open_weather/models/coord.rb
|
222
|
+
- lib/open_weather/models/forecast.rb
|
223
|
+
- lib/open_weather/models/forecast/city.rb
|
224
|
+
- lib/open_weather/models/forecast/forecast.rb
|
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
|
220
230
|
- lib/open_weather/models/list.rb
|
221
231
|
- lib/open_weather/models/main.rb
|
222
232
|
- lib/open_weather/models/mixins.rb
|
@@ -224,6 +234,7 @@ files:
|
|
224
234
|
- lib/open_weather/models/mixins/temp.rb
|
225
235
|
- lib/open_weather/models/model.rb
|
226
236
|
- lib/open_weather/models/one_call.rb
|
237
|
+
- lib/open_weather/models/one_call/alert.rb
|
227
238
|
- lib/open_weather/models/one_call/current_weather.rb
|
228
239
|
- lib/open_weather/models/one_call/daily_weather.rb
|
229
240
|
- lib/open_weather/models/one_call/feels_like.rb
|