api_recipes 2.7.1 → 2.9.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/lib/api_recipes/exceptions.rb +8 -2
- data/lib/api_recipes/route.rb +1 -1
- data/lib/api_recipes/utils.rb +31 -0
- data/lib/api_recipes/version.rb +1 -1
- data/lib/api_recipes.rb +5 -5
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee06dcfdc43e19eeb0e2c101061fcae81cbdcd426911ba44c7b78ead44800e12
|
4
|
+
data.tar.gz: 2a53571c7b048774579c9132b9ef89a52a674ff2818d16e46be0b5ffcf4c1829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aa6283219f68dad431806374fa7dbba514c3ec05e6c1d0bf9b10b59ce0df41f0cfb617f107067aba90ac3e64e830874e286c5ccfdd0a92d54230fa1f648fbcb
|
7
|
+
data.tar.gz: 34e77a1d6e67185bdbe884a42c8e92de8bc1bd6922f01dbefcd7cbaaf91855ac7f19ec260314cf391c8c011c0174393e994f7500d80d39b36c0a40079b8e208b
|
@@ -40,9 +40,15 @@ module ApiRecipes
|
|
40
40
|
end
|
41
41
|
|
42
42
|
class ResponseCodeNotAsExpected < Exception
|
43
|
-
|
43
|
+
|
44
|
+
attr_reader :path, :expected_code, :response
|
45
|
+
|
46
|
+
def initialize(path, expected_code = nil, response = nil, message: nil)
|
47
|
+
@path = path
|
48
|
+
@expected_code = expected_code
|
49
|
+
@response = response
|
44
50
|
unless message
|
45
|
-
message = "response code for request on route '#{path}' has returned '#{
|
51
|
+
message = "response code for request on route '#{@path}' has returned '#{@response.code}', but '#{@expected_code}' was expected\n\nResponse body:\n #{@response.body}"
|
46
52
|
end
|
47
53
|
super(message)
|
48
54
|
end
|
data/lib/api_recipes/route.rb
CHANGED
@@ -76,7 +76,7 @@ module ApiRecipes
|
|
76
76
|
case attributes[:on_bad_code].to_s
|
77
77
|
when 'ignore'
|
78
78
|
when 'raise'
|
79
|
-
raise ResponseCodeNotAsExpected.new(path, expected_code,
|
79
|
+
raise ResponseCodeNotAsExpected.new(path, expected_code, @response, message: message)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
data/lib/api_recipes/utils.rb
CHANGED
@@ -77,6 +77,37 @@ class Hash
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
81
|
+
#
|
82
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
83
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
84
|
+
#
|
85
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
86
|
+
#
|
87
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
88
|
+
# to merge values:
|
89
|
+
#
|
90
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
91
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
92
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
93
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
94
|
+
def deep_merge(other_hash, &block)
|
95
|
+
dup.deep_merge!(other_hash, &block)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Same as +deep_merge+, but modifies +self+.
|
99
|
+
def deep_merge!(other_hash, &block)
|
100
|
+
merge!(other_hash) do |key, this_val, other_val|
|
101
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
102
|
+
this_val.deep_merge(other_val, &block)
|
103
|
+
elsif block_given?
|
104
|
+
block.call(key, this_val, other_val)
|
105
|
+
else
|
106
|
+
other_val
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
80
111
|
# Returns a new hash with all keys converted by the block operation.
|
81
112
|
# This includes the keys from the root hash and from all
|
82
113
|
# nested hashes and arrays.
|
data/lib/api_recipes/version.rb
CHANGED
data/lib/api_recipes.rb
CHANGED
@@ -58,6 +58,7 @@ module ApiRecipes
|
|
58
58
|
unless @configuration
|
59
59
|
@configuration = Configuration.new
|
60
60
|
end
|
61
|
+
|
61
62
|
@configuration
|
62
63
|
end
|
63
64
|
|
@@ -116,6 +117,7 @@ module ApiRecipes
|
|
116
117
|
unless @storage
|
117
118
|
@storage = {}
|
118
119
|
end
|
120
|
+
|
119
121
|
@storage
|
120
122
|
end
|
121
123
|
|
@@ -130,11 +132,9 @@ module ApiRecipes
|
|
130
132
|
unless api_name.is_a?(String) || api_name.is_a?(Symbol)
|
131
133
|
raise ArgumentError, "no api_name provided. Given: #{api_name.inspect}"
|
132
134
|
end
|
133
|
-
|
134
|
-
ApiRecipes.configuration.apis_configs[api_name] = {}
|
135
|
-
end
|
135
|
+
global_api_configs = _aprcps_global_storage[api_name]&.configs || {}
|
136
136
|
if configs
|
137
|
-
|
137
|
+
global_api_configs.deep_merge(configs) do |_, old_val, new_val|
|
138
138
|
if new_val.nil?
|
139
139
|
old_val
|
140
140
|
else
|
@@ -142,7 +142,7 @@ module ApiRecipes
|
|
142
142
|
end
|
143
143
|
end
|
144
144
|
else
|
145
|
-
|
145
|
+
global_api_configs
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Verlato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.4
|
19
|
+
version: '4.4'
|
20
|
+
- - "<="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.4'
|
30
|
+
- - "<="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: '5.1'
|
27
33
|
description:
|
28
34
|
email:
|
29
35
|
- averlato@gmail.com
|
@@ -55,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
61
|
requirements:
|
56
62
|
- - ">="
|
57
63
|
- !ruby/object:Gem::Version
|
58
|
-
version: 2.
|
64
|
+
version: 2.7.0
|
59
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
66
|
requirements:
|
61
67
|
- - ">="
|
62
68
|
- !ruby/object:Gem::Version
|
63
69
|
version: '0'
|
64
70
|
requirements: []
|
65
|
-
rubygems_version: 3.0.
|
71
|
+
rubygems_version: 3.0.9
|
66
72
|
signing_key:
|
67
73
|
specification_version: 4
|
68
74
|
summary: Consume HTTP APIs with style
|