loquor 1.4.0 → 1.5.0
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/CHANGELOG.md +3 -0
- data/lib/loquor/api_calls/show.rb +15 -5
- data/lib/loquor/client.rb +2 -2
- data/lib/loquor/configuration.rb +5 -3
- data/lib/loquor/version.rb +1 -1
- data/test/api_calls/show_test.rb +24 -4
- data/test/client_test.rb +2 -2
- data/test/configuration_test.rb +16 -0
- data/test/http_actions/get_test.rb +4 -4
- data/test/resource_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 632149903ddd90cf5dc6edaede05ac490317090c
|
4
|
+
data.tar.gz: a523cf47111b39b1086a8f378316bac2fbf78a6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd8547f47aab0d704b909488c4a59cf569ad7b9bccefb8fb95f313b2aeb7adb1b6b774fe6153c523cecf81d5fdace2dfa7a873f260623ceac00658fced90192
|
7
|
+
data.tar.gz: 43e207ddc2425f44db2a8bc6138b67bff3853b7d6155c61a343d3ab8a4ab41fd22fa59fe87511abcbdade03a5d60a8e1b4658d195903438072fa5265e2bdafba
|
data/CHANGELOG.md
CHANGED
@@ -7,12 +7,22 @@ module Loquor
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def execute
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Loquor.
|
10
|
+
begin
|
11
|
+
get_data
|
12
|
+
rescue RestClient::ResourceNotFound
|
13
|
+
if Loquor.config.retry_404s
|
14
|
+
sleep(1)
|
15
|
+
get_data
|
16
|
+
else
|
17
|
+
raise
|
18
|
+
end
|
14
19
|
end
|
15
|
-
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def get_data
|
24
|
+
options = {cache: klass.cache}
|
25
|
+
klass.new Loquor.get("#{klass.path}/#{@id}", options)
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
data/lib/loquor/client.rb
CHANGED
@@ -6,9 +6,9 @@ module Loquor
|
|
6
6
|
@config = Configuration.new
|
7
7
|
end
|
8
8
|
|
9
|
-
def get(url,
|
9
|
+
def get(url, options = {})
|
10
10
|
deps = {config: @config}
|
11
|
-
deps[:should_cache] = cache if cache
|
11
|
+
deps[:should_cache] = options[:cache] if options[:cache]
|
12
12
|
HttpAction::Get.get(url, deps)
|
13
13
|
end
|
14
14
|
|
data/lib/loquor/configuration.rb
CHANGED
@@ -7,7 +7,7 @@ module Loquor
|
|
7
7
|
class Configuration
|
8
8
|
|
9
9
|
SETTINGS = [
|
10
|
-
:logger, :access_id, :secret_key, :endpoint, :substitute_values
|
10
|
+
:logger, :access_id, :secret_key, :endpoint, :substitute_values, :retry_404s
|
11
11
|
]
|
12
12
|
|
13
13
|
attr_writer *SETTINGS
|
@@ -16,6 +16,7 @@ module Loquor
|
|
16
16
|
def initialize
|
17
17
|
self.logger = Filum.logger
|
18
18
|
self.substitute_values = {}
|
19
|
+
self.retry_404s = false
|
19
20
|
end
|
20
21
|
|
21
22
|
SETTINGS.each do |setting|
|
@@ -27,8 +28,9 @@ module Loquor
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def get_or_raise(setting)
|
30
|
-
instance_variable_get("@#{setting.to_s}")
|
31
|
-
|
31
|
+
val = instance_variable_get("@#{setting.to_s}")
|
32
|
+
raise(LoquorConfigurationError.new("Configuration for #{setting} is not set")) if val.nil?
|
33
|
+
val
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/loquor/version.rb
CHANGED
data/test/api_calls/show_test.rb
CHANGED
@@ -9,21 +9,41 @@ module Loquor
|
|
9
9
|
|
10
10
|
class CachedResource < Resource
|
11
11
|
self.path = '/cached'
|
12
|
-
self.cache = true
|
12
|
+
self.cache = true
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_request_correct_path
|
16
16
|
show = ApiCall::Show.new(NormalResource, 42)
|
17
|
-
Loquor.expects(:get).with('/normal/42').returns({}.to_json)
|
17
|
+
Loquor.expects(:get).with('/normal/42', {cache: nil}).returns({}.to_json)
|
18
18
|
show.execute
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_request_correct_path_for_cachable_resources
|
22
22
|
show = ApiCall::Show.new(CachedResource, 42)
|
23
|
-
Loquor.expects(:get).with('/cached/42', cache
|
23
|
+
Loquor.expects(:get).with('/cached/42', {cache: true}).returns({}.to_json)
|
24
24
|
show.execute
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_should_retry_for_404_if_configured
|
28
|
+
Loquor.config.retry_404s = true
|
29
|
+
Loquor.expects(:get).twice.raises(RestClient::ResourceNotFound)
|
30
|
+
|
31
|
+
show = ApiCall::Show.new(CachedResource, 42)
|
32
|
+
assert_raises(RestClient::ResourceNotFound) do
|
33
|
+
show.execute
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_not_retry_for_404_if_configured
|
38
|
+
Loquor.config.retry_404s = false
|
39
|
+
Loquor.expects(:get).once.raises(RestClient::ResourceNotFound)
|
40
|
+
|
41
|
+
show = ApiCall::Show.new(CachedResource, 42)
|
42
|
+
assert_raises(RestClient::ResourceNotFound) do
|
43
|
+
show.execute
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
27
47
|
def test_response_is_a_representation
|
28
48
|
show = ApiCall::Show.new(Resource, 1)
|
29
49
|
Loquor.stubs(get: {foo: 'bar'}.to_json)
|
data/test/client_test.rb
CHANGED
@@ -35,7 +35,7 @@ module Loquor
|
|
35
35
|
HttpAction::Post.expects(:post).with(url, payload, deps)
|
36
36
|
client.post(url, payload)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
|
40
40
|
def test_get_calls_gets_with_cache_flag
|
41
41
|
url = "foobar"
|
@@ -43,7 +43,7 @@ module Loquor
|
|
43
43
|
client = Client.new
|
44
44
|
deps = {config: client.config, should_cache: true}
|
45
45
|
HttpAction::Get.expects(:get).with(url, deps)
|
46
|
-
client.get(url, cache
|
46
|
+
client.get(url, cache: true)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/test/configuration_test.rb
CHANGED
@@ -37,6 +37,22 @@ module Loquor
|
|
37
37
|
assert_equal endpoint, Loquor.config.endpoint
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_retry_404s_should_be_false_by_default
|
41
|
+
assert_equal false, Loquor.config.retry_404s
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_retry_404s_should_set_to_false
|
45
|
+
retry_404s = false
|
46
|
+
Loquor.config.retry_404s = retry_404s
|
47
|
+
assert_equal retry_404s, Loquor.config.retry_404s
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_retry_404s_should_set_to_false
|
51
|
+
retry_404s = true
|
52
|
+
Loquor.config.retry_404s = retry_404s
|
53
|
+
assert_equal retry_404s, Loquor.config.retry_404s
|
54
|
+
end
|
55
|
+
|
40
56
|
def test_substitute_values
|
41
57
|
substitute_values = {foo: 'bar'}
|
42
58
|
Loquor.config.substitute_values = substitute_values
|
@@ -47,7 +47,7 @@ module Loquor
|
|
47
47
|
gets.expects(execute_against_cache: json)
|
48
48
|
assert_equal output, gets.get
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def test_cache_hit
|
52
52
|
url = "/resource"
|
53
53
|
full_url = "#{@endpoint}#{url}"
|
@@ -58,10 +58,10 @@ module Loquor
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_execute_http_call_on_cache_miss
|
61
|
-
url = "/resource"
|
61
|
+
url = "/resource"
|
62
62
|
full_url = "#{@endpoint}#{url}"
|
63
63
|
json_response = "{}"
|
64
|
-
|
64
|
+
|
65
65
|
@cache.expects(:get).with(full_url).returns(nil)
|
66
66
|
@cache.expects(:set).with(full_url, json_response)
|
67
67
|
|
@@ -72,7 +72,7 @@ module Loquor
|
|
72
72
|
|
73
73
|
def test_does_not_cache_when_no_cache_configured
|
74
74
|
json_response = "{}"
|
75
|
-
|
75
|
+
|
76
76
|
@cache = nil
|
77
77
|
gets = HttpAction::Get.new("", deps.merge({should_cache: true}))
|
78
78
|
gets.expects(execute: json_response)
|
data/test/resource_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filum
|