open-weather-ruby-client 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6f08b9b57fd352c8ad1733b4b25f9bb261d015a226fa40da66f506772824452
4
- data.tar.gz: eb4e97da6efd6dacac6c827c42039de81cb9aa399511cb8d5736131dc6a7ba53
3
+ metadata.gz: 50db5335dc75a5a05dceb8c71b9de5a46b325e15f3a4a7a61ea04e7667be4937
4
+ data.tar.gz: f0666d4eab1829d74d4a76c0ea484e8b555199ffdbfd6684f0dd259587e2f930
5
5
  SHA512:
6
- metadata.gz: 0a842f0686f6886c2d7c17e214adfa1834c7f7b4d497950a00a1e372f97b394e3ced599f14a219246b93367c472f609bbf930feb42721555187dfd86554cd1c4
7
- data.tar.gz: 05dbb02fa61d7d30aa1bdd4cd538725dd3b46f19f63a48963b63a3576c2320ae9f816a22b5fc8d6fd5ad2ae22387a09a0573657f2ebfdbad9fa8755164a72de5
6
+ metadata.gz: d6cb7dc0addc30dbc76108b055ac1a36dcc5b9d91049af28ce8ee3c5e046c19a0431218ce037f2f7d1be550ae06c7faddf8ff33073a924b767d6ac4edcaed158
7
+ data.tar.gz: 818a28e582b0f359ce1005fcc0fead12135a2f0b1c8f0d2cd8a46dbebf11e66901937a351b09ce66589d9f98525a53cdc3c476a164e1f8ab98a259f183f2e68c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.5.0 (2024/07/03)
2
+
3
+ * [#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).
4
+ * [#38](https://github.com/dblock/open-weather-ruby-client/pull/38): Migrated to One Call 3.0 API - [@jeanmartin](https://github.com/jeanmartin).
5
+ * [#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).
6
+
1
7
  ### 0.4.0 (2023/08/13)
2
8
 
3
9
  * [#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,7 @@ 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)
23
24
  - [Stations](#stations)
24
25
  - [Register a Station](#register-a-station)
25
26
  - [List Stations](#list-stations)
@@ -87,10 +88,21 @@ data.main.temp # => 12
87
88
  ```
88
89
 
89
90
  Returns weather by city, optional state (in the US) and optional ISO 3166 country code.
91
+ Names that cannot be resolved will cause the API call to raise a `Faraday::ResourceNotFound` error.
90
92
 
91
93
  ```ruby
92
- client.current_city('New York', 'NY', 'US')
93
- client.current_weather(city: 'New York', state: 'NY', country: 'US')
94
+ client.current_city('Sydney')
95
+ client.current_city('London, UK')
96
+ client.current_city('London', 'UK')
97
+ client.current_city('Albany')
98
+ client.current_city('Albany, New York')
99
+ client.current_city('Albany, New York', 'US')
100
+ client.current_city('Albany, NY', 'US')
101
+ client.current_city('Albany', 'New York', 'US')
102
+ client.current_city('Albany', 'NY', 'US')
103
+ client.current_city('Albany', 'NY') # 2-letter state abbreviation w/o country will raise Faraday::ResourceNotFound
104
+
105
+ client.current_weather(city: 'Albany', state: 'NY', country: 'US')
94
106
  ```
95
107
 
96
108
  Returns weather by city ID.
@@ -167,7 +179,7 @@ data.main.temp # => 285.15
167
179
 
168
180
  ### One Call
169
181
 
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, and historical weather data for 5 previous days for any geographical coordinate.
182
+ [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
183
 
172
184
  See [OpenWeather::Models::OneCall](lib/open_weather/models/one_call) for all available models and properties.
173
185
 
@@ -175,6 +187,7 @@ See [OpenWeather::Models::OneCall](lib/open_weather/models/one_call) for all ava
175
187
 
176
188
  ```ruby
177
189
  data = client.one_call(lat: 33.441792, lon: -94.037689) # => OpenWeather::Models::OneCall::Weather
190
+
178
191
  data.lat # => 33.44
179
192
  data.lon # => -94.04
180
193
  data.timezone # => 'America/Chicago'
@@ -182,6 +195,7 @@ data.current # => OpenWeather::Models::OneCall::CurrentWeather
182
195
  data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
183
196
  data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
184
197
  data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
198
+ data.alerts # => Array[OpenWeather::Models::OneCall::Alert]
185
199
  ```
186
200
 
187
201
  Exclude minutely and hourly data.
@@ -194,6 +208,7 @@ client.one_call(lat: 33.441792, lon: -94.037689, exclude: ['minutely', 'hourly']
194
208
 
195
209
  ```ruby
196
210
  data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.now - 24 * 60 * 60) # => OpenWeather::Models::OneCall::Weather
211
+
197
212
  data.lat # => 33.44
198
213
  data.lon # => -94.04
199
214
  data.timezone # => 'America/Chicago'
@@ -201,6 +216,28 @@ data.current # => OpenWeather::Models::OneCall::CurrentWeather
201
216
  data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
202
217
  ```
203
218
 
219
+ ### Hourly Forecast (Pro)
220
+
221
+ The [Hourly Forecast API](https://openweathermap.org/api/hourly-forecast) provides hourly weather forecast for 4 days. Note: This API requires a piad api-key from [OpenWeather.org](https://openweathermap.org/full-price#current).
222
+
223
+ ```ruby
224
+ data = client.client.hourly(lat: 33.5312, lon: -111.9426) # => OpenWeather::Models::Forecast::Hourly
225
+
226
+ data.cnt # => 96 (number of entries)
227
+ data.list.first # => OpenWeather::Models::Forecast::Forecast
228
+ data.list.first.dt # => Time
229
+ data.list.first.main # => OpenWeather::Models::Forecast::Main
230
+ data.list.first.weather # => Array[OpenWeather::Models::Forecast::Weather]
231
+ data.list.first.clouds # => OpenWeather::Models::Forecast::Clouds or nil
232
+ data.list.first.wind # => OpenWeather::Models::Forecast::Wind or nil
233
+ data.list.first.visibility # => 10000
234
+ data.list.first.pop # => 0.1 (probability of precipitation from 0.0 to 1.0 (0% to 100%))
235
+ data.list.first.rain # => OpenWeather::Models::Forecast::Rain or nil
236
+ data.list.first.snow # => OpenWeather::Models::Forecast::Snow or nil
237
+ data.list.first.sys # => OpenWeather::Models::Forecast::Sys or nil
238
+ data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
239
+ ```
240
+
204
241
  ### Stations
205
242
 
206
243
  The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
@@ -5,6 +5,7 @@ module OpenWeather
5
5
  include Connection
6
6
  include Request
7
7
  include Endpoints::Current
8
+ include Endpoints::Hourly
8
9
  include Endpoints::OneCall
9
10
  include Endpoints::Stations
10
11
 
@@ -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) ? '2.5/onecall/timemachine' : '2.5/onecall'
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
@@ -3,3 +3,4 @@
3
3
  require_relative 'endpoints/current'
4
4
  require_relative 'endpoints/one_call'
5
5
  require_relative 'endpoints/stations'
6
+ require_relative 'endpoints/hourly'
@@ -0,0 +1,17 @@
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
+ end
15
+ end
16
+ end
17
+ 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. The values of the parameter vary between 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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'forecast/hourly'
4
+ require_relative 'forecast/forecast'
5
+ require_relative 'forecast/city'
@@ -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
@@ -20,6 +20,7 @@ module OpenWeather
20
20
  property 'rain' # precipitation volume, mm
21
21
  property 'snow' # snow volume, mm
22
22
  property 'weather'
23
+ property 'summary'
23
24
 
24
25
  def initialize(args = nil, options = {})
25
26
  super args, options
@@ -11,6 +11,7 @@ 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
14
15
 
15
16
  def initialize(args = nil, options = {})
16
17
  super args, options
@@ -19,6 +20,7 @@ module OpenWeather
19
20
  self.minutely = minutely.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i, options) } if minutely
20
21
  self.hourly = hourly.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i, options) } if hourly
21
22
  self.daily = daily.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i, options) } if daily
23
+ self.alerts = alerts.map { |i| OpenWeather::Models::OneCall::Alert.new(i, options) } if alerts
22
24
  end
23
25
  end
24
26
  end
@@ -7,3 +7,4 @@ require_relative 'one_call/daily_weather'
7
7
  require_relative 'one_call/hourly_weather'
8
8
  require_relative 'one_call/minutely_weather'
9
9
  require_relative 'one_call/weather'
10
+ require_relative 'one_call/alert'
@@ -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'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenWeather
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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.0
4
+ version: 0.5.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: 2023-08-13 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -207,6 +207,7 @@ 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
212
213
  - lib/open_weather/errors.rb
@@ -217,6 +218,10 @@ files:
217
218
  - lib/open_weather/models/city/weather.rb
218
219
  - lib/open_weather/models/clouds.rb
219
220
  - lib/open_weather/models/coord.rb
221
+ - lib/open_weather/models/forecast.rb
222
+ - lib/open_weather/models/forecast/city.rb
223
+ - lib/open_weather/models/forecast/forecast.rb
224
+ - lib/open_weather/models/forecast/hourly.rb
220
225
  - lib/open_weather/models/list.rb
221
226
  - lib/open_weather/models/main.rb
222
227
  - lib/open_weather/models/mixins.rb
@@ -224,6 +229,7 @@ files:
224
229
  - lib/open_weather/models/mixins/temp.rb
225
230
  - lib/open_weather/models/model.rb
226
231
  - lib/open_weather/models/one_call.rb
232
+ - lib/open_weather/models/one_call/alert.rb
227
233
  - lib/open_weather/models/one_call/current_weather.rb
228
234
  - lib/open_weather/models/one_call/daily_weather.rb
229
235
  - lib/open_weather/models/one_call/feels_like.rb
@@ -264,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
270
  - !ruby/object:Gem::Version
265
271
  version: 1.3.6
266
272
  requirements: []
267
- rubygems_version: 3.3.7
273
+ rubygems_version: 3.5.6
268
274
  signing_key:
269
275
  specification_version: 4
270
276
  summary: OpenWeather API Ruby client.