open_weather_client 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dec682ab56d84b58d75c7cee7e1741ea87e5a38e8cedec1ef927b35014108be
4
- data.tar.gz: ed092b5ca8ddeb5bffdb77d1abcacbb52cc5c37a317cee41aacd4063fd680a25
3
+ metadata.gz: 17bf8dfad870e88aaf543056800194275c1571aca109a24cc622a22b79b8d045
4
+ data.tar.gz: f3636d87638a6567c008e30ac0cebb557cc0835f3d1c56217a6164b57ac2b1e9
5
5
  SHA512:
6
- metadata.gz: 84de4f4266c121d44033694c6dbca2519db1f87976dd420ec64711831e45957ceb827a33b60a30a045ac6b7734760c85f7404654332c4d22fd9a7fb1423c05be
7
- data.tar.gz: 037bcb2ff6e0fdf53023520b290fc0cfc821c0184a94208dfd9d108a86852998d5af7ff23a1aa4d8ceb73f2dacc46d9bb64d0e01a7e096c198ff121aab7a2fff
6
+ metadata.gz: 0c00a702fbedee69d3860d6dc1c0c99ffaf3dd51be0c0db3dadddf5f7aba2739cc015bb8a0c641f280433754a97a77d0cebd4a40ae355a85a8c6c1e6bdcf187a
7
+ data.tar.gz: 61fc3ea2ef6ed2a72adfa45281ce63169643598cad654b42f74665e415329da934b0dee9b80c8d26ebc7ac7bd581db840b512a3fa86b0cf7bc26ba4434ab818c
@@ -15,21 +15,17 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
-
19
18
  runs-on: ubuntu-latest
20
19
  strategy:
21
20
  matrix:
22
- ruby-version: ['3.0']
21
+ ruby-version: ['3.0', '3.2']
23
22
 
24
23
  steps:
25
- - uses: actions/checkout@v2
24
+ - uses: actions/checkout@v3
26
25
  - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
26
+ uses: ruby/setup-ruby@v1
31
27
  with:
