open-weather-ruby-client 0.1.0 → 0.3.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 +17 -1
- data/README.md +178 -11
- data/lib/open-weather-ruby-client.rb +1 -3
- data/lib/open_weather/client.rb +2 -0
- data/lib/open_weather/config.rb +3 -3
- data/lib/open_weather/connection.rb +22 -17
- data/lib/open_weather/endpoints/current.rb +4 -4
- data/lib/open_weather/endpoints/one_call.rb +15 -0
- data/lib/open_weather/endpoints/stations.rb +53 -0
- data/lib/open_weather/endpoints.rb +2 -0
- data/lib/open_weather/models/city/weather.rb +38 -0
- data/lib/open_weather/models/city.rb +3 -0
- data/lib/open_weather/models/list.rb +7 -1
- data/lib/open_weather/models/main.rb +4 -4
- data/lib/open_weather/models/mixins/speed.rb +45 -0
- data/lib/open_weather/models/mixins/temp.rb +64 -0
- data/lib/open_weather/models/mixins.rb +4 -0
- data/lib/open_weather/models/model.rb +14 -0
- data/lib/open_weather/models/one_call/current_weather.rb +35 -0
- data/lib/open_weather/models/one_call/daily_weather.rb +34 -0
- data/lib/open_weather/models/one_call/feels_like.rb +14 -0
- data/lib/open_weather/models/one_call/hourly_weather.rb +32 -0
- data/lib/open_weather/models/one_call/minutely_weather.rb +12 -0
- data/lib/open_weather/models/one_call/temp.rb +16 -0
- data/lib/open_weather/models/one_call/weather.rb +26 -0
- data/lib/open_weather/models/one_call.rb +9 -0
- data/lib/open_weather/models/station.rb +35 -0
- data/lib/open_weather/models/stations/humidity.rb +12 -0
- data/lib/open_weather/models/stations/measurement.rb +27 -0
- data/lib/open_weather/models/stations/precipitation.rb +11 -0
- data/lib/open_weather/models/stations/pressure.rb +14 -0
- data/lib/open_weather/models/stations/temp.rb +14 -0
- data/lib/open_weather/models/sys.rb +1 -0
- data/lib/open_weather/models/weather.rb +1 -0
- data/lib/open_weather/models/wind.rb +1 -1
- data/lib/open_weather/models.rb +9 -1
- data/lib/open_weather/raise_error.rb +2 -2
- data/lib/open_weather/request.rb +14 -1
- data/lib/open_weather/version.rb +1 -1
- metadata +30 -10
- data/lib/open_weather/models/city_weather.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b61381c999fcbbcefa63521936ee96cc28eb7648a9b2b13cc9d01a608d8b12f
|
4
|
+
data.tar.gz: aaa00190d52e86a471f2dca1e52c5c4f5fbf67cdfdf5639fe9302d793d1326e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890ef7edc806545a9b83f99a87133d7ff83900593f17e5aadcf76f7389cfa7c6a3249d0f4911d6d257d493a00dd572880f8848ee68a6ba0cd5ffd9561c53c75f
|
7
|
+
data.tar.gz: 3094f7b9d058070590db2ddfabc99d9f799f00b3b185fb9efd93b348d9abd8f124ec8d2f0552f7430850bf08dc7cb698e802c648a32aa9dbaf333b343c0521b4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
-
### 0.
|
1
|
+
### 0.3.0 (2023/03/25)
|
2
|
+
|
3
|
+
* [#30](https://github.com/dblock/open-weather-ruby-client/pull/30): Added support for Ruby 3.2 - [@petergoldstein](https://github.com/petergoldstein).
|
4
|
+
* [#27](https://github.com/dblock/open-weather-ruby-client/pull/27): Removed default values for Faraday’s SSL settings ca_file and ca_path - [@sunny](https://github.com/sunny).
|
5
|
+
* [#21](https://github.com/dblock/open-weather-ruby-client/pull/21), [#20](https://github.com/dblock/open-weather-ruby-client/pull/20), [#19](https://github.com/dblock/open-weather-ruby-client/pull/19), [#18](https://github.com/dblock/open-weather-ruby-client/pull/18): Added support for Stations API - [@wasabigeek](https://github.com/wasabigeek).
|
6
|
+
* [#22](https://github.com/dblock/open-weather-ruby-client/pull/23): Removed API version from `Config#endpoint` - [@dblock](https://github.com/dblock).
|
7
|
+
|
8
|
+
### 0.2.0 (2020/05/17)
|
9
|
+
|
10
|
+
* [#14](https://github.com/dblock/open-weather-ruby-client/pull/14): Added support for One Call API - [@dblock](https://github.com/dblock).
|
11
|
+
* [#16](https://github.com/dblock/open-weather-ruby-client/pull/16): Added support for temperature and wind speed conversion - [@dblock](https://github.com/dblock).
|
12
|
+
* [#16](https://github.com/dblock/open-weather-ruby-client/pull/16): Added `weather#icon_url` returning a parsed `URI` - [@dblock](https://github.com/dblock).
|
13
|
+
* [#15](https://github.com/dblock/open-weather-ruby-client/pull/15): Renamed `CityWeather` to `OpenWeather::Models::City::Weather` - [@dblock](https://github.com/dblock).
|
14
|
+
* [#12](https://github.com/dblock/open-weather-ruby-client/pull/12): Cache `Faraday::Connection` for persistent adapters - [@dblock](https://github.com/dblock).
|
15
|
+
* [#13](https://github.com/dblock/open-weather-ruby-client/pull/13): Require Faraday >= 1.0 - [@dblock](https://github.com/dblock).
|
16
|
+
|
17
|
+
### 0.1.0 (2020/05/01)
|
2
18
|
|
3
19
|
* Initial public release - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@ OpenWeather Ruby Client
|
|
2
2
|
=======================
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/open-weather-ruby-client.svg)](https://badge.fury.io/rb/open-weather-ruby-client)
|
5
|
-
[![
|
5
|
+
[![Tests Status](https://github.com/dblock/open-weather-ruby-client/actions/workflows/test.yml/badge.svg)](https://github.com/dblock/open-weather-ruby-client/actions)
|
6
6
|
|
7
|
-
A Ruby client for the [OpenWeather API v3](https://openweathermap.org/api).
|
7
|
+
A Ruby client for the [OpenWeather API v2.5 and v3.0](https://openweathermap.org/api).
|
8
8
|
|
9
|
-
Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_open_weather_map), provides a rich first class interface to OpenWeather models,
|
9
|
+
Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_open_weather_map), provides a rich first class interface to OpenWeather models, structured timestamps, built-in metrics conversion for temperature and wind speed, offers more consistent error handling, and is implemented with thorough test coverage using actual OpenWeather data.
|
10
10
|
|
11
11
|
## Table of Contents
|
12
12
|
|
@@ -17,8 +17,21 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o
|
|
17
17
|
- [Cities Within a Rectangle Zone](#cities-within-a-rectangle-zone)
|
18
18
|
- [Cities Within a Circle](#cities-within-a-circle)
|
19
19
|
- [Multiple Cities by Id](#multiple-cities-by-id)
|
20
|
+
- [One Call](#one-call)
|
21
|
+
- [Current and Forecast Weather](#current-and-forecast-weather)
|
22
|
+
- [Historical Weather](#historical-weather)
|
23
|
+
- [Stations](#stations)
|
24
|
+
- [Register a Station](#register-a-station)
|
25
|
+
- [List Stations](#list-stations)
|
26
|
+
- [Get Station](#get-station)
|
27
|
+
- [Update Station](#update-station)
|
28
|
+
- [Delete Station](#delete-station)
|
29
|
+
- [Create Measurements](#create-measurements)
|
30
|
+
- [Get Measurements](#get-measurements)
|
20
31
|
- [Configuration](#configuration)
|
21
32
|
- [Units](#units)
|
33
|
+
- [Converting Temperature](#converting-temperature)
|
34
|
+
- [Converting Wind Speed](#converting-wind-speed)
|
22
35
|
- [Language](#language)
|
23
36
|
- [Errors](#errors)
|
24
37
|
- [Resources](#resources)
|
@@ -50,21 +63,24 @@ client = OpenWeather::Client.new(
|
|
50
63
|
Returns [current weather](https://openweathermap.org/current).
|
51
64
|
|
52
65
|
```ruby
|
53
|
-
data = client.current_weather(city: 'London') # => OpenWeather::Models::
|
66
|
+
data = client.current_weather(city: 'London') # => OpenWeather::Models::City::Weather
|
54
67
|
|
55
68
|
data.name # => 'London'
|
69
|
+
data.dt # => Time
|
56
70
|
data.main.feels_like # => 277.73
|
57
71
|
data.main.humidity # => 81
|
58
72
|
data.main.pressure # => 1005
|
59
73
|
data.main.temp # => 282.57
|
60
|
-
data.main.temp_max # => 283.15
|
74
|
+
data.main.temp_max # => 283.15, degrees Kelvin
|
75
|
+
data.main.temp_max_c # => 10, degrees Celcius
|
76
|
+
data.main.temp_max_f # => 50.0, degrees Farenheit
|
61
77
|
data.main.temp_min # => 281.48
|
62
78
|
```
|
63
79
|
|
64
80
|
Returns the current weather in metric units and Russian metadata.
|
65
81
|
|
66
82
|
```ruby
|
67
|
-
data = client.current_weather(city: 'Moscow', units: 'metric', lang: 'ru') # => OpenWeather::Models::
|
83
|
+
data = client.current_weather(city: 'Moscow', units: 'metric', lang: 'ru') # => OpenWeather::Models::City::Weather
|
68
84
|
|
69
85
|
data.name # => 'Москва'
|
70
86
|
data.main.temp # => 12
|
@@ -98,10 +114,12 @@ client.current_zip(10018, 'US') # => weather in New York, 10018
|
|
98
114
|
client.current_weather(zip: 10018, country: 'US') # => weather in New York, 10018
|
99
115
|
```
|
100
116
|
|
101
|
-
See [OpenWeather::Models::
|
117
|
+
See [OpenWeather::Models::City::Weather](lib/open_weather/models/city/weather.rb) and related [OpenWeather::Models](lib/open_weather/models) for all available properties.
|
102
118
|
|
103
119
|
### Current Weather for Several Cities
|
104
120
|
|
121
|
+
Collection APIs return [OpenWeather::Models::List](lib/open_weather/models/list.rb), which includes multiple instances of [OpenWeather::Models::City::Weather](lib/open_weather/models/city/weather.rb).
|
122
|
+
|
105
123
|
#### Cities Within a Rectangle Zone
|
106
124
|
|
107
125
|
```ruby
|
@@ -147,6 +165,132 @@ data.first.name # 'Moscow'
|
|
147
165
|
data.main.temp # => 285.15
|
148
166
|
```
|
149
167
|
|
168
|
+
### One Call
|
169
|
+
|
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.
|
171
|
+
|
172
|
+
See [OpenWeather::Models::OneCall](lib/open_weather/models/one_call) for all available models and properties.
|
173
|
+
|
174
|
+
#### Current and Forecast Weather
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
data = client.one_call(lat: 33.441792, lon: -94.037689) # => OpenWeather::Models::OneCall::Weather
|
178
|
+
data.lat # => 33.44
|
179
|
+
data.lon # => -94.04
|
180
|
+
data.timezone # => 'America/Chicago'
|
181
|
+
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
182
|
+
data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
|
183
|
+
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
184
|
+
data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
|
185
|
+
```
|
186
|
+
|
187
|
+
Exclude minutely and hourly data.
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
client.one_call(lat: 33.441792, lon: -94.037689, exclude: ['minutely', 'hourly'])
|
191
|
+
```
|
192
|
+
|
193
|
+
#### Historical Weather
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.now - 24 * 60 * 60) # => OpenWeather::Models::OneCall::Weather
|
197
|
+
data.lat # => 33.44
|
198
|
+
data.lon # => -94.04
|
199
|
+
data.timezone # => 'America/Chicago'
|
200
|
+
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
201
|
+
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
202
|
+
```
|
203
|
+
|
204
|
+
### Stations
|
205
|
+
|
206
|
+
The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
|
207
|
+
|
208
|
+
#### Register a Station
|
209
|
+
|
210
|
+
To register a station, you can call the client method:
|
211
|
+
```ruby
|
212
|
+
data = client.register_station(external_id: 'SF_TEST001', ...) # => OpenWeather::Models::Station
|
213
|
+
data.id # => '5ed2118acca8ce0001f1aeg1'
|
214
|
+
data.external_id # => 'SF_TEST001'
|
215
|
+
```
|
216
|
+
Alternatively, call `register!` on an instance of `Station`:
|
217
|
+
```ruby
|
218
|
+
model = OpenWeather::Models::Station.new(external_id: 'SF_TEST001', ...)
|
219
|
+
model.register!
|
220
|
+
model.id # => '5ed2118acca8ce0001f1aeg1'
|
221
|
+
```
|
222
|
+
|
223
|
+
#### List Stations
|
224
|
+
|
225
|
+
To list all stations, call the client method:
|
226
|
+
```ruby
|
227
|
+
client.list_stations # => Array[OpenWeather::Models::Station]
|
228
|
+
```
|
229
|
+
|
230
|
+
#### Get Station
|
231
|
+
|
232
|
+
To get a station, call the client method:
|
233
|
+
```ruby
|
234
|
+
client.get_station('5ed2118acca8ce0001f1aeg1') # => OpenWeather::Models::Station
|
235
|
+
```
|
236
|
+
|
237
|
+
#### Update Station
|
238
|
+
|
239
|
+
To update a station, call the client method:
|
240
|
+
```ruby
|
241
|
+
client.update_station('5ed2118acca8ce0001f1aeg1', external_id: 'SF_TEST002') # => OpenWeather::Models::Station
|
242
|
+
```
|
243
|
+
Alternatively, call `update!` on an instance of `Station`:
|
244
|
+
```ruby
|
245
|
+
model = OpenWeather::Models::Station.new(external_id: 'SF_TEST001', ...)
|
246
|
+
model.register!
|
247
|
+
model.update!(external_id: 'SF_TEST002')
|
248
|
+
model.external_id # => 'SF_TEST002'
|
249
|
+
```
|
250
|
+
|
251
|
+
#### Delete Station
|
252
|
+
|
253
|
+
To delete a station, call the client method:
|
254
|
+
```ruby
|
255
|
+
data = client.delete_station('5ed2118acca8ce0001f1aeg1') # => nil
|
256
|
+
```
|
257
|
+
|
258
|
+
#### Create Measurements
|
259
|
+
|
260
|
+
To create measurements, call the client method:
|
261
|
+
```ruby
|
262
|
+
client.create_measurements([
|
263
|
+
{
|
264
|
+
"station_id": -1,
|
265
|
+
"dt": 1479817340,
|
266
|
+
"temperature": 18.7,
|
267
|
+
"wind_speed": 1.2,
|
268
|
+
"wind_gust": 3.4,
|
269
|
+
"pressure": 1021,
|
270
|
+
"humidity": 87,
|
271
|
+
"rain_1h": 2,
|
272
|
+
"clouds": [
|
273
|
+
{
|
274
|
+
"condition": 'NSC'
|
275
|
+
}
|
276
|
+
]
|
277
|
+
}
|
278
|
+
]) # => nil
|
279
|
+
```
|
280
|
+
|
281
|
+
#### Get Measurements
|
282
|
+
|
283
|
+
To get measurements, call the client method with the required parameters:
|
284
|
+
```ruby
|
285
|
+
client.get_measurements(
|
286
|
+
station_id: '5ed21a12cca8ce0001f1aef1',
|
287
|
+
type: 'd',
|
288
|
+
limit: 100,
|
289
|
+
from: 1469817340,
|
290
|
+
to: 1591620047
|
291
|
+
) # => Array[OpenWeather::Models::Stations::Measurement]
|
292
|
+
```
|
293
|
+
|
150
294
|
## Configuration
|
151
295
|
|
152
296
|
You can configure client options, globally.
|
@@ -165,7 +309,7 @@ setting | description
|
|
165
309
|
api_key | Required API key.
|
166
310
|
lang | Default language in API responses.
|
167
311
|
units | Default units in API responses.
|
168
|
-
endpoint | Defaults to `https://api.openweathermap.org/data
|
312
|
+
endpoint | Defaults to `https://api.openweathermap.org/data`.
|
169
313
|
user_agent | User-agent, defaults to _OpenWeather Ruby Client/version_.
|
170
314
|
proxy | Optional HTTP proxy.
|
171
315
|
ca_path | Optional SSL certificates path.
|
@@ -181,7 +325,7 @@ The OpenWeather API returns responses in `standard`, `metric`, and `imperial` un
|
|
181
325
|
```ruby
|
182
326
|
data = client.weather(id: 2643743, units: 'metric')
|
183
327
|
data.name # => 'London'
|
184
|
-
data.main.temp # => 12
|
328
|
+
data.main.temp # => 12, degrees Celcius
|
185
329
|
```
|
186
330
|
|
187
331
|
```ruby
|
@@ -191,7 +335,30 @@ end
|
|
191
335
|
|
192
336
|
data = client.weather(id: 2643743)
|
193
337
|
data.name # => 'London'
|
194
|
-
data.main.temp # => 12
|
338
|
+
data.main.temp # => 12, degrees Celcius
|
339
|
+
```
|
340
|
+
|
341
|
+
#### Converting Temperature
|
342
|
+
|
343
|
+
APIs that return temperature support conversion between default, metric and imperial units, regardless of what units were requested. The following example requests current weather in metric units in Moscow. Use `_k` for Kelvin, `_c` for Celcius and `_f` for Farenheit.
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
data = client.current_weather(city: 'Moscow', units: 'metric') # => OpenWeather::Models::City::Weather
|
347
|
+
|
348
|
+
data.main.temp_max # => 12, degrees Celcius, metric as requested
|
349
|
+
data.main.temp_max_c # => 12, degrees Celcius
|
350
|
+
data.main.temp_max_k # => 285.15, degrees Kelvin
|
351
|
+
data.main.temp_max_f # => 53.6, degrees Farenheit
|
352
|
+
```
|
353
|
+
|
354
|
+
#### Converting Wind Speed
|
355
|
+
|
356
|
+
Use `_mps` for wind speed in meters-per-second, and `_mph` for miles-per-second.
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
data.wind.speed # => 3, in meters per second, metric as requested
|
360
|
+
data.main.speed_mph # => 6.71, miles per hour
|
361
|
+
data.main.speed_mps # 3, meters per second
|
195
362
|
```
|
196
363
|
|
197
364
|
### Language
|
@@ -214,7 +381,7 @@ data.name # => 'Лондон'
|
|
214
381
|
|
215
382
|
## Errors
|
216
383
|
|
217
|
-
All errors that return HTTP codes 400-600 result in either `Faraday::
|
384
|
+
All errors that return HTTP codes 400-600 result in either `Faraday::ResourceNotFound`, `Faraday::ConnectionFailed` or [OpenWeather::Errors::Fault](lib/open_weather/errors/fault.rb) exceptions.
|
218
385
|
|
219
386
|
## Resources
|
220
387
|
|
@@ -16,13 +16,11 @@ require_relative 'open_weather/logger'
|
|
16
16
|
|
17
17
|
require_relative 'open_weather/errors/fault'
|
18
18
|
|
19
|
-
require_relative 'open_weather/models
|
20
|
-
|
19
|
+
require_relative 'open_weather/models'
|
21
20
|
require_relative 'open_weather/raise_error'
|
22
21
|
require_relative 'open_weather/connection'
|
23
22
|
require_relative 'open_weather/request'
|
24
23
|
require_relative 'open_weather/config'
|
25
24
|
require_relative 'open_weather/errors'
|
26
|
-
require_relative 'open_weather/models'
|
27
25
|
require_relative 'open_weather/endpoints'
|
28
26
|
require_relative 'open_weather/client'
|
data/lib/open_weather/client.rb
CHANGED
data/lib/open_weather/config.rb
CHANGED
@@ -21,11 +21,11 @@ module OpenWeather
|
|
21
21
|
attr_accessor(*Config::ATTRIBUTES)
|
22
22
|
|
23
23
|
def reset
|
24
|
-
self.endpoint = 'https://api.openweathermap.org/data
|
24
|
+
self.endpoint = 'https://api.openweathermap.org/data'
|
25
25
|
self.api_key = nil
|
26
26
|
self.user_agent = "OpenWeather Ruby Client/#{OpenWeather::VERSION}"
|
27
|
-
self.ca_path =
|
28
|
-
self.ca_file =
|
27
|
+
self.ca_path = nil
|
28
|
+
self.ca_file = nil
|
29
29
|
self.proxy = nil
|
30
30
|
self.logger = nil
|
31
31
|
self.timeout = nil
|
@@ -9,26 +9,31 @@ module OpenWeather
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def connection
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
@connection ||= begin
|
13
|
+
options = {
|
14
|
+
headers: headers.merge(
|
15
|
+
'Accept' => 'application/json; charset=utf-8',
|
16
|
+
'Content-Type' => 'application/json'
|
17
|
+
)
|
18
|
+
}
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
options[:headers]['User-Agent'] = user_agent if user_agent
|
21
|
+
options[:proxy] = proxy if proxy
|
22
|
+
options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
request_options = {}
|
25
|
+
request_options[:timeout] = timeout if timeout
|
26
|
+
request_options[:open_timeout] = open_timeout if open_timeout
|
27
|
+
options[:request] = request_options if request_options.any?
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
::Faraday::Connection.new(endpoint, options) do |connection|
|
30
|
+
connection.use ::Faraday::Request::Multipart
|
31
|
+
connection.use ::Faraday::Request::UrlEncoded
|
32
|
+
connection.use ::OpenWeather::Response::RaiseError
|
33
|
+
connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
34
|
+
connection.response :logger, logger if logger
|
35
|
+
connection.adapter ::Faraday.default_adapter
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -38,7 +38,7 @@ module OpenWeather
|
|
38
38
|
options.delete(:country)
|
39
39
|
].compact.join(',')
|
40
40
|
end
|
41
|
-
OpenWeather::Models::
|
41
|
+
OpenWeather::Models::City::Weather.new(get('2.5/weather', options), options)
|
42
42
|
end
|
43
43
|
|
44
44
|
def current_cities_geo_box(*args)
|
@@ -51,7 +51,7 @@ module OpenWeather
|
|
51
51
|
options.delete(:lat_top),
|
52
52
|
options.delete(:zoom)
|
53
53
|
].join(',')
|
54
|
-
OpenWeather::Models::List.new(get('box/city', options))
|
54
|
+
OpenWeather::Models::List.new(get('2.5/box/city', options), options)
|
55
55
|
end
|
56
56
|
|
57
57
|
def current_cities_geo_circle(*args)
|
@@ -63,7 +63,7 @@ module OpenWeather
|
|
63
63
|
options[:cnt] = args.shift || 1
|
64
64
|
end
|
65
65
|
|
66
|
-
OpenWeather::Models::List.new(get('find', options))
|
66
|
+
OpenWeather::Models::List.new(get('2.5/find', options), options)
|
67
67
|
end
|
68
68
|
|
69
69
|
def current_cities_id(*args)
|
@@ -71,7 +71,7 @@ module OpenWeather
|
|
71
71
|
options[:id] = args.join(',') if args.any?
|
72
72
|
options[:id] = options.delete(:ids) if options.key?(:ids)
|
73
73
|
options[:id] = options[:id].join(',') if options[:id].is_a?(Array)
|
74
|
-
OpenWeather::Models::List.new(get('group', options))
|
74
|
+
OpenWeather::Models::List.new(get('2.5/group', options), options)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Endpoints
|
5
|
+
module OneCall
|
6
|
+
def one_call(lat, lon = nil, options = {})
|
7
|
+
options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon)
|
8
|
+
options[:exclude] = options[:exclude].join(',') if options[:exclude].is_a?(Array)
|
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'
|
11
|
+
OpenWeather::Models::OneCall::Weather.new(get(path, options), options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Endpoints
|
5
|
+
module Stations
|
6
|
+
def register_station(options = {})
|
7
|
+
OpenWeather::Models::Station.new(post('3.0/stations', options))
|
8
|
+
end
|
9
|
+
|
10
|
+
def list_stations
|
11
|
+
get('3.0/stations').map { |data| OpenWeather::Models::Station.new(data) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_station(id)
|
15
|
+
validate_id(id)
|
16
|
+
|
17
|
+
OpenWeather::Models::Station.new(get("3.0/stations/#{id}"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_station(id, options = {})
|
21
|
+
validate_id(id)
|
22
|
+
|
23
|
+
OpenWeather::Models::Station.new(put("3.0/stations/#{id}", options))
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_station(id)
|
27
|
+
validate_id(id)
|
28
|
+
|
29
|
+
delete("3.0/stations/#{id}")
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_measurements(measurements, options = {})
|
34
|
+
post('3.0/measurements', options.merge(body: measurements))
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_measurements(options)
|
39
|
+
required_keys = %i[station_id type limit from to]
|
40
|
+
missing_keys = required_keys - options.keys
|
41
|
+
raise ArgumentError, "Missing params: #{missing_keys.join(', ')}" if missing_keys.any?
|
42
|
+
|
43
|
+
get('3.0/measurements', options).map { |m| OpenWeather::Models::Stations::Measurement.new(m) }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def validate_id(id)
|
49
|
+
raise ArgumentError, 'Invalid ID' unless id&.is_a?(String)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module City
|
6
|
+
class Weather < Model
|
7
|
+
property 'coord'
|
8
|
+
property 'weather'
|
9
|
+
property 'base' # internal parameter
|
10
|
+
property 'main'
|
11
|
+
property 'visibility'
|
12
|
+
property 'wind'
|
13
|
+
property 'clouds'
|
14
|
+
property 'rain'
|
15
|
+
property 'snow'
|
16
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data calculation, UTC
|
17
|
+
property 'sys'
|
18
|
+
property 'id' # city id
|
19
|
+
property 'timezone' # shift in seconds from UTC
|
20
|
+
property 'name' # city name
|
21
|
+
property 'cod' # internal parameter
|
22
|
+
|
23
|
+
def initialize(args = nil, options = {})
|
24
|
+
super args, options
|
25
|
+
|
26
|
+
self.coord = OpenWeather::Models::Coord.new(coord, options) if coord
|
27
|
+
self.weather = weather.map { |i| OpenWeather::Models::Weather.new(i, options) } if weather
|
28
|
+
self.main = OpenWeather::Models::Main.new(main, options) if main
|
29
|
+
self.wind = OpenWeather::Models::Wind.new(wind, options) if wind
|
30
|
+
self.clouds = OpenWeather::Models::Clouds.new(clouds, options) if clouds
|
31
|
+
self.rain = OpenWeather::Models::Rain.new(rain, options) if rain
|
32
|
+
self.snow = OpenWeather::Models::Snow.new(snow, options) if snow
|
33
|
+
self.sys = OpenWeather::Models::Sys.new(sys, options) if sys
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -8,9 +8,15 @@ module OpenWeather
|
|
8
8
|
property 'cod'
|
9
9
|
property 'calctime'
|
10
10
|
property 'cnt', from: 'count'
|
11
|
-
property 'list'
|
11
|
+
property 'list'
|
12
12
|
property 'message'
|
13
13
|
|
14
|
+
def initialize(args = nil, options = {})
|
15
|
+
super args, options
|
16
|
+
|
17
|
+
self.list = list.map { |i| OpenWeather::Models::City::Weather.new(i, options) } if list
|
18
|
+
end
|
19
|
+
|
14
20
|
def each(&block)
|
15
21
|
list.each(&block)
|
16
22
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module OpenWeather
|
4
4
|
module Models
|
5
5
|
class Main < Model
|
6
|
-
|
6
|
+
temperature_property 'temp' # temperature in requested unit
|
7
7
|
property 'pressure' # atmospheric pressure on the sea_level or grnd_level when unavailable, hPa
|
8
8
|
property 'humidity' # humidity in %
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
temperature_property 'feels_like' # temperature, accounting for the human perception of weather, in requested unit
|
10
|
+
temperature_property 'temp_min' # minimal currently observed temperature
|
11
|
+
temperature_property 'temp_max' # maximal currently observed temperature
|
12
12
|
property 'sea_level' # atmospheric pressure on the sea level, hPa
|
13
13
|
property 'grnd_level' # atmospheric pressure on the ground level, hPa
|
14
14
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Mixins
|
6
|
+
module Speed
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def speed_property(field)
|
11
|
+
property field
|
12
|
+
|
13
|
+
define_method "#{field}_mps" do
|
14
|
+
to_meters_per_sec(send(field))
|
15
|
+
end
|
16
|
+
|
17
|
+
define_method "#{field}_mph" do
|
18
|
+
to_miles_per_hour(send(field))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def to_meters_per_sec(value)
|
26
|
+
case units
|
27
|
+
when :imperial
|
28
|
+
(value.to_f / 2.23694).round(2)
|
29
|
+
else
|
30
|
+
value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_miles_per_hour(value)
|
35
|
+
case units
|
36
|
+
when :metric
|
37
|
+
(value * 2.23694).round(2)
|
38
|
+
else
|
39
|
+
value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Mixins
|
6
|
+
module Temp
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def temperature_property(field)
|
11
|
+
property field
|
12
|
+
|
13
|
+
define_method "#{field}_k" do
|
14
|
+
to_kelvin(send(field))
|
15
|
+
end
|
16
|
+
|
17
|
+
define_method "#{field}_c" do
|
18
|
+
to_celcius(send(field))
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method "#{field}_f" do
|
22
|
+
to_farenheit(send(field))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def to_kelvin(value)
|
30
|
+
case units
|
31
|
+
when :metric
|
32
|
+
(value.to_f + 273.15).round(2)
|
33
|
+
when :imperial
|
34
|
+
((value.to_f - 32) * 5 / 9 + 273.15).round(2)
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_celcius(value)
|
41
|
+
case units
|
42
|
+
when :metric
|
43
|
+
value
|
44
|
+
when :imperial
|
45
|
+
((value.to_f - 32) * 5 / 9).round(2)
|
46
|
+
else
|
47
|
+
(value.to_f - 273.15).round(2)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_farenheit(value)
|
52
|
+
case units
|
53
|
+
when :metric
|
54
|
+
((value.to_f * 9 / 5) + 32).round(2)
|
55
|
+
when :imperial
|
56
|
+
value
|
57
|
+
else
|
58
|
+
((value.to_f - 273.15) * 9 / 5 + 32).round(2)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -4,6 +4,20 @@ module OpenWeather
|
|
4
4
|
module Models
|
5
5
|
class Model < Hashie::Trash
|
6
6
|
include Hashie::Extensions::IgnoreUndeclared
|
7
|
+
include OpenWeather::Models::Mixins::Temp
|
8
|
+
include OpenWeather::Models::Mixins::Speed
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(args = nil, options = {})
|
13
|
+
transformed_args = args.respond_to?(:transform_keys) ? args.transform_keys(&:to_s) : args
|
14
|
+
super transformed_args
|
15
|
+
@options = { units: OpenWeather.config.units }.merge(options || {})
|
16
|
+
end
|
17
|
+
|
18
|
+
def units
|
19
|
+
options && options[:units]&.to_sym
|
20
|
+
end
|
7
21
|
end
|
8
22
|
end
|
9
23
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class CurrentWeather < Model
|
7
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data UTC
|
8
|
+
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # sunrise time, UTC
|
9
|
+
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # sunset time, UTC
|
10
|
+
temperature_property 'temp' # temperature
|
11
|
+
temperature_property 'feels_like' # temperature, accounts for the human perception of weather
|
12
|
+
property 'pressure' # atmospheric pressure on the sea level, hPa
|
13
|
+
property 'humidity' # humidity, %
|
14
|
+
temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form
|
15
|
+
property 'clouds' # cloudiness, %
|
16
|
+
property 'uvi' # UV index
|
17
|
+
property 'visibility' # average visibility, meters
|
18
|
+
speed_property 'wind_speed' # wind speed
|
19
|
+
speed_property 'wind_gust' # wind gust
|
20
|
+
property 'wind_deg' # wind direction, degrees (meteorological)
|
21
|
+
property 'rain'
|
22
|
+
property 'snow'
|
23
|
+
property 'weather'
|
24
|
+
|
25
|
+
def initialize(args = nil, options = {})
|
26
|
+
super args, options
|
27
|
+
|
28
|
+
self.rain = OpenWeather::Models::Rain.new(rain, options) if rain
|
29
|
+
self.snow = OpenWeather::Models::Snow.new(snow, options) if snow
|
30
|
+
self.weather = weather.map { |i| OpenWeather::Models::Weather.new(i, options) } if weather
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class DailyWeather < Model
|
7
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data UTC
|
8
|
+
property 'sunrise', transform_with: ->(v) { Time.at(v).utc } # sunrise time, UTC
|
9
|
+
property 'sunset', transform_with: ->(v) { Time.at(v).utc } # sunset time, UTC
|
10
|
+
property 'temp'
|
11
|
+
property 'feels_like'
|
12
|
+
property 'pressure' # atmospheric pressure on the sea level, hPa
|
13
|
+
property 'humidity' # humidity, %
|
14
|
+
temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form
|
15
|
+
speed_property 'wind_speed' # wind speed
|
16
|
+
speed_property 'wind_gust' # wind gust
|
17
|
+
property 'wind_deg' # wind direction, degrees (meteorological)
|
18
|
+
property 'clouds' # cloudiness, %
|
19
|
+
property 'uvi' # UV index
|
20
|
+
property 'rain' # precipitation volume, mm
|
21
|
+
property 'snow' # snow volume, mm
|
22
|
+
property 'weather'
|
23
|
+
|
24
|
+
def initialize(args = nil, options = {})
|
25
|
+
super args, options
|
26
|
+
|
27
|
+
self.temp = OpenWeather::Models::OneCall::Temp.new(temp, options) if temp
|
28
|
+
self.feels_like = OpenWeather::Models::OneCall::FeelsLike.new(feels_like, options) if feels_like
|
29
|
+
self.weather = weather.map { |i| OpenWeather::Models::Weather.new(i, options) } if weather
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class FeelsLike < Model
|
7
|
+
temperature_property 'morn'
|
8
|
+
temperature_property 'day'
|
9
|
+
temperature_property 'eve'
|
10
|
+
temperature_property 'night'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class HourlyWeather < Model
|
7
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # Time of the forecasted data UTC
|
8
|
+
temperature_property 'temp'
|
9
|
+
temperature_property 'feels_like'
|
10
|
+
property 'pressure' # atmospheric pressure on the sea level, hPa
|
11
|
+
property 'humidity' # humidity, %
|
12
|
+
temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form
|
13
|
+
property 'clouds' # cloudiness, %
|
14
|
+
property 'visibility' # average visibility, meters
|
15
|
+
speed_property 'wind_speed' # wind speed.
|
16
|
+
speed_property 'wind_gust' # wind gust.
|
17
|
+
property 'wind_deg' # wind direction, degrees (meteorological)
|
18
|
+
property 'rain'
|
19
|
+
property 'snow'
|
20
|
+
property 'weather'
|
21
|
+
|
22
|
+
def initialize(args = nil, options = {})
|
23
|
+
super args, options
|
24
|
+
|
25
|
+
self.rain = OpenWeather::Models::Rain.new(rain, options) if rain
|
26
|
+
self.snow = OpenWeather::Models::Snow.new(snow, options) if snow
|
27
|
+
self.weather = weather.map { |i| OpenWeather::Models::Weather.new(i, options) } if weather
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class MinutelyWeather < Model
|
7
|
+
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of the forecasted data UTC
|
8
|
+
property 'precipitation'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class Temp < Model
|
7
|
+
temperature_property 'morn'
|
8
|
+
temperature_property 'day'
|
9
|
+
temperature_property 'eve'
|
10
|
+
temperature_property 'night'
|
11
|
+
temperature_property 'min'
|
12
|
+
temperature_property 'max'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module OneCall
|
6
|
+
class Weather < Model
|
7
|
+
property 'lat' # geographical coordinates of the location (latitude)
|
8
|
+
property 'lon' # geographical coordinates of the location (longitude)
|
9
|
+
property 'timezone' # timezone name for the requested location
|
10
|
+
property 'current' # current weather
|
11
|
+
property 'minutely' # minute forecast weather
|
12
|
+
property 'hourly' # hourly forecast weather
|
13
|
+
property 'daily' # daily forecast weather
|
14
|
+
|
15
|
+
def initialize(args = nil, options = {})
|
16
|
+
super args, options
|
17
|
+
|
18
|
+
self.current = OpenWeather::Models::OneCall::CurrentWeather.new(current, options) if current
|
19
|
+
self.minutely = minutely.map { |i| OpenWeather::Models::OneCall::MinutelyWeather.new(i, options) } if minutely
|
20
|
+
self.hourly = hourly.map { |i| OpenWeather::Models::OneCall::HourlyWeather.new(i, options) } if hourly
|
21
|
+
self.daily = daily.map { |i| OpenWeather::Models::OneCall::DailyWeather.new(i, options) } if daily
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'one_call/temp'
|
4
|
+
require_relative 'one_call/feels_like'
|
5
|
+
require_relative 'one_call/current_weather'
|
6
|
+
require_relative 'one_call/daily_weather'
|
7
|
+
require_relative 'one_call/hourly_weather'
|
8
|
+
require_relative 'one_call/minutely_weather'
|
9
|
+
require_relative 'one_call/weather'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
class Station < Model
|
6
|
+
property 'id', from: 'ID' # internal identifier for the station
|
7
|
+
property 'external_id' # external identifier for the station
|
8
|
+
property 'name' # name of the station
|
9
|
+
property 'latitude' # geographical coordinates of the location (latitude)
|
10
|
+
property 'longitude' # geographical coordinates of the location (longitude)
|
11
|
+
property 'altitude' # height of station above sea level
|
12
|
+
property 'created_at' # timestamp when station was created
|
13
|
+
property 'updated_at' # timestamp when station was updated
|
14
|
+
property 'rank' # rank of station
|
15
|
+
|
16
|
+
def register!
|
17
|
+
data = OpenWeather::Client.new.register_station(to_h)
|
18
|
+
update_attributes!(data)
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def update!(attributes)
|
24
|
+
data = OpenWeather::Client.new.update_station(id, attributes)
|
25
|
+
update_attributes!(data)
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete!
|
31
|
+
OpenWeather::Client.new.delete_station(id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWeather
|
4
|
+
module Models
|
5
|
+
module Stations
|
6
|
+
class Measurement < Model
|
7
|
+
property 'station_id' # The internal ID of the station
|
8
|
+
property 'type' # Type of the aggregated data - minute, hour or day. Specifies the letters m, h or d respectively
|
9
|
+
property 'date' # Time of measurement
|
10
|
+
property 'temp'
|
11
|
+
property 'humidity'
|
12
|
+
property 'wind'
|
13
|
+
property 'precipitation'
|
14
|
+
property 'pressure'
|
15
|
+
|
16
|
+
def initialize(args = nil, options = {})
|
17
|
+
super args, options
|
18
|
+
|
19
|
+
self.temp = OpenWeather::Models::Stations::Temp.new(temp, options) if temp
|
20
|
+
self.humidity = OpenWeather::Models::Stations::Humidity.new(humidity, options) if humidity
|
21
|
+
self.pressure = OpenWeather::Models::Stations::Pressure.new(pressure, options) if pressure
|
22
|
+
self.precipitation = OpenWeather::Models::Stations::Precipitation.new(precipitation, options) if precipitation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,6 +6,7 @@ module OpenWeather
|
|
6
6
|
property 'id' # weather condition id
|
7
7
|
property 'main' # group of weather parameters (Rain, Snow, Extreme, etc.)
|
8
8
|
property 'description' # weather condition within the group, in your language
|
9
|
+
property 'icon_uri', from: 'icon', transform_with: ->(v) { URI.parse("http://openweathermap.org/img/wn/#{v}@2x.png") }
|
9
10
|
property 'icon' # weather icon id
|
10
11
|
end
|
11
12
|
end
|
data/lib/open_weather/models.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'models/mixins'
|
3
4
|
require_relative 'models/model'
|
4
5
|
require_relative 'models/clouds'
|
5
6
|
require_relative 'models/coord'
|
6
|
-
require_relative 'models/city_weather'
|
7
7
|
require_relative 'models/main'
|
8
8
|
require_relative 'models/sys'
|
9
9
|
require_relative 'models/weather'
|
@@ -11,3 +11,11 @@ require_relative 'models/wind'
|
|
11
11
|
require_relative 'models/rain'
|
12
12
|
require_relative 'models/snow'
|
13
13
|
require_relative 'models/list'
|
14
|
+
require_relative 'models/city'
|
15
|
+
require_relative 'models/one_call'
|
16
|
+
require_relative 'models/station'
|
17
|
+
require_relative 'models/stations/measurement'
|
18
|
+
require_relative 'models/stations/temp'
|
19
|
+
require_relative 'models/stations/humidity'
|
20
|
+
require_relative 'models/stations/pressure'
|
21
|
+
require_relative 'models/stations/precipitation'
|
@@ -6,10 +6,10 @@ module OpenWeather
|
|
6
6
|
def on_complete(env)
|
7
7
|
case env[:status]
|
8
8
|
when 404
|
9
|
-
raise Faraday::
|
9
|
+
raise Faraday::ResourceNotFound, response_values(env)
|
10
10
|
when 407
|
11
11
|
# mimic the behavior that we get with proxy requests with HTTPS
|
12
|
-
raise Faraday::
|
12
|
+
raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
|
13
13
|
when (400...600).freeze
|
14
14
|
raise OpenWeather::Errors::Fault, response_values(env)
|
15
15
|
end
|
data/lib/open_weather/request.rb
CHANGED
@@ -20,6 +20,14 @@ module OpenWeather
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
#
|
24
|
+
# @param [Symbol] method - Faraday HTTP method.
|
25
|
+
# @param [String] path - URL to send.
|
26
|
+
# @param [Hash] options - :appid, :lang, :units, :endpoint, :body keys will configure the request.
|
27
|
+
# The rest will be converted to query params for GET/DELETE, or jsonified for POST/PUT.
|
28
|
+
#
|
29
|
+
# @return [Object] - the Faraday::Response#body.
|
30
|
+
#
|
23
31
|
def request(method, path, options)
|
24
32
|
options = options.dup
|
25
33
|
options[:appid] ||= api_key if api_key.present?
|
@@ -33,7 +41,12 @@ module OpenWeather
|
|
33
41
|
request.url(path, options)
|
34
42
|
when :post, :put
|
35
43
|
request.path = path
|
36
|
-
request.
|
44
|
+
request.params = { appid: options.delete(:appid) }
|
45
|
+
if options.key?(:body)
|
46
|
+
request.body = options.delete(:body).to_json
|
47
|
+
elsif !options.empty?
|
48
|
+
request.body = options.to_json
|
49
|
+
end
|
37
50
|
end
|
38
51
|
request.options.merge!(options.delete(:request)) if options.key?(:request)
|
39
52
|
end
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday_middleware
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email: dblock@dblock.org
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
@@ -81,18 +81,38 @@ files:
|
|
81
81
|
- lib/open_weather/connection.rb
|
82
82
|
- lib/open_weather/endpoints.rb
|
83
83
|
- lib/open_weather/endpoints/current.rb
|
84
|
+
- lib/open_weather/endpoints/one_call.rb
|
85
|
+
- lib/open_weather/endpoints/stations.rb
|
84
86
|
- lib/open_weather/errors.rb
|
85
87
|
- lib/open_weather/errors/fault.rb
|
86
88
|
- lib/open_weather/logger.rb
|
87
89
|
- lib/open_weather/models.rb
|
88
|
-
- lib/open_weather/models/
|
90
|
+
- lib/open_weather/models/city.rb
|
91
|
+
- lib/open_weather/models/city/weather.rb
|
89
92
|
- lib/open_weather/models/clouds.rb
|
90
93
|
- lib/open_weather/models/coord.rb
|
91
94
|
- lib/open_weather/models/list.rb
|
92
95
|
- lib/open_weather/models/main.rb
|
96
|
+
- lib/open_weather/models/mixins.rb
|
97
|
+
- lib/open_weather/models/mixins/speed.rb
|
98
|
+
- lib/open_weather/models/mixins/temp.rb
|
93
99
|
- lib/open_weather/models/model.rb
|
100
|
+
- lib/open_weather/models/one_call.rb
|
101
|
+
- lib/open_weather/models/one_call/current_weather.rb
|
102
|
+
- lib/open_weather/models/one_call/daily_weather.rb
|
103
|
+
- lib/open_weather/models/one_call/feels_like.rb
|
104
|
+
- lib/open_weather/models/one_call/hourly_weather.rb
|
105
|
+
- lib/open_weather/models/one_call/minutely_weather.rb
|
106
|
+
- lib/open_weather/models/one_call/temp.rb
|
107
|
+
- lib/open_weather/models/one_call/weather.rb
|
94
108
|
- lib/open_weather/models/rain.rb
|
95
109
|
- lib/open_weather/models/snow.rb
|
110
|
+
- lib/open_weather/models/station.rb
|
111
|
+
- lib/open_weather/models/stations/humidity.rb
|
112
|
+
- lib/open_weather/models/stations/measurement.rb
|
113
|
+
- lib/open_weather/models/stations/precipitation.rb
|
114
|
+
- lib/open_weather/models/stations/pressure.rb
|
115
|
+
- lib/open_weather/models/stations/temp.rb
|
96
116
|
- lib/open_weather/models/sys.rb
|
97
117
|
- lib/open_weather/models/weather.rb
|
98
118
|
- lib/open_weather/models/wind.rb
|
@@ -103,7 +123,7 @@ homepage: http://github.com/dblock/open-weather-ruby-client
|
|
103
123
|
licenses:
|
104
124
|
- MIT
|
105
125
|
metadata: {}
|
106
|
-
post_install_message:
|
126
|
+
post_install_message:
|
107
127
|
rdoc_options: []
|
108
128
|
require_paths:
|
109
129
|
- lib
|
@@ -118,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
138
|
- !ruby/object:Gem::Version
|
119
139
|
version: 1.3.6
|
120
140
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
122
|
-
signing_key:
|
141
|
+
rubygems_version: 3.1.3
|
142
|
+
signing_key:
|
123
143
|
specification_version: 4
|
124
144
|
summary: OpenWeather API Ruby client.
|
125
145
|
test_files: []
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenWeather
|
4
|
-
module Models
|
5
|
-
class CityWeather < Model
|
6
|
-
property 'coord', transform_with: ->(v) { OpenWeather::Models::Coord.new(v) }
|
7
|
-
property 'weather', transform_with: ->(v) { v.map { |i| OpenWeather::Models::Weather.new(i) } }
|
8
|
-
property 'base' # internal parameter
|
9
|
-
property 'main', transform_with: ->(v) { OpenWeather::Models::Main.new(v) }
|
10
|
-
property 'visibility'
|
11
|
-
property 'wind', transform_with: ->(v) { OpenWeather::Models::Wind.new(v) }
|
12
|
-
property 'clouds', transform_with: ->(v) { OpenWeather::Models::Clouds.new(v) }
|
13
|
-
property 'rain', transform_with: ->(v) { OpenWeather::Models::Rain.new(v) }
|
14
|
-
property 'snow', transform_with: ->(v) { OpenWeather::Models::Snow.new(v) }
|
15
|
-
property 'dt', transform_with: ->(v) { Time.at(v).utc } # time of data calculation, UTC
|
16
|
-
property 'sys', transform_with: ->(v) { OpenWeather::Models::Sys.new(v) }
|
17
|
-
property 'id' # city id
|
18
|
-
property 'timezone' # shift in seconds from UTC
|
19
|
-
property 'name' # city name
|
20
|
-
property 'cod' # internal parameter
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|