open_weather_client 0.1.6 → 0.2.0

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: 4dab7c6f40c34f79492bbb71dd0cd6257bbf42da8398975d6cf93f9ab63a4175
4
- data.tar.gz: 7d3bcfafce03716cfac19f8e823ae8a7baa37a742e8cfe0c442ae4880b3cf534
3
+ metadata.gz: c6d4db65e59ab7bde82a64f2b3da01fbd80cc1e5f4acf7b5084d9dc7ec7db89e
4
+ data.tar.gz: 43b2bb7361f68e91b23e022703cf2ba436f8cea7734dd7495d9f6a31a6cc8215
5
5
  SHA512:
6
- metadata.gz: 3c3cf0422a523d2979fd17d9853801a170ee3adbe2153cf78927a6bd3aa7d691119e44bc2fe152a06ca4d938285cb96b36514efed769b69e28fd837d21e905c1
7
- data.tar.gz: a166b3018ef7d395216ad1cbeeabe9a50dc5899d17a98b651502219c13b409d0e523d1af8d255b24b710fa2b75d24bdeda9677e3fb472d745507b8eafd0ccd63
6
+ metadata.gz: 880007ce334e68cacac086112242a304c081a5535e593589e6797f48d1d3061247cc51f8663deb750e20816978e3b5947d44a466c85d3fe5145c999e5e83676a
7
+ data.tar.gz: f2fdabce1f5d502b41e0cc2c97c8f7efc0d0e121dd8f38fe9465008f3799436efd19bbe81a7c87dadc066e025832149923dd2b563c7a37c7e48eb41e29cd4dc2
@@ -18,7 +18,7 @@ jobs:
18
18
  runs-on: ubuntu-latest
19
19
  strategy:
20
20
  matrix:
21
- ruby-version: ['3.0', '3.2']
21
+ ruby-version: ['2.6', '2.7', '3.0', '3.2', '3.3']
22
22
 
23
23
  steps:
24
24
  - uses: actions/checkout@v3
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.0
2
+ TargetRubyVersion: 2.6
3
3
 
4
4
  Metrics/BlockLength:
5
5
  Exclude:
