lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.2.8 vs lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.2.9
- old
+ new
@@ -1,15 +1,13 @@
-
require_relative 'exchange_handler'
require_relative '../core_ext/hash'
require_relative '../not_found_errors'
require_relative 'handler_accessors'
require_relative '../interpreter'
require 'forwardable'
module Soaspec
-
# Accessors specific to SOAP handler
module SoapAccessors
# Define attributes set on root SOAP element
def root_attributes(attributes)
define_method('request_root_attributes') do
@@ -76,14 +74,12 @@
if name.is_a?(Hash) && options == {} # If name is not set
options = name
name = self.class.to_s
end
super
- set_remove_key(options, :operation)
- set_remove_key(options, :default_hash)
- set_remove_key(options, :template_name)
- merged_options = Soaspec.log_api_traffic? ? default_options.merge(logging_options) : default_options
+ set_remove_keys(options, %i[operation default_hash template_name])
+ merged_options = Soaspec::SpecLogger.log_api_traffic? ? default_options.merge(logging_options) : default_options
merged_options.merge! savon_options
merged_options.merge!(options)
self.client = Savon.client(merged_options)
end
@@ -150,20 +146,21 @@
# Convert all XML nodes to lowercase
# @param [Nokogiri::XML::Document]
def convert_to_lower_case(xml_doc)
xml_doc.traverse do |node|
- node.name = node.name.downcase if node.kind_of?(Nokogiri::XML::Element)
+ node.name = node.name.downcase if node.is_a?(Nokogiri::XML::Element)
end
end
# Returns the value at the provided xpath
# @param [Savon::Response] response
# @param [String] xpath
# @return [Enumerable] Elements found through Xpath
def xpath_elements_for(response: nil, xpath: nil, attribute: nil)
raise ArgumentError('response and xpath must be passed to method') unless response && xpath
+
xpath = "//*[@#{attribute}]" unless attribute.nil?
xpath = '//' + xpath if xpath[0] != '/'
temp_doc = response.doc.dup
convert_to_lower_case(temp_doc) if convert_to_lower?
if strip_namespaces? && !xpath.include?(':')
@@ -182,10 +179,11 @@
# @return [String] Value at Xpath
def value_from_path(response, path, attribute: nil)
results = xpath_elements_for(response: response, xpath: path, attribute: attribute)
raise NoElementAtPath, "No value at Xpath '#{path}' in XML #{response.doc}" if results.empty?
return results.first.inner_text if attribute.nil?
+
results.first.attributes[attribute].inner_text
end
# @return [Enumerable] List of values returned from path
def values_from_path(response, path, attribute: nil)
@@ -204,11 +202,10 @@
response.body
end
# Convenience methods for once off usage of a SOAP request
class << self
-
# Implement undefined setter with []= for FactoryBot to use without needing to define params to set
# @param [Object] method_name Name of method not defined
# @param [Object] args Arguments passed to method
# @param [Object] block
def method_missing(method_name, *args, &block)
@@ -229,8 +226,7 @@
tmp_class = new(args)
operations = tmp_class.operations
operations.include?(method_name) || super
end
end
-
end
-end
\ No newline at end of file
+end