open_weather_client-caching-redis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/CHANGES.md +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +12 -0
- data/lib/open_weather_client-caching-redis/caching/redis/version.rb +9 -0
- data/lib/open_weather_client-caching-redis/caching/redis.rb +41 -0
- data/lib/open_weather_client-caching-redis/configuration.rb +40 -0
- data/open_weather_client-caching-redis.gemspec +40 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ceb73bb4309bdc88a064ee79b12a8685b2d5114c5721be3010158804566faaac
|
4
|
+
data.tar.gz: 55a673a1fb0e6a1f534cbe8b4f6f6a14c25ef5ddca5c422dab42978212a36e20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2754c61e3690326078ecd33dc63f97cb78702f8137999cd850170beaaa588038d38be5bf9af6b0f1bdd2f5ddfdbf2454f18e24d44aa8ab0ca1ede2392f3a7e97
|
7
|
+
data.tar.gz: f716fa8a5b89542b0d951324f39429e63fde967cf1187003df9888e8913b179053b6d30c9e12dca1e6b4cb4f6176fd05e45dc2600e561149eded1a92c18d31ba
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Qurasoft GmbH
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# OpenWeatherClient::Caching::Redis
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/open_weather_client-caching-redis.svg)](https://badge.fury.io/rb/open_weather_client-caching-redis)
|
4
|
+
![RSpec](https://github.com/qurasoft/open_weather_client-caching-redis/actions/workflows/ruby.yml/badge.svg)
|
5
|
+
|
6
|
+
Welcome to OpenWeatherClient::Caching::Redis.
|
7
|
+
This gem provides the redis caching method for [OpenWeatherClient](https://github.com/qurasoft/open_waether_client).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'open_weather_client'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install open_weather_client-caching-redis
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Configure `OpenWeatherClient` to use redis caching.
|
28
|
+
The redis connection can be configured through rails credentials or by manually setting the parameters in configuration.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# OpenWeatherClient initializer
|
32
|
+
OpenWeatherClient.configure do |config|
|
33
|
+
config.caching = OpenWeatherClient::Caching::Redis
|
34
|
+
# Time in days until cached requests are expired, default: 7
|
35
|
+
config.ttl = 14
|
36
|
+
|
37
|
+
# redis connection configuration
|
38
|
+
config.db = 0
|
39
|
+
config.host = 'localhost'
|
40
|
+
config.password = '123456'
|
41
|
+
config.port = 6379
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### Secure Configuration
|
46
|
+
|
47
|
+
```yaml
|
48
|
+
# $ bin/rails credentials:edit
|
49
|
+
open_weather_client:
|
50
|
+
appid: "<INSERT OPENWEATHERMAP API KEY HERE>"
|
51
|
+
redis:
|
52
|
+
db: 0
|
53
|
+
host: 'localhost'
|
54
|
+
password: '123456'
|
55
|
+
port: 6379
|
56
|
+
```
|
57
|
+
|
58
|
+
After configuration of the credentials you can load the settings in your initializer with `#load_from_rails_configuration`.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# OpenWeatherClient initializer
|
62
|
+
OpenWeatherClient.configure do |config|
|
63
|
+
config.load_from_rails_credentials
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
70
|
+
Then, run `rake spec` to run the tests.
|
71
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
72
|
+
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
74
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/qurasoft/open_weather_client-caching-redis.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open_weather_client/caching'
|
4
|
+
require 'open_weather_client-caching-redis/configuration'
|
5
|
+
require 'redis'
|
6
|
+
require_relative 'redis/version'
|
7
|
+
|
8
|
+
module OpenWeatherClient
|
9
|
+
class Caching
|
10
|
+
##
|
11
|
+
# Redis cache of OpenWeatherMap requests
|
12
|
+
#
|
13
|
+
# The requests are cached in redis with an expiration time set by the configuration
|
14
|
+
class Redis < OpenWeatherClient::Caching
|
15
|
+
attr_reader :redis
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
|
20
|
+
config = OpenWeatherClient.configuration
|
21
|
+
@redis = ::Redis.new(host: config.host, port: config.port, db: config.db)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def caching_get(key)
|
27
|
+
JSON.parse(redis.get(key))
|
28
|
+
end
|
29
|
+
|
30
|
+
def caching_store(key, data)
|
31
|
+
redis.set key, data.to_json, ex: OpenWeatherClient.configuration.ttl * 24 * 60 * 60
|
32
|
+
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
def present?(key)
|
37
|
+
redis.exists?(key)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open_weather_client/configuration'
|
4
|
+
|
5
|
+
module OpenWeatherClient
|
6
|
+
##
|
7
|
+
# Configuratin of OpenWeatherClient
|
8
|
+
class Configuration
|
9
|
+
# [Integer] db of the redis server used for caching
|
10
|
+
attr_accessor :db
|
11
|
+
# [String] host of the redis server
|
12
|
+
attr_accessor :host
|
13
|
+
# [Integer] password of the redis server
|
14
|
+
attr_accessor :password
|
15
|
+
# [Integer] port of the redis server
|
16
|
+
attr_accessor :port
|
17
|
+
# [Integer] The time in days until an entry cached in redis is expired
|
18
|
+
attr_accessor :ttl
|
19
|
+
|
20
|
+
alias old_initialize initialize
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
old_initialize
|
24
|
+
|
25
|
+
self.ttl = 7
|
26
|
+
end
|
27
|
+
|
28
|
+
alias old_load load_from_rails_credentials
|
29
|
+
|
30
|
+
def load_from_rails_credentials
|
31
|
+
old_load
|
32
|
+
|
33
|
+
settings = Rails.application.credentials.open_weather_client!.redis!
|
34
|
+
self.host = settings[:host]
|
35
|
+
self.port = settings[:port]
|
36
|
+
self.db = settings[:db]
|
37
|
+
self.password = settings[:password]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/open_weather_client-caching-redis/caching/redis/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'open_weather_client-caching-redis'
|
7
|
+
spec.version = OpenWeatherClient::Caching::Redis::VERSION
|
8
|
+
spec.required_ruby_version = '>= 3.0.0'
|
9
|
+
spec.authors = ['Lucas Keune']
|
10
|
+
spec.email = ['lucas.keune@qurasoft.de']
|
11
|
+
|
12
|
+
spec.summary = 'Redis caching for OpenWeatherClient'
|
13
|
+
spec.description = ''
|
14
|
+
spec.homepage = 'https://github.com/Qurasoft/open_weather_client-caching-redis'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/Qurasoft/open_weather_client-caching-redis'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/Qurasoft/open_weather_client-caching-redis/blob/main/CHANGES.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'bin'
|
29
|
+
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'open_weather_client', '>= 0.1.4'
|
33
|
+
spec.add_dependency 'redis', '>= 4.5.0'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'bundler', '>= 1.17'
|
36
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
38
|
+
spec.add_development_dependency 'rubocop'
|
39
|
+
spec.add_development_dependency 'simplecov'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_weather_client-caching-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Keune
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: open_weather_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: ''
|
112
|
+
email:
|
113
|
+
- lucas.keune@qurasoft.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- CHANGES.md
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- lib/open_weather_client-caching-redis/caching/redis.rb
|
126
|
+
- lib/open_weather_client-caching-redis/caching/redis/version.rb
|
127
|
+
- lib/open_weather_client-caching-redis/configuration.rb
|
128
|
+
- open_weather_client-caching-redis.gemspec
|
129
|
+
homepage: https://github.com/Qurasoft/open_weather_client-caching-redis
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata:
|
133
|
+
homepage_uri: https://github.com/Qurasoft/open_weather_client-caching-redis
|
134
|
+
source_code_uri: https://github.com/Qurasoft/open_weather_client-caching-redis
|
135
|
+
changelog_uri: https://github.com/Qurasoft/open_weather_client-caching-redis/blob/main/CHANGES.md
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 3.0.0
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubygems_version: 3.4.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Redis caching for OpenWeatherClient
|
155
|
+
test_files: []
|