data/CHANGES.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.2.0
6
+ - Upgrade to Open Weather One Call API 3.0 through configuration option (#8)
7
+
5
8
  ## 0.1.6
6
9
  - Relax required Ruby Version
7
10
 
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  ![RSpec](https://github.com/qurasoft/open_weather_client/actions/workflows/ruby.yml/badge.svg)
5
5
 
6
6
  Welcome to Open Weather Client.
7
- This gem allows you to easily request weather information from OpenWeatherMap.
7
+ This gem allows you to easily request weather information from Open Weather.
8
8
  It integrates in your rails project, when you are using bundler or even in plain ruby projects.
9
9
 
10
10
  ## Installation
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
  $ gem install open_weather_client
25
25
 
26
26
  ## Usage
27
- During configuration the OpenWeatherMap API key must be set. Afterwards it is as simple as calling `OpenWeatherClient.current(lat:, lon:)` to get the current weather at a location.
27
+ During configuration the Open Weather API key must be set. Afterwards it is as simple as calling `OpenWeatherClient.current(lat:, lon:)` to get the current weather at a location.
28
28
 
29
29
  ```ruby
30
30
  # OpenWeatherClient initializer
@@ -36,13 +36,32 @@ end
36
36
  OpenWeatherClient::Weather.current(lat: 50.3569, lon: 7.5890)
37
37
  ```
38
38
 
39
+ ### Used Open Weather API version
40
+ Open Weather provides One Call API 3.0 and API 2.5, which is expected to be deprecated in June 2024.
41
+ Until API 2.5 is deprecated it is the default. With Open Weather Client version 1.0 the default will change to One Call API 3.0.
42
+
43
+ The used API version is configurable through `OpenWeatherClient.configuration.api_version`.
44
+
45
+ ```ruby
46
+ # OpenWeatherClient initializer
47
+ OpenWeatherClient.configure do |config|
48
+ config.api_version = :v25 # (default) also supports :v30
49
+ end
50
+ ```
51
+
39
52
  ### Exceptions during requests
40
53
  When an error occurs during a request, an exception is raised.
41
- If the request is not authorized `OpenWeatherClient::AutheniticationError` is raied.
42
- When attributes like latitude or longitude are outside of the expected range a `RangeError` is raised.
54
+
55
+ If the configured API version is not supported by the client, `OpenWeatherClient::APIVersionNotSupportedError` is raised.
56
+ If the request is not authorized, `OpenWeatherClient::AutheniticationError` is raised.
57
+ If attributes like latitude or longitude are outside of the expected range, `RangeError` is raised.
58
+ If the time is longer in the past than one hour, `OpenWeatherClient::NotCurrentError` is raised.
43
59
 
44
60
  ### Secure Configuration
45
- 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.
61
+ Rails provides the credentials functionality for [environmental security](https://edgeguides.rubyonrails.org/security.html#environmental-security).
62
+ This mechanism can be used by OpenWeatherClient to load the API key from an encrypted file.
63
+ This also allows easy separation of production and development api key configuration.
64
+
46
65
  All settings are defined under the top-level entry `open_weather_client`.
47
66
  ```yaml
48
67
  # $ bin/rails credentials:edit
@@ -50,7 +69,7 @@ open_weather_client:
50
69
  appid: "<INSERT OPENWEATHERMAP API KEY HERE>"
51
70
  ```
52
71
 
53
- After configuration of the credentials you can load the settings in your initializer with `#load_from_rails_configuration`.
72
+ After configuring the credentials, they can be loaded in the initializer with `#load_from_rails_configuration`.
54
73
 
55
74
  ```ruby
56
75
  # OpenWeatherClient initializer
data/bin/console CHANGED
@@ -13,11 +13,10 @@ require 'open_weather_client'
13
13
 
14
14
  OpenWeatherClient.configure do |config|
15
15
  if File.exist?('config.yml')
16
- # NOTE(Keune): The channels available in the console can be set in the file channels.yml. It contains a simple
17
- # mapping of channel identifiers to webhook URLs. The channel identifier is loaded as a symbol.
16
+ # NOTE(Keune): The console automatically loads the appid from the config.yml file in the same directory
18
17
  #
19
18
  # Example: APPID: "<INSERT YOUR WEBHOOK URL HERE>"
20
- puts 'Load channels specified by file'
19
+ puts 'Load appid specified by file'
21
20
 
22
21
  require 'yaml'
23
22
  settings = YAML.load_file 'config.yml'
@@ -9,9 +9,9 @@ module OpenWeatherClient
9
9
  # When the limit is reached the least recently used entry is evicted.
10
10
  class Memory < OpenWeatherClient::Caching
11
11
  # Memory cache to store a hash of keys and request data
12
- attr :memory_cache
12
+ attr_reader :memory_cache
13
13
  # Key registry of the memory cache. The first entry is the key of the least recently accessed data
14
- attr :memory_keys
14
+ attr_reader :memory_keys
15
15
 
16
16
  ##
17
17
  # Initialize an empty cache
@@ -4,6 +4,8 @@ module OpenWeatherClient
4
4
  ##
5
5
  # Configuratin of OpenWeatherClient
6
6
  class Configuration
7
+ # [String] Used api version. One of :v25, :v30. Default :v25
8
+ attr_accessor :api_version
7
9
  # [String] API key to access OpenWeatherMap
8
10
  attr_accessor :appid
9
11
  # Caching method. One of :none, :memory
@@ -24,6 +26,7 @@ module OpenWeatherClient
24
26
  ##
25
27
  # Initialize a new Configuration with the default settings
26
28
  def initialize
29
+ @api_version = :v25
27
30
  @caching = OpenWeatherClient::Caching.new
28
31
  @lang = 'de'
29
32
  @max_memory_entries = 10_000
@@ -13,6 +13,7 @@ module OpenWeatherClient
13
13
  # @param lon[Float] longitude of the requests location
14
14
  # @param time[Time] time of the request
15
15
  #
16
+ # @raise [APIVersionNotSupportedError] if the configured api version is not supported
16
17
  # @raise [AuthenticationError] if the request is not authorized, e.g in case the API key is not correct
17
18
  # @raise [NotCurrentError] if the requested time is older than 1 hour
18
19
  #
@@ -21,7 +22,7 @@ module OpenWeatherClient
21
22
  raise OpenWeatherClient::NotCurrentError if time < Time.now - 1 * 60 * 60
22
23
 
23
24
  begin
24
- response = connection(lat, lon).get('2.5/weather')
25
+ response = connection(lat, lon).get(path)
25
26
  OpenWeatherClient.cache.store(lat: lat, lon: lon, data: response.body, time: time)
26
27
  rescue Faraday::UnauthorizedError
27
28
  raise OpenWeatherClient::AuthenticationError
@@ -54,5 +55,16 @@ module OpenWeatherClient
54
55
  units: OpenWeatherClient.configuration.units
55
56
  }
56
57
  end
58
+
59
+ def self.path
60
+ case OpenWeatherClient.configuration.api_version
61
+ when :v25
62
+ '2.5/weather'
63
+ when :v30
64
+ '3.0/onecall'
65
+ else
66
+ raise OpenWeatherClient::APIVersionNotSupportedError
67
+ end
68
+ end
57
69
  end
58
70
  end
@@ -3,5 +3,5 @@
3
3
  module OpenWeatherClient
4
4
  ##
5
5
  # Version of OpenWeatherClient
6
- VERSION = '0.1.6'
6
+ VERSION = '0.2.0'
7
7
  end
@@ -9,10 +9,13 @@ require 'open_weather_client/weather'
9
9
  ##
10
10
  # Get weather data from OpenWeatherMap
11
11
  module OpenWeatherClient
12
+ # The configured Open Weather API Version is not supported
13
+ class APIVersionNotSupportedError < StandardError; end
14
+
12
15
  # Error during authentication with the OpenWeatherMap servers
13
16
  class AuthenticationError < StandardError; end
14
17
 
15
- # The rquested time is not current enough for getting weather data from the OpenWeatherMap server
18
+ # The requested time is not current enough for getting weather data from the OpenWeatherMap server
16
19
  class NotCurrentError < StandardError; end
17
20
 
18
21
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_weather_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Keune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday