open-weather-ruby-client 0.7.0 → 0.8.1
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 +4 -4
- data/CHANGELOG.md +16 -1
- data/README.md +30 -336
- data/lib/open-weather-ruby-client.rb +1 -0
- data/lib/open_weather/client.rb +1 -0
- data/lib/open_weather/config.rb +2 -0
- data/lib/open_weather/endpoints/geocoding.rb +37 -0
- data/lib/open_weather/endpoints.rb +1 -0
- data/lib/open_weather/models/geo_location.rb +14 -0
- data/lib/open_weather/models/geo_location_zip.rb +13 -0
- data/lib/open_weather/models/mixins/temp.rb +4 -4
- data/lib/open_weather/models/model.rb +18 -2
- data/lib/open_weather/models/weather.rb +6 -1
- data/lib/open_weather/models.rb +2 -0
- data/lib/open_weather/version.rb +1 -1
- metadata +20 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6a1d8500eb96ae00c27608e53223cdb9cbc3ab8fd5f2344a12b760d9e37c3613
|
|
4
|
+
data.tar.gz: 86e3df5f13df2e365fb431d477379c80362bd34e2cd882419f3815c3f28c6ddd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 810123c712145a3efdb1b9299abc7df23a4102be9897872eef11572427d0631e0cc8adea63d331eb8f1514d35dd0b598c193ae07bb1fb22efefcee2300993d17
|
|
7
|
+
data.tar.gz: c277622f792ec918bda5b801f608163bcef945713c82d93aa717bec2edb730fa2e58c83b778831393f37e04207d08b1b56ff3089f35cef94a91e7d8ef182f53b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
### 0.
|
|
1
|
+
### 0.8.1 (2026/11/24)
|
|
2
|
+
|
|
3
|
+
* [#57](https://github.com/dblock/open-weather-ruby-client/pull/57): Fixes `min`, `max` and `zip` with `hashie` >= 6.0, adds Appraisals (`hashie-5`, `hashie-6`) - [@dblock](https://github.com/dblock).
|
|
4
|
+
* [#58](https://github.com/dblock/open-weather-ruby-client/pull/58): Speeds up CI by reporting coverage from the Ruby 3.4 test job instead of a separate run, skipping duplicate push builds of PR branches, canceling superseded PR builds and using `JRUBY_OPTS=--dev`, and upgrades to [danger-pr-comment](https://github.com/danger/danger-pr-comment) 0.3.0 - [@dblock](https://github.com/dblock).
|
|
5
|
+
* [#59](https://github.com/dblock/open-weather-ruby-client/pull/59): Adds `rake benchmark`, speeds up responses 10-20% by not copying models' String keys and caching weather icon URIs, which are now frozen - [@dblock](https://github.com/dblock).
|
|
6
|
+
* [#60](https://github.com/dblock/open-weather-ruby-client/pull/60): Releases with [ruby-gem-release](https://github.com/dblock/ruby-gem-release) and RubyGems Trusted Publishing - [@dblock](https://github.com/dblock).
|
|
7
|
+
* [#61](https://github.com/dblock/open-weather-ruby-client/pull/61): Simplifies README usage, moves the API reference to [docs/USAGE.md](docs/USAGE.md) and fixes the units, language and wind speed examples - [@dblock](https://github.com/dblock).
|
|
8
|
+
|
|
9
|
+
### 0.8.0 (2026/10/09)
|
|
10
|
+
|
|
11
|
+
* [#54](https://github.com/dblock/open-weather-ruby-client/pull/54): Add support for the Geocoding API (`geo_direct`, `geo_reverse`, `geo_zip`) - [@dblock](https://github.com/dblock).
|
|
12
|
+
* [#50](https://github.com/dblock/open-weather-ruby-client/pull/50): Fixes `Danger Comment` workflow failing with a `contents: none` permissions error - [@dblock](https://github.com/dblock).
|
|
13
|
+
* [#51](https://github.com/dblock/open-weather-ruby-client/pull/51): Adds test coverage reporting with [coveralls.io](https://coveralls.io) - [@dblock](https://github.com/dblock).
|
|
14
|
+
* [#53](https://github.com/dblock/open-weather-ruby-client/pull/53): Fixed coverage reporting to Coveralls not running on pull requests by switching from `coveralls_reborn`/`COVERALLS_REPO_TOKEN` to `coverallsapp/github-action`/`GITHUB_TOKEN` - [@dblock](https://github.com/dblock).
|
|
15
|
+
* [#56](https://github.com/dblock/open-weather-ruby-client/pull/56): Correct spelling of Celsius and Fahrenheit - [@dblock](https://github.com/dblock).
|
|
16
|
+
### 0.7.0 (2026/8/23)
|
|
2
17
|
|
|
3
18
|
* [#49](https://github.com/dblock/open-weather-ruby-client/pull/49): Migrate Danger to use the `danger-pr-comment` reusable workflow - [@dblock](https://github.com/dblock), [@Copilot](https://github.com/apps/copilot-swe-agent).
|
|
4
19
|
* [#49](https://github.com/dblock/open-weather-ruby-client/pull/49): Upgrade danger-changelog to 0.8.0 and danger-toc to 0.2.0 - [@dblock](https://github.com/dblock), [@Copilot](https://github.com/apps/copilot-swe-agent).
|
data/README.md
CHANGED
|
@@ -3,34 +3,19 @@ OpenWeather Ruby Client
|
|
|
3
3
|
|
|
4
4
|
[](https://badge.fury.io/rb/open-weather-ruby-client)
|
|
5
5
|
[](https://github.com/dblock/open-weather-ruby-client/actions/workflows/test.yml)
|
|
6
|
+
[](https://coveralls.io/github/dblock/open-weather-ruby-client?branch=master)
|
|
6
7
|
|
|
7
8
|
A Ruby client for the [OpenWeather API v2.5 and v3.0](https://openweathermap.org/api).
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
It provides rich OpenWeather models with structured timestamps, temperature and wind speed conversion, and consistent error handling, and is tested with actual OpenWeather data.
|
|
10
11
|
|
|
11
12
|
## Table of Contents
|
|
12
13
|
|
|
13
14
|
- [Installation](#installation)
|
|
14
15
|
- [Usage](#usage)
|
|
15
16
|
- [Current Weather](#current-weather)
|
|
16
|
-
- [
|
|
17
|
-
|
|
18
|
-
- [Cities Within a Circle](#cities-within-a-circle)
|
|
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
|
-
- [Hourly Forecast (Pro)](#hourly-forecast-pro)
|
|
24
|
-
- [30 Day Forecast (Pro)](#30-day-forecast-pro)
|
|
25
|
-
- [5 Day Forecast](#5-day-forecast)
|
|
26
|
-
- [Stations](#stations)
|
|
27
|
-
- [Register a Station](#register-a-station)
|
|
28
|
-
- [List Stations](#list-stations)
|
|
29
|
-
- [Get Station](#get-station)
|
|
30
|
-
- [Update Station](#update-station)
|
|
31
|
-
- [Delete Station](#delete-station)
|
|
32
|
-
- [Create Measurements](#create-measurements)
|
|
33
|
-
- [Get Measurements](#get-measurements)
|
|
17
|
+
- [Forecasts](#forecasts)
|
|
18
|
+
- [More](#more)
|
|
34
19
|
- [Configuration](#configuration)
|
|
35
20
|
- [Units](#units)
|
|
36
21
|
- [Converting Temperature](#converting-temperature)
|
|
@@ -53,331 +38,40 @@ Run `bundle install`.
|
|
|
53
38
|
|
|
54
39
|
## Usage
|
|
55
40
|
|
|
56
|
-
|
|
41
|
+
Get an API key from [API Keys](https://home.openweathermap.org/api_keys) on the OpenWeather website after registration.
|
|
57
42
|
|
|
58
43
|
```ruby
|
|
59
|
-
client = OpenWeather::Client.new(
|
|
60
|
-
api_key: "1a2b3c4d5a6b7c8d9a8b7c6d5a4b3c2d1"
|
|
61
|
-
)
|
|
44
|
+
client = OpenWeather::Client.new(api_key: ENV['OPEN_WEATHER_API_KEY'])
|
|
62
45
|
```
|
|
63
46
|
|
|
64
47
|
### Current Weather
|
|
65
48
|
|
|
66
|
-
Returns [current weather](https://openweathermap.org/current).
|
|
67
|
-
|
|
68
49
|
```ruby
|
|
69
50
|
data = client.current_weather(city: 'London') # => OpenWeather::Models::City::Weather
|
|
70
51
|
|
|
71
52
|
data.name # => 'London'
|
|
72
53
|
data.dt # => Time
|
|
73
|
-
data.main.
|
|
74
|
-
data.main.
|
|
75
|
-
data.
|
|
76
|
-
data.main.temp # => 282.57
|
|
77
|
-
data.main.temp_max # => 283.15, degrees Kelvin
|
|
78
|
-
data.main.temp_max_c # => 10, degrees Celcius
|
|
79
|
-
data.main.temp_max_f # => 50.0, degrees Farenheit
|
|
80
|
-
data.main.temp_min # => 281.48
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Returns the current weather in metric units and Russian metadata.
|
|
84
|
-
|
|
85
|
-
```ruby
|
|
86
|
-
data = client.current_weather(city: 'Moscow', units: 'metric', lang: 'ru') # => OpenWeather::Models::City::Weather
|
|
87
|
-
|
|
88
|
-
data.name # => 'Москва'
|
|
89
|
-
data.main.temp # => 12
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Returns weather by city, optional state (in the US) and optional ISO 3166 country code.
|
|
93
|
-
Names that cannot be resolved will cause the API call to raise a `Faraday::ResourceNotFound` error.
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
client.current_city('Sydney')
|
|
97
|
-
client.current_city('London, UK')
|
|
98
|
-
client.current_city('London', 'UK')
|
|
99
|
-
client.current_city('Albany')
|
|
100
|
-
client.current_city('Albany, New York')
|
|
101
|
-
client.current_city('Albany, New York', 'US')
|
|
102
|
-
client.current_city('Albany, NY', 'US')
|
|
103
|
-
client.current_city('Albany', 'New York', 'US')
|
|
104
|
-
client.current_city('Albany', 'NY', 'US')
|
|
105
|
-
client.current_city('Albany', 'NY') # 2-letter state abbreviation w/o country will raise Faraday::ResourceNotFound
|
|
106
|
-
|
|
107
|
-
client.current_weather(city: 'Albany', state: 'NY', country: 'US')
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Returns weather by city ID.
|
|
111
|
-
|
|
112
|
-
```ruby
|
|
113
|
-
client.current_city_id(2643743) # => weather in London
|
|
114
|
-
client.current_weather(id: 2643743) # => weather in London
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Returns weather by latitude and longitude.
|
|
118
|
-
|
|
119
|
-
```ruby
|
|
120
|
-
client.current_geo(51.51, -0.13) # => weather in London
|
|
121
|
-
client.current_weather(lat: 51.51, lon: -0.13) # => weather in London
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Returns weather by zip code with an optional country code (defaults to US).
|
|
125
|
-
|
|
126
|
-
```ruby
|
|
127
|
-
client.current_zip(10018, 'US') # => weather in New York, 10018
|
|
128
|
-
client.current_weather(zip: 10018, country: 'US') # => weather in New York, 10018
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
See [OpenWeather::Models::City::Weather](lib/open_weather/models/city/weather.rb) and related [OpenWeather::Models](lib/open_weather/models) for all available properties.
|
|
132
|
-
|
|
133
|
-
### Current Weather for Several Cities
|
|
134
|
-
|
|
135
|
-
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).
|
|
136
|
-
|
|
137
|
-
#### Cities Within a Rectangle Zone
|
|
138
|
-
|
|
139
|
-
```ruby
|
|
140
|
-
data = client.current_cities_geo_box(12, 32, 15, 37, 10) # => OpenWeather::Models::List
|
|
141
|
-
|
|
142
|
-
data.first.name # 'Birkirkara'
|
|
143
|
-
data.main.temp # => 16.23
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
You can optionally name parameters.
|
|
147
|
-
|
|
148
|
-
```ruby
|
|
149
|
-
client.current_cities_geo_box(lon_left: 12, lat_bottom: 32, lon_right: 15, lat_top: 37, zoom: 10) # => OpenWeather::Models::List
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
You can use server clustering of points with `cluster: true`.
|
|
153
|
-
|
|
154
|
-
```ruby
|
|
155
|
-
client.current_cities_geo_box(12, 32, 15, 37, 10, cluster: true) # => OpenWeather::Models::List
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### Cities Within a Circle
|
|
159
|
-
|
|
160
|
-
```ruby
|
|
161
|
-
data = client.current_cities_geo_circle(55.5, 37.5, 10) # => OpenWeather::Models::List
|
|
162
|
-
|
|
163
|
-
data.first.name # 'Shcherbinka'
|
|
164
|
-
data.main.temp # => 276.86
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
You can optionally name parameters.
|
|
168
|
-
|
|
169
|
-
```ruby
|
|
170
|
-
client.current_cities_geo_circle(lat: 55.5, lon: 37.5, cnt: 7) # => OpenWeather::Models::List
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
#### Multiple Cities by Id
|
|
174
|
-
|
|
175
|
-
```ruby
|
|
176
|
-
data = client.current_cities_id(524901, 703448, 2643743) # => OpenWeather::Models::List
|
|
177
|
-
|
|
178
|
-
data.first.name # 'Moscow'
|
|
179
|
-
data.main.temp # => 285.15
|
|
54
|
+
data.main.temp # => 282.57, degrees Kelvin by default
|
|
55
|
+
data.main.temp_c # => 9.42, degrees Celsius
|
|
56
|
+
data.weather.first.description # => 'light rain'
|
|
180
57
|
```
|
|
181
58
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
[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.
|
|
59
|
+
Look up weather by city and country (`city: 'London', country: 'UK'`), id (`id: 2643743`), coordinates (`lat: 51.51, lon: -0.13`) or zip code (`zip: 10018, country: 'US'`).
|
|
185
60
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
#### Current and Forecast Weather
|
|
61
|
+
### Forecasts
|
|
189
62
|
|
|
190
63
|
```ruby
|
|
191
|
-
data = client.one_call(lat: 33.
|
|
64
|
+
data = client.one_call(lat: 33.5312, lon: -111.9426) # => OpenWeather::Models::OneCall::Weather
|
|
192
65
|
|
|
193
|
-
data.
|
|
194
|
-
data.lon # => -94.04
|
|
195
|
-
data.timezone # => 'America/Chicago'
|
|
66
|
+
data.timezone # => 'America/Phoenix'
|
|
196
67
|
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
|
197
|
-
data.
|
|
198
|
-
data.minutely # => Array[OpenWeather::Models::OneCall::MinutelyWeather]
|
|
199
|
-
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
|
68
|
+
data.hourly.first.temp # => 289.2
|
|
200
69
|
data.daily # => Array[OpenWeather::Models::OneCall::DailyWeather]
|
|
201
|
-
data.alerts # => Array[OpenWeather::Models::OneCall::Alert]
|
|
202
70
|
```
|
|
203
71
|
|
|
204
|
-
|
|
72
|
+
### More
|
|
205
73
|
|
|
206
|
-
|
|
207
|
-
client.one_call(lat: 33.441792, lon: -94.037689, exclude: ['minutely', 'hourly'])
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
#### Historical Weather
|
|
211
|
-
|
|
212
|
-
```ruby
|
|
213
|
-
data = client.one_call(lat: 33.441792, lon: -94.037689, dt: Time.now - 24 * 60 * 60) # => OpenWeather::Models::OneCall::Weather
|
|
214
|
-
|
|
215
|
-
data.lat # => 33.44
|
|
216
|
-
data.lon # => -94.04
|
|
217
|
-
data.timezone # => 'America/Chicago'
|
|
218
|
-
data.current # => OpenWeather::Models::OneCall::CurrentWeather
|
|
219
|
-
data.hourly # => Array[OpenWeather::Models::OneCall::HourlyWeather]
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Hourly Forecast (Pro)
|
|
223
|
-
|
|
224
|
-
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).
|
|
225
|
-
|
|
226
|
-
```ruby
|
|
227
|
-
data = client.client.hourly(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::Hourly
|
|
228
|
-
|
|
229
|
-
data.cnt # => 96 (number of entries)
|
|
230
|
-
data.city # => OpenWeather::Models::Forecast::City
|
|
231
|
-
data.list.first # => OpenWeather::Models::Forecast::Forecast
|
|
232
|
-
data.list.first.dt # => Time
|
|
233
|
-
data.list.first.main # => OpenWeather::Models::Forecast::Main
|
|
234
|
-
data.list.first.weather # => Array[OpenWeather::Models::Forecast::Weather]
|
|
235
|
-
data.list.first.clouds # => OpenWeather::Models::Forecast::Clouds or nil
|
|
236
|
-
data.list.first.wind # => OpenWeather::Models::Forecast::Wind or nil
|
|
237
|
-
data.list.first.visibility # => 10000
|
|
238
|
-
data.list.first.pop # => 0.1 (probability of precipitation from 0.0 to 1.0 (0% to 100%))
|
|
239
|
-
data.list.first.rain # => OpenWeather::Models::Forecast::Rain or nil
|
|
240
|
-
data.list.first.snow # => OpenWeather::Models::Forecast::Snow or nil
|
|
241
|
-
data.list.first.sys # => OpenWeather::Models::Forecast::Sys or nil
|
|
242
|
-
data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
### 30 Day Forecast (Pro)
|
|
246
|
-
|
|
247
|
-
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).
|
|
248
|
-
|
|
249
|
-
```ruby
|
|
250
|
-
data = client.client.forecast(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::ThirtyDay::ThirtyDay
|
|
251
|
-
|
|
252
|
-
data.cnt # => 30 (number of entries - sometimes this is 29)
|
|
253
|
-
data.city # => OpenWeather::Models::Forecast::City
|
|
254
|
-
data.list.first # => OpenWeather::Models::Forecast::ThirtyDay::Forecast
|
|
255
|
-
data.list.first.dt # => Time - time of data forcasted, UTC
|
|
256
|
-
data.list.first.sunrise # => Time - Sunrise time, UTC
|
|
257
|
-
data.list.first.sunset # => Time - Sunset time, UTC
|
|
258
|
-
data.list.first.temp # => OpenWeather::Models::Forecast::ThirtyDay::Temp
|
|
259
|
-
data.list.first.feels_like # => OpenWeather::Models::OneCall::FeelsLike
|
|
260
|
-
data.list.first.pressure # => int - Atmospheric pressure on the sea level, hPa
|
|
261
|
-
data.list.first.humidity # => int - Humidity, % (e.g. integer 24 means 24% cloudiness)
|
|
262
|
-
data.list.first.weather # => Array[OpenWeather::Models::Weather]
|
|
263
|
-
data.list.first.speed # => double - Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
|
264
|
-
data.list.first.deg # => int - Wind direction, degrees (meteorological)
|
|
265
|
-
data.list.first.clouds # => int - Cloudiness, % (e.g. integer 78 means 78% cloudiness)
|
|
266
|
-
data.list.first.rain # => double or nil - Precipitation volume, mm. Please note that only mm as units of measurement are available for this parameter
|
|
267
|
-
data.list.first.snow # => double or nil - Snow volume, mm. Please note that only mm as units of measurement are available for this parameter
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### 5 Day Forecast
|
|
271
|
-
|
|
272
|
-
The [5 Day Forecast API](https://openweathermap.org/forecast5) provides weather forecast for 5 days with data every 3 hours by geographic coordinates.
|
|
273
|
-
|
|
274
|
-
```ruby
|
|
275
|
-
data = client.client.five_day_forecast(lat: 33.5312, lon: -111.9426, appid: "<your api key>") # => OpenWeather::Models::Forecast::FiveDay
|
|
276
|
-
|
|
277
|
-
data.cnt # => 40 (number of entries)
|
|
278
|
-
data.list.first # => OpenWeather::Models::Forecast::FiveDay::Forecast
|
|
279
|
-
data.list.first.dt # => Time
|
|
280
|
-
data.list.first.main # => OpenWeather::Models::Main
|
|
281
|
-
data.list.first.weather # => Array[OpenWeather::Models::Weather]
|
|
282
|
-
data.list.first.clouds # => OpenWeather::Models::Clouds or nil
|
|
283
|
-
data.list.first.wind # => OpenWeather::Models::Wind or nil
|
|
284
|
-
data.list.first.visibility # => 10000
|
|
285
|
-
data.list.first.pop # => 0.1 (probability of precipitation from 0.0 to 1.0 (0% to 100%))
|
|
286
|
-
data.list.first.rain # => OpenWeather::Models::Rain or nil
|
|
287
|
-
data.list.first.snow # => OpenWeather::Models::Snow or nil
|
|
288
|
-
data.list.first.sys # => OpenWeather::Models::Sys or nil
|
|
289
|
-
data.list.first.dt_txt # => String (Time of data forecasted, ISO, UTC)
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Stations
|
|
293
|
-
|
|
294
|
-
The [Stations API](https://openweathermap.org/stations) lets your manage personal weather stations and measurements.
|
|
295
|
-
|
|
296
|
-
#### Register a Station
|
|
297
|
-
|
|
298
|
-
To register a station, you can call the client method:
|
|
299
|
-
```ruby
|
|
300
|
-
data = client.register_station(external_id: 'SF_TEST001', ...) # => OpenWeather::Models::Station
|
|
301
|
-
data.id # => '5ed2118acca8ce0001f1aeg1'
|
|
302
|
-
data.external_id # => 'SF_TEST001'
|
|
303
|
-
```
|
|
304
|
-
Alternatively, call `register!` on an instance of `Station`:
|
|
305
|
-
```ruby
|
|
306
|
-
model = OpenWeather::Models::Station.new(external_id: 'SF_TEST001', ...)
|
|
307
|
-
model.register!
|
|
308
|
-
model.id # => '5ed2118acca8ce0001f1aeg1'
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
#### List Stations
|
|
312
|
-
|
|
313
|
-
To list all stations, call the client method:
|
|
314
|
-
```ruby
|
|
315
|
-
client.list_stations # => Array[OpenWeather::Models::Station]
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
#### Get Station
|
|
319
|
-
|
|
320
|
-
To get a station, call the client method:
|
|
321
|
-
```ruby
|
|
322
|
-
client.get_station('5ed2118acca8ce0001f1aeg1') # => OpenWeather::Models::Station
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
#### Update Station
|
|
326
|
-
|
|
327
|
-
To update a station, call the client method:
|
|
328
|
-
```ruby
|
|
329
|
-
client.update_station('5ed2118acca8ce0001f1aeg1', external_id: 'SF_TEST002') # => OpenWeather::Models::Station
|
|
330
|
-
```
|
|
331
|
-
Alternatively, call `update!` on an instance of `Station`:
|
|
332
|
-
```ruby
|
|
333
|
-
model = OpenWeather::Models::Station.new(external_id: 'SF_TEST001', ...)
|
|
334
|
-
model.register!
|
|
335
|
-
model.update!(external_id: 'SF_TEST002')
|
|
336
|
-
model.external_id # => 'SF_TEST002'
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
#### Delete Station
|
|
340
|
-
|
|
341
|
-
To delete a station, call the client method:
|
|
342
|
-
```ruby
|
|
343
|
-
data = client.delete_station('5ed2118acca8ce0001f1aeg1') # => nil
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
#### Create Measurements
|
|
347
|
-
|
|
348
|
-
To create measurements, call the client method:
|
|
349
|
-
```ruby
|
|
350
|
-
client.create_measurements([
|
|
351
|
-
{
|
|
352
|
-
"station_id": -1,
|
|
353
|
-
"dt": 1479817340,
|
|
354
|
-
"temperature": 18.7,
|
|
355
|
-
"wind_speed": 1.2,
|
|
356
|
-
"wind_gust": 3.4,
|
|
357
|
-
"pressure": 1021,
|
|
358
|
-
"humidity": 87,
|
|
359
|
-
"rain_1h": 2,
|
|
360
|
-
"clouds": [
|
|
361
|
-
{
|
|
362
|
-
"condition": 'NSC'
|
|
363
|
-
}
|
|
364
|
-
]
|
|
365
|
-
}
|
|
366
|
-
]) # => nil
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
#### Get Measurements
|
|
370
|
-
|
|
371
|
-
To get measurements, call the client method with the required parameters:
|
|
372
|
-
```ruby
|
|
373
|
-
client.get_measurements(
|
|
374
|
-
station_id: '5ed21a12cca8ce0001f1aef1',
|
|
375
|
-
type: 'd',
|
|
376
|
-
limit: 100,
|
|
377
|
-
from: 1469817340,
|
|
378
|
-
to: 1591620047
|
|
379
|
-
) # => Array[OpenWeather::Models::Stations::Measurement]
|
|
380
|
-
```
|
|
74
|
+
See [docs/USAGE.md](docs/USAGE.md) for all APIs, including weather for several cities, One Call history, hourly, 5 day and 30 day forecasts, stations and geocoding.
|
|
381
75
|
|
|
382
76
|
## Configuration
|
|
383
77
|
|
|
@@ -411,9 +105,9 @@ The following settings are supported.
|
|
|
411
105
|
The OpenWeather API returns responses in `standard`, `metric`, and `imperial` units. You can pass `units` into API requests or configure the desired units globally.
|
|
412
106
|
|
|
413
107
|
```ruby
|
|
414
|
-
data = client.
|
|
108
|
+
data = client.current_weather(id: 2643743, units: 'metric')
|
|
415
109
|
data.name # => 'London'
|
|
416
|
-
data.main.temp # => 12, degrees
|
|
110
|
+
data.main.temp # => 12, degrees Celsius
|
|
417
111
|
```
|
|
418
112
|
|
|
419
113
|
```ruby
|
|
@@ -421,32 +115,32 @@ OpenWeather.configure do |config|
|
|
|
421
115
|
config.units = 'metric'
|
|
422
116
|
end
|
|
423
117
|
|
|
424
|
-
data = client.
|
|
118
|
+
data = client.current_weather(id: 2643743)
|
|
425
119
|
data.name # => 'London'
|
|
426
|
-
data.main.temp # => 12, degrees
|
|
120
|
+
data.main.temp # => 12, degrees Celsius
|
|
427
121
|
```
|
|
428
122
|
|
|
429
123
|
#### Converting Temperature
|
|
430
124
|
|
|
431
|
-
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
|
|
125
|
+
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 Celsius and `_f` for Fahrenheit.
|
|
432
126
|
|
|
433
127
|
```ruby
|
|
434
128
|
data = client.current_weather(city: 'Moscow', units: 'metric') # => OpenWeather::Models::City::Weather
|
|
435
129
|
|
|
436
|
-
data.main.temp_max # => 12, degrees
|
|
437
|
-
data.main.temp_max_c # => 12, degrees
|
|
130
|
+
data.main.temp_max # => 12, degrees Celsius, metric as requested
|
|
131
|
+
data.main.temp_max_c # => 12, degrees Celsius
|
|
438
132
|
data.main.temp_max_k # => 285.15, degrees Kelvin
|
|
439
|
-
data.main.temp_max_f # => 53.6, degrees
|
|
133
|
+
data.main.temp_max_f # => 53.6, degrees Fahrenheit
|
|
440
134
|
```
|
|
441
135
|
|
|
442
136
|
#### Converting Wind Speed
|
|
443
137
|
|
|
444
|
-
Use `_mps` for wind speed in meters
|
|
138
|
+
Use `_mps` for wind speed in meters per second, and `_mph` for miles per hour.
|
|
445
139
|
|
|
446
140
|
```ruby
|
|
447
141
|
data.wind.speed # => 3, in meters per second, metric as requested
|
|
448
|
-
data.
|
|
449
|
-
data.
|
|
142
|
+
data.wind.speed_mph # => 6.71, miles per hour
|
|
143
|
+
data.wind.speed_mps # => 3, meters per second
|
|
450
144
|
```
|
|
451
145
|
|
|
452
146
|
### Language
|
|
@@ -454,7 +148,7 @@ data.main.speed_mps # 3, meters per second
|
|
|
454
148
|
The OpenWeather API returns responses in English and supports many other languages. You can pass `lang` into API requests or configure the desired language globally.
|
|
455
149
|
|
|
456
150
|
```ruby
|
|
457
|
-
data = client.
|
|
151
|
+
data = client.current_weather(id: 2643743, lang: 'ru')
|
|
458
152
|
data.name # => 'Лондон'
|
|
459
153
|
```
|
|
460
154
|
|
|
@@ -463,7 +157,7 @@ OpenWeather.configure do |config|
|
|
|
463
157
|
config.lang = 'ru'
|
|
464
158
|
end
|
|
465
159
|
|
|
466
|
-
data = client.
|
|
160
|
+
data = client.current_weather(id: 2643743)
|
|
467
161
|
data.name # => 'Лондон'
|
|
468
162
|
```
|
|
469
163
|
|
|
@@ -477,7 +171,7 @@ All errors that return HTTP codes 400-600 result in either `Faraday::ResourceNot
|
|
|
477
171
|
|
|
478
172
|
## Contributing
|
|
479
173
|
|
|
480
|
-
See [CONTRIBUTING](CONTRIBUTING.md).
|
|
174
|
+
See [CONTRIBUTING](CONTRIBUTING.md), [CHANGELOG](CHANGELOG.md), [UPGRADING](UPGRADING.md) and [RELEASING](RELEASING.md).
|
|
481
175
|
|
|
482
176
|
## Copyright and License
|
|
483
177
|
|
data/lib/open_weather/client.rb
CHANGED
data/lib/open_weather/config.rb
CHANGED
|
@@ -7,6 +7,7 @@ module OpenWeather
|
|
|
7
7
|
ATTRIBUTES = %i[
|
|
8
8
|
endpoint
|
|
9
9
|
pro_endpoint
|
|
10
|
+
geo_endpoint
|
|
10
11
|
api_key
|
|
11
12
|
proxy
|
|
12
13
|
user_agent
|
|
@@ -24,6 +25,7 @@ module OpenWeather
|
|
|
24
25
|
def reset
|
|
25
26
|
self.endpoint = 'https://api.openweathermap.org/data'
|
|
26
27
|
self.pro_endpoint = 'https://pro.openweathermap.org/data'
|
|
28
|
+
self.geo_endpoint = 'https://api.openweathermap.org/geo'
|
|
27
29
|
self.api_key = nil
|
|
28
30
|
self.user_agent = "OpenWeather Ruby Client/#{OpenWeather::VERSION}"
|
|
29
31
|
self.ca_path = nil
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenWeather
|
|
4
|
+
module Endpoints
|
|
5
|
+
module Geocoding
|
|
6
|
+
def geo_direct(name, state = nil, country = nil, options = {})
|
|
7
|
+
options = name.is_a?(Hash) ? options.merge(name) : options.merge(city: name, state: state, country: country)
|
|
8
|
+
options[:q] = [
|
|
9
|
+
options.delete(:city),
|
|
10
|
+
options.delete(:state),
|
|
11
|
+
options.delete(:country)
|
|
12
|
+
].compact.join(',')
|
|
13
|
+
options[:endpoint] ||= geo_endpoint
|
|
14
|
+
|
|
15
|
+
get('1.0/direct', options).map { |data| OpenWeather::Models::GeoLocation.new(data) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def geo_reverse(lat, lon = nil, options = {})
|
|
19
|
+
options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon)
|
|
20
|
+
options[:endpoint] ||= geo_endpoint
|
|
21
|
+
|
|
22
|
+
get('1.0/reverse', options).map { |data| OpenWeather::Models::GeoLocation.new(data) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def geo_zip(code, country = nil, options = {})
|
|
26
|
+
options = code.is_a?(Hash) ? options.merge(code) : options.merge(zip: code, country: country)
|
|
27
|
+
options[:zip] = [
|
|
28
|
+
options.delete(:zip),
|
|
29
|
+
options.delete(:country)
|
|
30
|
+
].compact.join(',')
|
|
31
|
+
options[:endpoint] ||= geo_endpoint
|
|
32
|
+
|
|
33
|
+
OpenWeather::Models::GeoLocationZip.new(get('1.0/zip', options))
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenWeather
|
|
4
|
+
module Models
|
|
5
|
+
class GeoLocation < Model
|
|
6
|
+
property 'name' # name of the found location
|
|
7
|
+
property 'local_names' # name of the found location in different languages
|
|
8
|
+
property 'lat' # geo location, latitude
|
|
9
|
+
property 'lon' # geo location, longitude
|
|
10
|
+
property 'country' # country of the found location
|
|
11
|
+
property 'state' # state of the found location
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenWeather
|
|
4
|
+
module Models
|
|
5
|
+
class GeoLocationZip < Model
|
|
6
|
+
property 'zip' # zip/post code
|
|
7
|
+
property 'name' # name of the found location
|
|
8
|
+
property 'lat' # geo location, latitude
|
|
9
|
+
property 'lon' # geo location, longitude
|
|
10
|
+
property 'country' # country of the found location
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -15,11 +15,11 @@ module OpenWeather
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
define_method "#{field}_c" do
|
|
18
|
-
|
|
18
|
+
to_celsius(send(field))
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
define_method "#{field}_f" do
|
|
22
|
-
|
|
22
|
+
to_fahrenheit(send(field))
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -37,7 +37,7 @@ module OpenWeather
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def
|
|
40
|
+
def to_celsius(value)
|
|
41
41
|
case units
|
|
42
42
|
when :metric
|
|
43
43
|
value
|
|
@@ -48,7 +48,7 @@ module OpenWeather
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
def
|
|
51
|
+
def to_fahrenheit(value)
|
|
52
52
|
case units
|
|
53
53
|
when :metric
|
|
54
54
|
((value.to_f * 9 / 5) + 32).round(2)
|
|
@@ -9,9 +9,25 @@ module OpenWeather
|
|
|
9
9
|
|
|
10
10
|
attr_reader :options
|
|
11
11
|
|
|
12
|
+
# Hashie >= 6 does not define property readers that conflict with existing methods,
|
|
13
|
+
# such as `min`, `max` and `zip`.
|
|
14
|
+
if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new('6.0')
|
|
15
|
+
def self.property(property_name, options = {})
|
|
16
|
+
conflict = method_defined?(property_name) || private_method_defined?(property_name)
|
|
17
|
+
super
|
|
18
|
+
define_method(property_name) { self[property_name] } if conflict
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Parsed JSON already has String keys, so only copy a Hash that does not.
|
|
23
|
+
def self.string_keys(args)
|
|
24
|
+
return args unless args.respond_to?(:transform_keys) && !args.each_key.all?(String)
|
|
25
|
+
|
|
26
|
+
args.transform_keys(&:to_s)
|
|
27
|
+
end
|
|
28
|
+
|
|
12
29
|
def initialize(args = nil, options = {})
|
|
13
|
-
|
|
14
|
-
super transformed_args
|
|
30
|
+
super(self.class.string_keys(args))
|
|
15
31
|
@options = { units: OpenWeather.config.units }.merge(options || {})
|
|
16
32
|
end
|
|
17
33
|
|
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
module OpenWeather
|
|
4
4
|
module Models
|
|
5
5
|
class Weather < Model
|
|
6
|
+
# Icon URIs by icon id, shared and frozen since there are only a few icons.
|
|
7
|
+
ICON_URIS = Concurrent::Map.new
|
|
8
|
+
|
|
6
9
|
property 'id' # weather condition id
|
|
7
10
|
property 'main' # group of weather parameters (Rain, Snow, Extreme, etc.)
|
|
8
11
|
property 'description' # weather condition within the group, in your language
|
|
9
|
-
property 'icon_uri', from: 'icon', transform_with:
|
|
12
|
+
property 'icon_uri', from: 'icon', transform_with: lambda { |v|
|
|
13
|
+
ICON_URIS.compute_if_absent(v) { URI.parse("http://openweathermap.org/img/wn/#{v}@2x.png").freeze }
|
|
14
|
+
}
|
|
10
15
|
property 'icon' # weather icon id
|
|
11
16
|
end
|
|
12
17
|
end
|
data/lib/open_weather/models.rb
CHANGED
|
@@ -15,6 +15,8 @@ require_relative 'models/city'
|
|
|
15
15
|
require_relative 'models/one_call'
|
|
16
16
|
require_relative 'models/forecast'
|
|
17
17
|
require_relative 'models/station'
|
|
18
|
+
require_relative 'models/geo_location'
|
|
19
|
+
require_relative 'models/geo_location_zip'
|
|
18
20
|
require_relative 'models/stations/measurement'
|
|
19
21
|
require_relative 'models/stations/temp'
|
|
20
22
|
require_relative 'models/stations/humidity'
|
data/lib/open_weather/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Doubrovkine
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: concurrent-ruby
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: faraday
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -220,6 +234,7 @@ files:
|
|
|
220
234
|
- lib/open_weather/endpoints.rb
|
|
221
235
|
- lib/open_weather/endpoints/current.rb
|
|
222
236
|
- lib/open_weather/endpoints/five_day_forecast.rb
|
|
237
|
+
- lib/open_weather/endpoints/geocoding.rb
|
|
223
238
|
- lib/open_weather/endpoints/hourly.rb
|
|
224
239
|
- lib/open_weather/endpoints/one_call.rb
|
|
225
240
|
- lib/open_weather/endpoints/stations.rb
|
|
@@ -243,6 +258,8 @@ files:
|
|
|
243
258
|
- lib/open_weather/models/forecast/thirty_day/forecast.rb
|
|
244
259
|
- lib/open_weather/models/forecast/thirty_day/temp.rb
|
|
245
260
|
- lib/open_weather/models/forecast/thirty_day/thirty_day.rb
|
|
261
|
+
- lib/open_weather/models/geo_location.rb
|
|
262
|
+
- lib/open_weather/models/geo_location_zip.rb
|
|
246
263
|
- lib/open_weather/models/list.rb
|
|
247
264
|
- lib/open_weather/models/main.rb
|
|
248
265
|
- lib/open_weather/models/mixins.rb
|
|
@@ -290,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
290
307
|
- !ruby/object:Gem::Version
|
|
291
308
|
version: 1.3.6
|
|
292
309
|
requirements: []
|
|
293
|
-
rubygems_version:
|
|
310
|
+
rubygems_version: 3.6.9
|
|
294
311
|
specification_version: 4
|
|
295
312
|
summary: OpenWeather API Ruby client.
|
|
296
313
|
test_files: []
|