open_weather_client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/README.md +5 -0
- data/lib/open_weather_client/version.rb +1 -1
- data/lib/open_weather_client/weather.rb +10 -3
- data/lib/open_weather_client.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12179413a7acc81adc794dbce0fb22720169a34c3e010fd22bfb32258c55a818
|
4
|
+
data.tar.gz: 4ca9bf5b64e2e5a4493084bdb7b91750279f40bd97b49c60c01a9e538b7e7390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec49b4f16d5379f1a1f937184028ba6e332c966d6649f683d509132ce832660909b4ee89531675d1b9293dc170dba9228ba0127a69ac45ff54a642ee0d6c563f
|
7
|
+
data.tar.gz: 3c9aec3ddedd6c6e172a7d673bf8b6230ce1a6fa2dccf2c67b0cc9d0c0ad84eaef2798d1fa2d4387900e06cf2c01cd515cd2f5263b62dc05adfc99dbb9e12d30
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Open Weather Client Changelog
|
2
2
|
|
3
|
+
## 0.1.1
|
4
|
+
- Raise `OpenWeatherClient::AuthenticationError` if the request is not authorized
|
5
|
+
- - Raise `RangeError` if latitude or longitude is out of the allowed range
|
6
|
+
- Raise `Faraday::Error` if the request fails otherwise
|
7
|
+
|
3
8
|
## 0.1.0
|
4
9
|
- Initial commit of the Open Weather Client gem
|
5
10
|
- Configuration of OpenWeatherClient
|
data/README.md
CHANGED
@@ -35,6 +35,11 @@ end
|
|
35
35
|
OpenWeatherClient::Weather.current(lat: 50.3569, lon: 7.5890)
|
36
36
|
```
|
37
37
|
|
38
|
+
### Exceptions during requests
|
39
|
+
When an error occurs during a request, an exception is raised.
|
40
|
+
If the request is not authorized `OpenWeatherClient::AutheniticationError` is raied.
|
41
|
+
When attributes like latitude or longitude are outside of the expected range a `RangeError` is raised.
|
42
|
+
|
38
43
|
### Secure Configuration
|
39
44
|
In Rails provides the credentials functionality for [environmental security](https://edgeguides.rubyonrails.org/security.html#environmental-security). This mechanism can be used by OpenWeatherClient to load the API key from an encrypted file. This also allows easy separation of production and development channel configuration.
|
40
45
|
All settings are defined under the top-level entry `open_weather_client`.
|
@@ -3,6 +3,9 @@ require 'faraday'
|
|
3
3
|
module OpenWeatherClient
|
4
4
|
class Weather
|
5
5
|
def self.current(lat:, lon:)
|
6
|
+
raise RangeError unless (-90..90).member?(lat)
|
7
|
+
raise RangeError unless (-180..180).member?(lon)
|
8
|
+
|
6
9
|
connection = Faraday.new(
|
7
10
|
url: OpenWeatherClient.configuration.url,
|
8
11
|
params: {
|
@@ -16,12 +19,16 @@ module OpenWeatherClient
|
|
16
19
|
'User-Agent': OpenWeatherClient.configuration.user_agent
|
17
20
|
}
|
18
21
|
) do |f|
|
22
|
+
f.response :raise_error
|
19
23
|
f.response :json
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
begin
|
27
|
+
response = connection.get('2.5/weather')
|
28
|
+
response.body
|
29
|
+
rescue Faraday::UnauthorizedError
|
30
|
+
raise OpenWeatherClient::AuthenticationError
|
31
|
+
end
|
25
32
|
end
|
26
33
|
end
|
27
34
|
end
|
data/lib/open_weather_client.rb
CHANGED