lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.80 vs lib/soaspec/exchange_handlers/soap_handler.rb in soaspec-0.0.81
- old
+ new
@@ -2,28 +2,31 @@
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
attributes
end
end
-
end
# Wraps around Savon client defining default values dependent on the soap request
class SoapHandler < ExchangeHandler
extend Soaspec::SoapAccessors
+ extend Forwardable
+ delegate [:operations] => :client
+
# Savon client used to make SOAP calls
attr_accessor :client
# SOAP Operation to use by default
attr_accessor :operation
@@ -81,11 +84,11 @@
set_remove_key(options, :default_hash)
set_remove_key(options, :template_name)
merged_options = default_options.merge logging_options
merged_options.merge! savon_options
merged_options.merge!(options)
- @client = Savon.client(merged_options)
+ self.client = Savon.client(merged_options)
end
# Used in making request via hash or in template via Erb
def request_body_params(request_parameters)
test_values = request_parameters[:body] ? request_parameters[:body] : request_parameters
@@ -195,16 +198,35 @@
# @return [Boolean] Whether any of the keys of the Body Hash include value
def include_value?(response, expected_value)
response.body.include_value?(expected_value)
end
- end
- # Deprecated class name. Will be removed in the future
- class BasicSoapHandler < SoapHandler
+ # Convenience methods for once off usage of a SOAP request
+ class << self
- def initialize(name, specific_options = {})
- super
- warn "'BasicSoapHandler' class is Deprecated. Please use 'SoapHandler' instead"
+ # 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)
+ tmp_class = new(method_name)
+ operations = tmp_class.operations
+ if operations.include? method_name
+ tmp_class.operation = method_name
+ exchange = Exchange.new(method_name, *args)
+ exchange.exchange_handler = tmp_class
+ exchange
+ else
+ super
+ end
+ end
+
+ def respond_to_missing?(method_name, *args)
+ tmp_class = new(args)
+ operations = tmp_class.operations
+ operations.include?(method_name) || super
+ end
end
+
end
end
\ No newline at end of file