soaspec 0.0.65 → 0.0.66
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/exe/soaspec-virtual-server +4 -4
- data/lib/soaspec/exchange_handlers/rest_handler.rb +38 -5
- data/lib/soaspec/test_server/puppy_service.rb +1 -1
- data/lib/soaspec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e85c415626794edcaa1b13f12026dc04e619359
|
4
|
+
data.tar.gz: 1bafaf7d28a044e41cfd284d94ee5210c19a3d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4062eae6480b45730bd44a8f94a2f564ba9a95f33c2e82cc5cb35de5a6d496d61e5f4cb41854c805e167c7d14d0758bb4bb2099f219f3fe3b9e6255b00091cd
|
7
|
+
data.tar.gz: aa7e71f4c08aa808fc381eb1199ee5027b4ee56bd5b03a41cc5ecbd4cd7692763f17ff9f642cf2d5f73de016427293f7ec5271e6625d46fb69873c8a2c7a3fbb
|
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.0.66
|
2
|
+
* Enhancements
|
3
|
+
* Added method to convert REST request keys to 'PascalCase' if 'pascal_keys' is set to true
|
4
|
+
* This also converts paths obtaining elements to 'PascalCase' if they're simple and have no starting '//' or '$..'
|
5
|
+
|
1
6
|
Version 0.0.65
|
2
7
|
* Enhancements
|
3
8
|
* Added ability to set 'suburl' and 'method' in Exchange accessor. Will be used in FactoryBot later
|
data/exe/soaspec-virtual-server
CHANGED
@@ -35,8 +35,8 @@ end
|
|
35
35
|
post '/test/name' do
|
36
36
|
request_hash = JSON.parse(request.body.string)
|
37
37
|
id = Soaspec::TestServer::PuppyService.new_id
|
38
|
-
Soaspec::TestServer::PuppyService.data[id][:
|
39
|
-
response_hash = { result: {
|
38
|
+
Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
|
39
|
+
response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
|
40
40
|
JSON.generate response_hash
|
41
41
|
end
|
42
42
|
|
@@ -48,7 +48,7 @@ end
|
|
48
48
|
|
49
49
|
patch '/test/name/:id' do |id|
|
50
50
|
request_hash = JSON.parse(request.body.string)
|
51
|
-
Soaspec::TestServer::PuppyService.data[id.to_i][:
|
52
|
-
response_hash = { result: {
|
51
|
+
Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
|
52
|
+
response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
|
53
53
|
JSON.generate response_hash
|
54
54
|
end
|
@@ -84,6 +84,13 @@ module Soaspec
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
# Convert each key from snake_case to PascalCase
|
88
|
+
def pascal_keys(set)
|
89
|
+
define_method('pascal_keys?') do
|
90
|
+
set
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
87
94
|
end
|
88
95
|
|
89
96
|
# Wraps around Savon client defining default values dependent on the soap request
|
@@ -138,6 +145,26 @@ module Soaspec
|
|
138
145
|
@resource = RestClient::Resource.new(base_url_value, merged_options) # @resource[url_extension].get
|
139
146
|
end
|
140
147
|
|
148
|
+
def convert_to_pascal_case(key)
|
149
|
+
key.split('_').map(&:capitalize).join
|
150
|
+
end
|
151
|
+
|
152
|
+
# @return Whether to convert each key in the request to PascalCase
|
153
|
+
# It will also auto convert simple XPath, JSONPath where '//' or '..' not specified
|
154
|
+
def pascal_keys?
|
155
|
+
false
|
156
|
+
end
|
157
|
+
|
158
|
+
# @return [Hash]
|
159
|
+
def hash_used_in_request(override_hash)
|
160
|
+
request = @default_hash.merge(override_hash)
|
161
|
+
if pascal_keys?
|
162
|
+
request.map { |k, v| [convert_to_pascal_case(k.to_s), v] }.to_h
|
163
|
+
else
|
164
|
+
request
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
141
168
|
# Used in together with Exchange request that passes such override parameters
|
142
169
|
# @param [Hash] override_parameters Params to characterize REST request
|
143
170
|
# @param_value [params] Extra parameters (E.g. headers)
|
@@ -156,7 +183,7 @@ module Soaspec
|
|
156
183
|
response = case test_values[:method]
|
157
184
|
when :post, :patch, :put
|
158
185
|
unless test_values[:payload]
|
159
|
-
test_values[:payload] = JSON.generate(
|
186
|
+
test_values[:payload] = JSON.generate(hash_used_in_request(test_values[:body])).to_s if test_values[:body]
|
160
187
|
end
|
161
188
|
@resource_used.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
|
162
189
|
else
|
@@ -170,9 +197,9 @@ module Soaspec
|
|
170
197
|
response
|
171
198
|
end
|
172
199
|
|
173
|
-
# @param [Hash]
|
200
|
+
# @param [Hash] _format Format of expected result. Ignored for this
|
174
201
|
# @return [Object] Generic body to be displayed in error messages
|
175
|
-
def response_body(response,
|
202
|
+
def response_body(response, _format: :hash)
|
176
203
|
extract_hash response
|
177
204
|
end
|
178
205
|
|
@@ -270,11 +297,17 @@ module Soaspec
|
|
270
297
|
case Interpreter.response_type_for(response)
|
271
298
|
when :xml
|
272
299
|
path = "//*[@#{attribute}]" unless attribute.nil?
|
273
|
-
|
300
|
+
if path[0] != '/'
|
301
|
+
path = convert_to_pascal_case(path) if pascal_keys?
|
302
|
+
path = '//' + path
|
303
|
+
end
|
274
304
|
xpath_value_for(response: response, xpath: path, attribute: attribute)
|
275
305
|
when :json
|
276
306
|
raise 'JSON does not support attributes' if attribute
|
277
|
-
|
307
|
+
if path[0] != '$'
|
308
|
+
path = convert_to_pascal_case(path) if pascal_keys?
|
309
|
+
path = '$..' + path
|
310
|
+
end
|
278
311
|
matching_values = JsonPath.on(response.body, path)
|
279
312
|
raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty?
|
280
313
|
matching_values.first
|
data/lib/soaspec/version.rb
CHANGED