require "logger"
require "httpi"
module Savon
class Options
def initialize(options = {})
@options = {}
assign options
end
attr_reader :option_type
def [](option)
@options[option]
end
def []=(option, value)
value = [value].flatten
self.send(option, *value)
end
def include?(option)
@options.key? option
end
private
def assign(options)
options.each do |option, value|
self.send(option, value)
end
end
def method_missing(option, _)
raise UnknownOptionError, "Unknown #{option_type} option: #{option.inspect}"
end
end
class GlobalOptions < Options
def initialize(options = {})
@option_type = :global
defaults = {
:encoding => "UTF-8",
:soap_version => 1,
:namespaces => {},
:logger => Logger.new($stdout),
:log => false,
:filters => [],
:pretty_print_xml => false,
:raise_errors => true,
:strip_namespaces => true,
:convert_response_tags_to => lambda { |tag| tag.snakecase.to_sym},
:multipart => false,
:adapter => nil,
}
options = defaults.merge(options)
delayed_level = options.delete(:log_level)
super(options)
log_level(delayed_level) unless delayed_level.nil?
end
def wsdl(wsdl_address)
@options[:wsdl] = wsdl_address
end
def endpoint(endpoint)
@options[:endpoint] = endpoint
end
def namespace(namespace)
@options[:namespace] = namespace
end
def namespace_identifier(identifier)
@options[:namespace_identifier] = identifier
end
def namespaces(namespaces)
@options[:namespaces] = namespaces
end
def proxy(proxy)
@options[:proxy] = proxy
end
def ()
@options[:headers] =
end
def open_timeout(open_timeout)
@options[:open_timeout] = open_timeout
end
def read_timeout(read_timeout)
@options[:read_timeout] = read_timeout
end
def encoding(encoding)
@options[:encoding] = encoding
end
def ()
@options[:soap_header] =
end
def element_form_default(element_form_default)
@options[:element_form_default] = element_form_default
end
def env_namespace(env_namespace)
@options[:env_namespace] = env_namespace
end
def soap_version(soap_version)
@options[:soap_version] = soap_version
end
def raise_errors(raise_errors)
@options[:raise_errors] = raise_errors
end
def log(log)
HTTPI.log = log
@options[:log] = log
end
def logger(logger)
@options[:logger] = logger
end
def log_level(level)
levels = { :debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4 }
unless levels.include? level
raise ArgumentError, "Invalid log level: #{level.inspect}\n" \
"Expected one of: #{levels.keys.inspect}"
end
@options[:logger].level = levels[level]
end
def filters(*filters)
@options[:filters] = filters.flatten
end
def pretty_print_xml(pretty_print_xml)
@options[:pretty_print_xml] = pretty_print_xml
end
def ssl_version(version)
@options[:ssl_version] = version
end
def ssl_verify_mode(verify_mode)
@options[:ssl_verify_mode] = verify_mode
end
def ssl_cert_key_file(file)
@options[:ssl_cert_key_file] = file
end
def ssl_cert_key_password(password)
@options[:ssl_cert_key_password] = password
end
def ssl_cert_file(file)
@options[:ssl_cert_file] = file
end
def ssl_ca_cert_file(file)
@options[:ssl_ca_cert_file] = file
end
def basic_auth(*credentials)
@options[:basic_auth] = credentials.flatten
end
def digest_auth(*credentials)
@options[:digest_auth] = credentials.flatten
end
def ntlm(*credentials)
@options[:ntlm] = credentials.flatten
end
def wsse_auth(*credentials)
@options[:wsse_auth] = credentials.flatten
end
def wsse_timestamp(*timestamp)
@options[:wsse_timestamp] = timestamp.flatten
end
def strip_namespaces(strip_namespaces)
@options[:strip_namespaces] = strip_namespaces
end
def convert_request_keys_to(converter)
@options[:convert_request_keys_to] = converter
end
def convert_response_tags_to(converter = nil, &block)
@options[:convert_response_tags_to] = block || converter
end
def multipart(multipart)
@options[:multipart] = multipart
end
def adapter(adapter)
@options[:adapter] = adapter
end
end
class LocalOptions < Options
def initialize(options = {})
@option_type = :local
defaults = {
:advanced_typecasting => true,
:response_parser => :nokogiri,
:multipart => false
}
super defaults.merge(options)
end
def ()
@options[:soap_header] =
end
def message(message)
@options[:message] = message
end
def message_tag(message_tag)
@options[:message_tag] = message_tag
end
def attributes(attributes)
@options[:attributes] = attributes
end
def soap_action(soap_action)
@options[:soap_action] = soap_action
end
def cookies(cookies)
@options[:cookies] = cookies
end
def xml(xml)
@options[:xml] = xml
end
def advanced_typecasting(advanced)
@options[:advanced_typecasting] = advanced
end
def response_parser(parser)
@options[:response_parser] = parser
end
def multipart(multipart)
@options[:multipart] = multipart
end
end
end