32
28
  ruby-version: ${{ matrix.ruby-version }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Run tests
29
+ bundler-cache: true
30
+ - name: Run the default task
35
31
  run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -4,3 +4,7 @@ AllCops:
4
4
  Metrics/BlockLength:
5
5
  Exclude:
6
6
  - spec/**/*
7
+
8
+ Layout/LineLength:
9
+ Exclude:
10
+ - spec/**/*
data/CHANGES.md CHANGED
@@ -1,4 +1,12 @@
1
- # Open Weather Client Changelog
1
+ # OpenWeatherClient Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## 0.1.4
6
+ - Add rubocop rake task
7
+ - Run Github actions for ruby 3.2
8
+ - Change cache key format to `weather:<lat>:<lon>:<time}>` for better compatibility with redis
9
+ - Make `OpenWeatherClient::Caching#cache_key` public
2
10
 
3
11
  ## 0.1.3
4
12
  Re-release of 0.1.2 since this version was released from an incorrect branch.
data/Gemfile CHANGED
@@ -2,7 +2,5 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
5
  # Specify your gem's dependencies in open_weather_client.gemspec
8
6
  gemspec
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/open_weather_client.svg)](https://badge.fury.io/rb/open_weather_client)
4
4
  ![RSpec](https://github.com/qurasoft/open_weather_client/actions/workflows/ruby.yml/badge.svg)
5
5
 
6
- Welcome to Open Weather Client. This gem allows you to easily request weather information from OpenWeatherMap.
6
+ Welcome to Open Weather Client.
7
+ This gem allows you to easily request weather information from OpenWeatherMap.
7
8
  It integrates in your rails project, when you are using bundler or even in plain ruby projects.
8
9
 
9
10
  ## Installation
@@ -69,12 +70,16 @@ Whether requests are only performed when the requested time is within the last h
69
70
  If caching is enabled, requests with a time older than one hour might still be answered with a response.
70
71
 
71
72
  ```ruby
73
+ # OpenWeatherClient initializer
72
74
  OpenWeatherClient.configure do |config|
73
75
  config.caching = OpenWeatherClient::Caching::Memory
74
76
  config.max_memory_entries = 100 # Maximum number of entries in memory cache
75
77
  end
76
78
  ```
77
79
 
80
+ ### Cache key
81
+ The cache key for a given latitute, longitude and time is calculated by `OpenWeatherClient::Caching#cache_key(lat, lon, time)`.
82
+
78
83
  #### Memory Caching
79
84
  `OpenWeatherClient` supports simple in memory caching.
80
85
  A hash is used to store and look up the cached responses.
@@ -93,6 +98,7 @@ The quantization receives latitude and longitude.
93
98
  The result is coerced back into latitude and longitude.
94
99
 
95
100
  ```ruby
101
+ # OpenWeatherClient initializer
96
102
  OpenWeatherClient.configure do |config|
97
103
  config.spatial_quantization = proc { |lat, lon| [lat.round(2), lon.round(2)] }
98
104
  end
data/Rakefile CHANGED
@@ -5,4 +5,8 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- task default: :spec
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -44,8 +44,6 @@ module OpenWeatherClient
44
44
  data
45
45
  end
46
46
 
47
- private
48
-
49
47
  ##
50
48
  # Calculate the key for storage in the cache
51
49
  #
@@ -53,9 +51,11 @@ module OpenWeatherClient
53
51
  # @param lon[Float] longitude of the requests location
54
52
  # @param time[Time] time of the request
55
53
  def cache_key(lat, lon, time)
56
- "#{lat}_#{lon}_#{time.strftime('%Y-%m-%dT%H')}"
54
+ "weather:#{lat}:#{lon}:#{time.strftime('%Y-%m-%dT%H')}"
57
55
  end
58
56
 
57
+ private
58
+
59
59
  ##
60
60
  # Read an entry out of the memory cache
61
61
  #
@@ -71,11 +71,11 @@ module OpenWeatherClient
71
71
  #
72
72
  # Evicts the entry with the least recent access if the memory cache is full
73
73
  #
74
- # @param key[String] key into the cache. Is stored at the end of the key registry
74
+ # @param _key[String] key into the cache. Is stored at the end of the key registry
75
75
  # @param data[Hash] data to be stored, must be able to be formatted and parsed as text
76
76
  #
77
77
  # @return [Hash] the input data
78
- def caching_store(key, data)
78
+ def caching_store(_key, data)
79
79
  data
80
80
  end
81
81
 
@@ -20,29 +20,39 @@ module OpenWeatherClient
20
20
  def self.get(lat:, lon:, time: Time.now)
21
21
  raise OpenWeatherClient::NotCurrentError if time < Time.now - 1 * 60 * 60
22
22
 
23
- connection = Faraday.new(
23
+ begin
24
+ response = connection(lat, lon).get('2.5/weather')
25
+ OpenWeatherClient.cache.store(lat: lat, lon: lon, data: response.body, time: time)
26
+ rescue Faraday::UnauthorizedError
27
+ raise OpenWeatherClient::AuthenticationError
28
+ end
29
+ end
30
+
31
+ def self.connection(lat, lon)
32
+ Faraday.new(
24
33
  url: OpenWeatherClient.configuration.url,
25
- params: {
26
- appid: OpenWeatherClient.configuration.appid,
27
- lat: lat,
28
- lon: lon,
29
- lang: OpenWeatherClient.configuration.lang,
30
- units: OpenWeatherClient.configuration.units
31
- },
32
- headers: {
33
- 'User-Agent': OpenWeatherClient.configuration.user_agent
34
- }
34
+ params: params(lat, lon),
35
+ headers: headers
35
36
  ) do |f|
36
37
  f.response :raise_error
37
38
  f.response :json
38
39
  end
40
+ end
39
41
 
40
- begin
41
- response = connection.get('2.5/weather')
42
- OpenWeatherClient.cache.store(lat: lat, lon: lon, data: response.body, time: time)
43
- rescue Faraday::UnauthorizedError
44
- raise OpenWeatherClient::AuthenticationError
45
- end
42
+ def self.headers
43
+ {
44
+ 'User-Agent': OpenWeatherClient.configuration.user_agent
45
+ }
46
+ end
47
+
48
+ def self.params(lat, lon)
49
+ {
50
+ appid: OpenWeatherClient.configuration.appid,
51
+ lat: lat,
52
+ lon: lon,
53
+ lang: OpenWeatherClient.configuration.lang,
54
+ units: OpenWeatherClient.configuration.units
55
+ }
46
56
  end
47
57
  end
48
58
  end
@@ -3,5 +3,5 @@
3
3
  module OpenWeatherClient
4
4
  ##
5
5
  # Version of OpenWeatherClient
6
- VERSION = '0.1.3'
6
+ VERSION = '0.1.4'
7
7
  end
@@ -1,14 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'open_weather_client/version'
3
+ require_relative 'lib/open_weather_client/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'open_weather_client'
9
7
  spec.version = OpenWeatherClient::VERSION
10
- spec.required_ruby_version = '>= 3.0'
11
- spec.required_rubygems_version = '>= 2'
8
+ spec.required_ruby_version = '>= 3.0.0'
12
9
  spec.authors = ['Lucas Keune']
13
10
  spec.email = ['lucas.keune@qurasoft.de']
14
11
 
@@ -23,7 +20,7 @@ Gem::Specification.new do |spec|
23
20
 
24
21
  # Specify which files should be added to the gem when it is released.
25
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ spec.files = Dir.chdir(__dir__) do
27
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
25
  end
29
26
  spec.bindir = 'bin'
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.3
4
+ version: 0.1.4
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-01-27 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -156,12 +156,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '3.0'
159
+ version: 3.0.0
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - ">="
163
163
  - !ruby/object:Gem::Version
164
- version: '2'
164
+ version: '0'
165
165
  requirements: []
166
166
  rubygems_version: 3.4.1
167
167
  signing_key: