soaspec 0.0.79 → 0.0.80
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 +6 -0
- data/exe/soaspec-virtual-server +16 -0
- data/lib/soaspec/exchange_handlers/rest_handler.rb +42 -26
- data/lib/soaspec/exchange_handlers/soap_handler.rb +1 -1
- data/lib/soaspec/interpreter.rb +1 -1
- data/lib/soaspec/test_server/note.xml +2 -0
- 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: da0b04fa67877430f80b6850de438eddff6ebec0
|
4
|
+
data.tar.gz: 6ab2a8342e27068d1e8004ba2d37f3183222f7e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6404bc0e90325c946b83cb4d98283f272b72747474892bb07aa2ef11387ea54972762ca27598e60fc58dc50494a60377fcea4c0bc3a0e12169b10bba57a463
|
7
|
+
data.tar.gz: 656f597d657333dd8c2159d03a3608dedef0026f2d2017ed0a5ce468067c4918a2e850a3c8e12f8bab6bd09cb3f99fcd520068a221280c4d7c558c9f6abec795
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Version 0.0.80
|
2
|
+
* Enhancements
|
3
|
+
* `values_from_path` method on `RestHandler` to easily extract multiple values for an xpath or json path
|
4
|
+
* Bug fix
|
5
|
+
* Support response that has white space surrounding message
|
6
|
+
|
1
7
|
Version 0.0.79
|
2
8
|
* Enhancements
|
3
9
|
* `values_from_path` method on `SoapHandler` to easily extract multiple values for an xpath
|
data/exe/soaspec-virtual-server
CHANGED
@@ -66,6 +66,22 @@ class SoaspecVirtualServer < Sinatra::Application
|
|
66
66
|
JSON.generate result
|
67
67
|
end
|
68
68
|
|
69
|
+
get '/test/multiple_json' do
|
70
|
+
<<-BOOKS
|
71
|
+
{"store":
|
72
|
+
{"bicycle":
|
73
|
+
{"price":19.95, "color":"red"},
|
74
|
+
"book":[
|
75
|
+
{"price":8.95, "category":"reference", "title":"Sayings of the Century", "author":"Nigel Rees"},
|
76
|
+
{"price":12.99, "category":"fiction", "title":"Sword of Honour", "author":"Evelyn Waugh"},
|
77
|
+
{"price":8.99, "category":"fiction", "isbn":"0-553-21311-3", "title":"Moby Dick", "author":"Herman Melville","color":"blue"},
|
78
|
+
{"price":22.99, "category":"fiction", "isbn":"0-395-19395-8", "title":"The Lord of the Rings", "author":"Tolkien"}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
BOOKS
|
83
|
+
end
|
84
|
+
|
69
85
|
patch '/test/puppy/:id' do |id|
|
70
86
|
request_hash = JSON.parse(request.body.string)
|
71
87
|
Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
|
@@ -280,21 +280,32 @@ module Soaspec
|
|
280
280
|
# Returns the value at the provided xpath
|
281
281
|
# @param [RestClient::Response] response
|
282
282
|
# @param [String] xpath
|
283
|
-
# @return [
|
284
|
-
def
|
283
|
+
# @return [Enumerable] Value inside element found through Xpath
|
284
|
+
def xpath_elements_for(response: nil, xpath: nil, attribute: nil)
|
285
285
|
raise ArgumentError unless response && xpath
|
286
286
|
raise "Can't perform XPATH if response is not XML" unless Interpreter.response_type_for(response) == :xml
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
287
|
+
xpath = "//*[@#{attribute}]" unless attribute.nil?
|
288
|
+
if xpath[0] != '/'
|
289
|
+
xpath = convert_to_pascal_case(xpath) if pascal_keys?
|
290
|
+
xpath = '//' + xpath
|
291
|
+
end
|
292
|
+
if Soaspec.strip_namespaces? && !xpath.include?(':')
|
293
|
+
temp_doc = Nokogiri.parse response.body
|
294
|
+
temp_doc.remove_namespaces!
|
295
|
+
temp_doc.xpath(xpath)
|
296
|
+
else
|
297
|
+
Nokogiri.parse(response.body).xpath(xpath)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# @return [Enumerable] List of values matching JSON path
|
302
|
+
def json_path_values_for(response, path, attribute: nil)
|
303
|
+
raise 'JSON does not support attributes' if attribute
|
304
|
+
if path[0] != '$'
|
305
|
+
path = convert_to_pascal_case(path) if pascal_keys?
|
306
|
+
path = '$..' + path
|
307
|
+
end
|
308
|
+
JsonPath.on(response.body, path)
|
298
309
|
end
|
299
310
|
|
300
311
|
# Based on a exchange, return the value at the provided xpath
|
@@ -305,22 +316,14 @@ module Soaspec
|
|
305
316
|
# @return [String] Value at Xpath
|
306
317
|
def value_from_path(response, path, attribute: nil)
|
307
318
|
path = path.to_s
|
308
|
-
|
309
319
|
case Interpreter.response_type_for(response)
|
310
320
|
when :xml
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
end
|
316
|
-
xpath_value_for(response: response, xpath: path, attribute: attribute)
|
321
|
+
result = xpath_elements_for(response: response, xpath: path, attribute: attribute).first
|
322
|
+
raise NoElementAtPath, "No value at Xpath '#{path}'" unless result
|
323
|
+
return result.inner_text if attribute.nil?
|
324
|
+
return result.attributes[attribute].inner_text
|
317
325
|
when :json
|
318
|
-
|
319
|
-
if path[0] != '$'
|
320
|
-
path = convert_to_pascal_case(path) if pascal_keys?
|
321
|
-
path = '$..' + path
|
322
|
-
end
|
323
|
-
matching_values = JsonPath.on(response.body, path)
|
326
|
+
matching_values = json_path_values_for(response, path, attribute: attribute)
|
324
327
|
raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty?
|
325
328
|
matching_values.first
|
326
329
|
when :hash
|
@@ -330,6 +333,19 @@ module Soaspec
|
|
330
333
|
end
|
331
334
|
end
|
332
335
|
|
336
|
+
# @return [Enumerable] List of values returned from path
|
337
|
+
def values_from_path(response, path, attribute: nil)
|
338
|
+
path = path.to_s
|
339
|
+
case Interpreter.response_type_for(response)
|
340
|
+
when :xml
|
341
|
+
xpath_elements_for(response: response, xpath: path, attribute: attribute).map(&:inner_text)
|
342
|
+
when :json
|
343
|
+
json_path_values_for(response, path, attribute: attribute)
|
344
|
+
else
|
345
|
+
raise "Unable to interpret type of #{response.body}"
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
333
349
|
# Convenience methods for once off usage of a REST request
|
334
350
|
class << self
|
335
351
|
|
@@ -188,7 +188,7 @@ module Soaspec
|
|
188
188
|
|
189
189
|
# @return [Enumerable] List of values returned from path
|
190
190
|
def values_from_path(response, path, attribute: nil)
|
191
|
-
xpath_elements_for(response: response, xpath: path, attribute: attribute).map(&:inner_text)
|
191
|
+
xpath_elements_for(response: response, xpath: path, attribute: attribute).map(&:inner_text)
|
192
192
|
end
|
193
193
|
|
194
194
|
# alias elements xpath_elements_for
|
data/lib/soaspec/interpreter.rb
CHANGED
data/lib/soaspec/version.rb
CHANGED