lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.51 vs lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.52
- old
+ new
@@ -1,8 +1,8 @@
require_relative 'exchange_handler'
-require_relative '../hash_methods'
+require_relative '../core_ext/hash'
require_relative '../not_found_errors'
require_relative 'handler_accessors'
require_relative '../interpreter'
module Soaspec
@@ -139,32 +139,36 @@
end
# Returns the value at the provided xpath
# @param [Savon::Response] response
# @param [String] xpath
+ # @param [String] attribute Generic attribute to find
# @return [String] Value inside element found through Xpath
- def xpath_value_for(response: nil, xpath: nil)
- raise ArgumentError unless response && xpath
+ def xpath_value_for(response: nil, xpath: nil, attribute: nil)
+ raise ArgumentError('response and xpath must be passed to method') unless response && xpath
result =
if Soaspec.strip_namespaces? && !xpath.include?(':')
temp_doc = response.doc.dup
temp_doc.remove_namespaces!
- temp_doc.xpath(xpath).first
+ temp_doc.at_xpath(xpath)
else
- response.xpath(xpath).first
+ response.xpath(xpath).first # Note this is Savon's xpath method. Hence Nokogiri 'at_xpath' not used
end
raise NoElementAtPath, "No value at Xpath '#{xpath}' in XML #{response.doc}" unless result
- result.inner_text
+ return result.inner_text if attribute.nil?
+ result.attributes[attribute].inner_text
end
# Based on a exchange, return the value at the provided xpath
# If the path does not begin with a '/', a '//' is added to it
# @param [Savon::Response] response
# @param [String] path Xpath
+ # @param [String] attribute Generic attribute to find. Will override path
# @return [String] Value at Xpath
- def value_from_path(response, path)
+ def value_from_path(response, path, attribute: nil)
+ path = "//*[@#{attribute}]" unless attribute.nil?
path = '//' + path if path[0] != '/'
- xpath_value_for(response: response, xpath: path)
+ xpath_value_for(response: response, xpath: path, attribute: attribute)
end
# Whether any of the keys of the Body Hash include value
def include_value?(response, expected_value)
response.body.include_value?(expected_value)
\ No newline at end of file