lws 7.2.0 → 7.2.1
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/lib/lws.rb +7 -0
- data/lib/lws/apps/generic.rb +5 -1
- data/lib/lws/config.rb +9 -0
- data/lib/lws/version.rb +1 -1
- data/test/http_caching_test.rb +80 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6deffc4e78a47854d29873d8fc9a28362613690de1c942ae8eed2c5e83e937ca
|
4
|
+
data.tar.gz: a1986c2225a9f172a12cacc6a37d00a19458cbe396212a3281cb74c7901db850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e8856e550c55c227c1671a42573f60044a7bee2e16be6a4f35f5e954cd2b37289a8ee4eee225894d5073e82cb37ee0111bd29c464ccad8c36b3872a0698eacf
|
7
|
+
data.tar.gz: c3e1c5f33253614acf54842796ccb4c9b3b532b4f172d22c7f5f0456056425c15f785a8df29db2af5eb80828bcd76ae3bf7131d74cff967702ad350b40f78656
|
data/lib/lws.rb
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
require "faraday_middleware"
|
13
|
+
require "faraday/http_cache"
|
13
14
|
require "hashie"
|
14
15
|
require "multi_json"
|
15
16
|
require "spyke"
|
@@ -116,6 +117,12 @@ module LWS
|
|
116
117
|
if config.caching_object
|
117
118
|
c.use FaradayMiddleware::Caching, config.caching_object
|
118
119
|
end
|
120
|
+
if config.http_caching
|
121
|
+
logger = config.http_debug ? config.logger : nil
|
122
|
+
c.use Faraday::HttpCache, store: config.http_caching_object,
|
123
|
+
logger: logger,
|
124
|
+
shared_cache: false
|
125
|
+
end
|
119
126
|
c.use RequestHeaders, config.api_token
|
120
127
|
c.use config.api_token_middleware if config.api_token_middleware.present?
|
121
128
|
c.request :json
|
data/lib/lws/apps/generic.rb
CHANGED
@@ -157,7 +157,11 @@ module LWS::Generic
|
|
157
157
|
# @return [Object, nil] the digged up value or +nil+
|
158
158
|
def dig(*attrs)
|
159
159
|
attr = attrs.shift
|
160
|
-
value =
|
160
|
+
value = begin
|
161
|
+
send(attr)
|
162
|
+
rescue NoMethodError
|
163
|
+
nil
|
164
|
+
end
|
161
165
|
return nil if value.nil?
|
162
166
|
return value if attrs.empty?
|
163
167
|
raise TypeError, "#{value.class} does not have #dig method" unless value.respond_to? :dig
|
data/lib/lws/config.rb
CHANGED
@@ -45,6 +45,15 @@ module LWS
|
|
45
45
|
# (default: +:production+)
|
46
46
|
property :environment, default: :production
|
47
47
|
|
48
|
+
#@!attribute http_caching
|
49
|
+
# @return [Boolean] whether HTTP caching is enabled
|
50
|
+
property :http_caching, default: true
|
51
|
+
|
52
|
+
#@!attribute http_caching_object
|
53
|
+
# @return [#read, #write, #delete] an object that caches results
|
54
|
+
# respecting HTTP expiration (instead of an in-memory hash)
|
55
|
+
property :http_caching_object, default: nil
|
56
|
+
|
48
57
|
#@!attribute http_debug
|
49
58
|
# @return [Boolean] whether to show HTTP debug messages (default: +false+)
|
50
59
|
property :http_debug, default: false
|
data/lib/lws/version.rb
CHANGED
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Copyright © 2016–2020 LeftClick B.V.
|
3
|
+
#
|
4
|
+
# This software is property of LeftClick B.V. and cannot be redistributed
|
5
|
+
# and/or modified without permission. The software or any of its parts
|
6
|
+
# cannot be used for any other purposes than the LeftClick services and
|
7
|
+
# only during a valid license subscription. For more information, please
|
8
|
+
# contact LeftClick B.V. at: Schootense Dreef 20A, 5708 HZ Helmond, The
|
9
|
+
# Netherlands, info@leftclick.eu, +3185-4444-004.
|
10
|
+
|
11
|
+
|
12
|
+
require "test_helper"
|
13
|
+
|
14
|
+
class TestHTTPCaching < MiniTest::Test
|
15
|
+
|
16
|
+
# Class used to check if data is read/written to or remove from the cache
|
17
|
+
class HTTPCacheTest
|
18
|
+
|
19
|
+
attr_reader :last_read_key
|
20
|
+
attr_reader :last_written_key, :last_written_value
|
21
|
+
attr_reader :last_deleted_key
|
22
|
+
|
23
|
+
def read(key)
|
24
|
+
@last_read_key = key
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def write(key, value)
|
29
|
+
@last_written_key = key
|
30
|
+
@last_written_value = value
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(key)
|
35
|
+
@last_deleted_key = key
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@cache_mock = HTTPCacheTest.new
|
43
|
+
|
44
|
+
# Redo the LWS setup with an HTTP caching object
|
45
|
+
LWS.setup do |config|
|
46
|
+
config.api_token = ENV["LC_LWS_TEST_TOKEN"]
|
47
|
+
config.http_caching_object = @cache_mock
|
48
|
+
if ENV["LC_LWS_TEST_DEBUG"].present?
|
49
|
+
config.http_debug = true
|
50
|
+
config.http_debug_headers = true
|
51
|
+
end
|
52
|
+
config.environment = :development
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def teardown
|
57
|
+
# Restore the configuration
|
58
|
+
reconfigure
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_working_cache
|
62
|
+
assert_nil(@cache_mock.last_read_key)
|
63
|
+
assert_nil(@cache_mock.last_written_key)
|
64
|
+
assert_nil(@cache_mock.last_written_value)
|
65
|
+
assert_nil(@cache_mock.last_deleted_key)
|
66
|
+
|
67
|
+
new_configuration = LWS::Auth::Configuration.create(key: "test", value: "some_value")
|
68
|
+
refute_nil(@cache_mock.last_deleted_key)
|
69
|
+
|
70
|
+
_configurations = LWS::Auth::Configuration.where(key: "test").to_a
|
71
|
+
refute_nil(@cache_mock.last_read_key)
|
72
|
+
assert_equal(@cache_mock.last_read_key, @cache_mock.last_written_key)
|
73
|
+
refute_nil(@cache_mock.last_written_value)
|
74
|
+
|
75
|
+
old_key = @cache_mock.last_deleted_key.dup
|
76
|
+
new_configuration.destroy
|
77
|
+
refute_equal(old_key, @cache_mock.last_deleted_key)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.2.
|
4
|
+
version: 7.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeftClick B.V.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday-http-cache
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday_middleware
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,6 +276,7 @@ files:
|
|
262
276
|
- test/fixtures/auth.yml
|
263
277
|
- test/fixtures/permissions.yml
|
264
278
|
- test/generic_test.rb
|
279
|
+
- test/http_caching_test.rb
|
265
280
|
- test/json_parser_test.rb
|
266
281
|
- test/logger_test.rb
|
267
282
|
- test/maps_test.rb
|
@@ -295,6 +310,7 @@ signing_key:
|
|
295
310
|
specification_version: 4
|
296
311
|
summary: LeftClick web services library for Ruby
|
297
312
|
test_files:
|
313
|
+
- test/http_caching_test.rb
|
298
314
|
- test/generic_test.rb
|
299
315
|
- test/caching_test.rb
|
300
316
|
- test/api_token_middleware_test.rb
|