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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e71860d474b67b88ec968c56ca18bfcd98029b9078bbd73fef481bd1dcf8736
4
- data.tar.gz: 8eb818af6393f4cbbac4dddea37800911ebe58a0dd10bc323f337251596cd088
3
+ metadata.gz: 12179413a7acc81adc794dbce0fb22720169a34c3e010fd22bfb32258c55a818
4
+ data.tar.gz: 4ca9bf5b64e2e5a4493084bdb7b91750279f40bd97b49c60c01a9e538b7e7390
5
5
  SHA512:
6
- metadata.gz: 85a0e87c06cfa1753b6c3b2baaa251fd864fc03e50af861b86d015dc5a37739f043361c82fafea26794877b0652821a65b27f04efaab905ffb903bca22fedba5
7
- data.tar.gz: 31ad8150d112bfcfd0b7b5e0b62830d3d5336968a76754dad1dc16e255ff0916901fd176fe8557688492101e2ed147392210cda1e4c6dd1920166d3c1bff477b
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`.
@@ -1,3 +1,3 @@
1
1
  module OpenWeatherClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
- response = connection.get('2.5/weather')
23
-
24
- response.body
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
@@ -3,6 +3,8 @@ require 'open_weather_client/version'
3
3
  require 'open_weather_client/weather'
4
4
 
5
5
  module OpenWeatherClient
6
+ class AuthenticationError < StandardError; end
7
+
6
8
  class << self
7
9
  attr_accessor :configuration, :testing
8
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_weather_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Keune