lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.32 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.33
- old
+ new
@@ -3,10 +3,11 @@
require_relative '../hash_methods'
require_relative '../not_found_errors'
require_relative '../accessors'
require_relative '../interpreter'
require 'json'
+require 'jsonpath'
require 'nori'
module Soaspec
# Accessors specific to REST handler
@@ -177,13 +178,12 @@
case Interpreter.response_type_for(exchange.response)
when :xml
path = '//' + path if path[0] != '/'
xpath_value_for(exchange: exchange, xpath: path)
when :json
- hash = extract_hash exchange.response
- value = hash.dig(*path)
- raise NoElementInHash, "Element in #{hash} not found with path '#{path}'" unless value
- value
+ matching_values = JsonPath.on(exchange.response.body, path)
+ raise NoElementInHash, "Element in #{exchange.response.body} not found with path '#{path}'" if matching_values.empty?
+ matching_values.first
else
raise 'Unrecognised response message. Neither xml nor json detected'
end
end
\ No newline at end of file