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 +4 -4
- data/.github/workflows/ruby.yml +5 -9
- data/.rubocop.yml +4 -0
- data/CHANGES.md +9 -1
- data/Gemfile +0 -2
- data/README.md +7 -1
- data/Rakefile +5 -1
- data/lib/open_weather_client/caching.rb +5 -5
- data/lib/open_weather_client/request.rb +27 -17
- data/lib/open_weather_client/version.rb +1 -1
- data/open_weather_client.gemspec +3 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17bf8dfad870e88aaf543056800194275c1571aca109a24cc622a22b79b8d045
|
4
|
+
data.tar.gz: f3636d87638a6567c008e30ac0cebb557cc0835f3d1c56217a6164b57ac2b1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c00a702fbedee69d3860d6dc1c0c99ffaf3dd51be0c0db3dadddf5f7aba2739cc015bb8a0c641f280433754a97a77d0cebd4a40ae355a85a8c6c1e6bdcf187a
|
7
|
+
data.tar.gz: 61fc3ea2ef6ed2a72adfa45281ce63169643598cad654b42f74665e415329da934b0dee9b80c8d26ebc7ac7bd581db840b512a3fa86b0cf7bc26ba4434ab818c
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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@
|
24
|
+
- uses: actions/checkout@v3
|
26
25
|
- name: Set up Ruby
|
27
|
-
|
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
|
34
|
-
- name: Run
|
29
|
+
bundler-cache: true
|
30
|
+
- name: Run the default task
|
35
31
|
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
#
|
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
data/README.md
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
[](https://badge.fury.io/rb/open_weather_client)
|
4
4
|

|
5
5
|
|
6
|
-
Welcome to Open Weather Client.
|
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
@@ -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
|
-
"
|
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
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
41
|
-
|
42
|
-
OpenWeatherClient.
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
data/open_weather_client.gemspec
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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
|
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.
|
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
|
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:
|
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: '
|
164
|
+
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubygems_version: 3.4.1
|
167
167
|
signing_key:
|