-
# frozen_string_literal: true
-
1
require "logger"
-
1
require "httpi"
-
-
1
module Savon
-
1
class Options
-
-
1
def initialize(options = {})
-
541
@options = {}
-
541
assign options
-
end
-
-
1
attr_reader :option_type
-
-
1
def [](option)
-
6815
@options[option]
-
end
-
-
1
def []=(option, value)
-
152
value = [value].flatten
-
152
self.send(option, *value)
-
end
-
-
1
def include?(option)
-
9899
@options.key? option
-
end
-
-
1
private
-
-
1
def assign(options)
-
541
options.each do |option, value|
-
7313
self.send(option, value)
-
end
-
end
-
-
1
def method_missing(option, _)
-
6
raise UnknownOptionError, "Unknown #{option_type} option: #{option.inspect}"
-
end
-
end
-
-
1
module SharedOptions
-
# WSSE auth credentials for Akami.
-
# Local will override the global wsse_auth value, e.g.
-
# global == [user, pass] && local == [user2, pass2] => [user2, pass2]
-
# global == [user, pass] && local == false => false
-
# global == [user, pass] && local == nil => [user, pass]
-
1
def wsse_auth(*credentials)
-
15
credentials.flatten!
-
15
if credentials.size == 1
-
4
@options[:wsse_auth] = credentials.first
-
else
-
11
@options[:wsse_auth] = credentials
-
end
-
end
-
-
# Instruct Akami to enable wsu:Timestamp headers.
-
# Local will override the global wsse_timestamp value, e.g.
-
# global == true && local == true => true
-
# global == true && local == false => false
-
# global == true && local == nil => true
-
1
def wsse_timestamp(timestamp = true)
-
11
@options[:wsse_timestamp] = timestamp
-
end
-
-
1
def wsse_signature(signature)
-
4
@options[:wsse_signature] = signature
-
end
-
end
-
-
1
class GlobalOptions < Options
-
1
include SharedOptions
-
-
1
def initialize(options = {})
-
330
@option_type = :global
-
-
defaults = {
-
330
:encoding => "UTF-8",
-
:soap_version => 1,
-
:namespaces => {},
-
:logger => Logger.new($stdout),
-
:log => false,
-
:filters => [],
-
:pretty_print_xml => false,
-
:raise_errors => true,
-
:strip_namespaces => true,
-
:delete_namespace_attributes => false,
-
467
:convert_response_tags_to => lambda { |tag| tag.snakecase.to_sym},
-
195
:convert_attributes_to => lambda { |k,v| [k,v] },
-
:multipart => false,
-
:adapter => nil,
-
:use_wsa_headers => false,
-
:no_message_tag => false,
-
:follow_redirects => false,
-
:unwrap => false,
-
:host => nil
-
}
-
-
330
options = defaults.merge(options)
-
-
# this option is a shortcut on the logger which needs to be set
-
# before it can be modified to set the option.
-
330
delayed_level = options.delete(:log_level)
-
-
330
super(options)
-
-
329
log_level(delayed_level) unless delayed_level.nil?
-
end
-
-
# Location of the local or remote WSDL document.
-
1
def wsdl(wsdl_address)
-
128
@options[:wsdl] = wsdl_address
-
end
-
-
# set different host for actions in WSDL
-
1
def host(host)
-
330
@options[:host] = host
-
end
-
-
# SOAP endpoint.
-
1
def endpoint(endpoint)
-
156
@options[:endpoint] = endpoint
-
end
-
-
# Target namespace.
-
1
def namespace(namespace)
-
38
@options[:namespace] = namespace
-
end
-
-
# The namespace identifer.
-
1
def namespace_identifier(identifier)
-
3
@options[:namespace_identifier] = identifier
-
end
-
-
# Namespaces for the SOAP envelope.
-
1
def namespaces(namespaces)
-
330
@options[:namespaces] = namespaces
-
end
-
-
# Proxy server to use for all requests.
-
1
def proxy(proxy)
-
3
@options[:proxy] = proxy unless proxy.nil?
-
end
-
-
# A Hash of HTTP headers.
-
1
def headers(headers)
-
5
@options[:headers] = headers
-
end
-
-
# Open timeout in seconds.
-
1
def open_timeout(open_timeout)
-
5
@options[:open_timeout] = open_timeout
-
end
-
-
# Read timeout in seconds.
-
1
def read_timeout(read_timeout)
-
3
@options[:read_timeout] = read_timeout
-
end
-
-
# Write timeout in seconds.
-
1
def write_timeout(write_timeout)
-
1
@options[:write_timeout] = write_timeout
-
end
-
-
# The encoding to use. Defaults to "UTF-8".
-
1
def encoding(encoding)
-
331
@options[:encoding] = encoding
-
end
-
-
# The global SOAP header. Expected to be a Hash or responding to #to_s.
-
1
def soap_header(header)
-
4
@options[:soap_header] = header
-
end
-
-
# Sets whether elements should be :qualified or :unqualified.
-
# If you need to use this option, please open an issue and make
-
# sure to add your WSDL document for debugging.
-
1
def element_form_default(element_form_default)
-
7
@options[:element_form_default] = element_form_default
-
end
-
-
# Can be used to change the SOAP envelope namespace identifier.
-
# If you need to use this option, please open an issue and make
-
# sure to add your WSDL document for debugging.
-
1
def env_namespace(env_namespace)
-
2
@options[:env_namespace] = env_namespace
-
end
-
-
# Changes the SOAP version to 1 or 2.
-
1
def soap_version(soap_version)
-
332
@options[:soap_version] = soap_version
-
end
-
-
# Whether or not to raise SOAP fault and HTTP errors.
-
1
def raise_errors(raise_errors)
-
343
@options[:raise_errors] = raise_errors
-
end
-
-
# Whether or not to log.
-
1
def log(log)
-
334
HTTPI.log = log
-
334
@options[:log] = log
-
end
-
-
# The logger to use. Defaults to a Savon::Logger instance.
-
1
def logger(logger)
-
330
HTTPI.logger = logger
-
330
@options[:logger] = logger
-
end
-
-
# Changes the Logger's log level.
-
1
def log_level(level)
-
6
levels = { :debug => 0, :info => 1, :warn => 2, :error => 3, :fatal => 4 }
-
-
6
unless levels.include? level
-
1
raise ArgumentError, "Invalid log level: #{level.inspect}\n" \
-
"Expected one of: #{levels.keys.inspect}"
-
end
-
-
5
@options[:logger].level = levels[level]
-
end
-
-
# A list of XML tags to filter from logged SOAP messages.
-
1
def filters(*filters)
-
330
@options[:filters] = filters.flatten
-
end
-
-
# Whether to pretty print request and response XML log messages.
-
1
def pretty_print_xml(pretty_print_xml)
-
330
@options[:pretty_print_xml] = pretty_print_xml
-
end
-
-
# Specifies the SSL version to use.
-
1
def ssl_version(version)
-
3
@options[:ssl_version] = version
-
end
-
-
# Specifies the SSL version to use.
-
1
def ssl_min_version(version)
-
2
@options[:ssl_min_version] = version
-
end
-
-
# Specifies the SSL version to use.
-
1
def ssl_max_version(version)
-
2
@options[:ssl_max_version] = version
-
end
-
-
# Whether and how to to verify the connection.
-
1
def ssl_verify_mode(verify_mode)
-
3
@options[:ssl_verify_mode] = verify_mode
-
end
-
-
# Sets the cert key file to use.
-
1
def ssl_cert_key_file(file)
-
6
@options[:ssl_cert_key_file] = file
-
end
-
-
# Sets the cert key to use.
-
1
def ssl_cert_key(key)
-
1
@options[:ssl_cert_key] = key
-
end
-
-
# Sets the cert key password to use.
-
1
def ssl_cert_key_password(password)
-
5
@options[:ssl_cert_key_password] = password
-
end
-
-
# Sets the cert file to use.
-
1
def ssl_cert_file(file)
-
5
@options[:ssl_cert_file] = file
-
end
-
-
# Sets the cert to use.
-
1
def ssl_cert(cert)
-
1
@options[:ssl_cert] = cert
-
end
-
-
# Sets the ca cert file to use.
-
1
def ssl_ca_cert_file(file)
-
3
@options[:ssl_ca_cert_file] = file
-
end
-
-
# Sets the ca cert to use.
-
1
def ssl_ca_cert(cert)
-
1
@options[:ssl_ca_cert] = cert
-
end
-
-
1
def ssl_ciphers(ciphers)
-
3
@options[:ssl_ciphers] = ciphers
-
end
-
-
# Sets the ca cert path.
-
1
def ssl_ca_cert_path(path)
-
1
@options[:ssl_ca_cert_path] = path
-
end
-
-
# Sets the ssl cert store.
-
1
def ssl_cert_store(store)
-
1
@options[:ssl_cert_store] = store
-
end
-
-
# HTTP basic auth credentials.
-
1
def basic_auth(*credentials)
-
3
@options[:basic_auth] = credentials.flatten
-
end
-
-
# HTTP digest auth credentials.
-
1
def digest_auth(*credentials)
-
3
@options[:digest_auth] = credentials.flatten
-
end
-
-
# NTLM auth credentials.
-
1
def ntlm(*credentials)
-
3
@options[:ntlm] = credentials.flatten
-
end
-
-
# Instruct Nori whether to strip namespaces from XML nodes.
-
1
def strip_namespaces(strip_namespaces)
-
333
@options[:strip_namespaces] = strip_namespaces
-
end
-
-
# Instruct Nori whether to delete namespace attributes from XML nodes.
-
1
def delete_namespace_attributes(delete_namespace_attributes)
-
330
@options[:delete_namespace_attributes] = delete_namespace_attributes
-
end
-
-
# Tell Gyoku how to convert Hash key Symbols to XML tags.
-
# Accepts one of :lower_camelcase, :camelcase, :upcase, or :none.
-
1
def convert_request_keys_to(converter)
-
5
@options[:convert_request_keys_to] = converter
-
end
-
-
# Tell Gyoku to unwrap Array of Hashes
-
# Accepts a boolean, default to false
-
1
def unwrap(unwrap)
-
330
@options[:unwrap] = unwrap
-
end
-
-
# Tell Nori how to convert XML tags from the SOAP response into Hash keys.
-
# Accepts a lambda or a block which receives an XML tag and returns a Hash key.
-
# Defaults to convert tags to snakecase Symbols.
-
1
def convert_response_tags_to(converter = nil, &block)
-
334
@options[:convert_response_tags_to] = block || converter
-
end
-
-
# Tell Nori how to convert XML attributes on tags from the SOAP response into Hash keys.
-
# Accepts a lambda or a block which receives an XML tag and returns a Hash key.
-
# Defaults to doing nothing
-
1
def convert_attributes_to(converter = nil, &block)
-
332
@options[:convert_attributes_to] = block || converter
-
end
-
-
# Instruct Savon to create a multipart response if available.
-
1
def multipart(multipart)
-
330
@options[:multipart] = multipart
-
end
-
-
# Instruct Savon what HTTPI adapter it should use instead of default
-
1
def adapter(adapter)
-
330
@options[:adapter] = adapter
-
end
-
-
# Enable inclusion of WS-Addressing headers.
-
1
def use_wsa_headers(use)
-
330
@options[:use_wsa_headers] = use
-
end
-
-
1
def no_message_tag(bool)
-
330
@options[:no_message_tag] = bool
-
end
-
-
# Instruct requests to follow HTTP redirects.
-
1
def follow_redirects(follow_redirects)
-
330
@options[:follow_redirects] = follow_redirects
-
end
-
end
-
-
1
class LocalOptions < Options
-
1
include SharedOptions
-
-
1
def initialize(options = {})
-
211
@option_type = :local
-
-
211
defaults = {
-
:advanced_typecasting => true,
-
:response_parser => :nokogiri,
-
:multipart => false
-
}
-
-
211
super defaults.merge(options)
-
end
-
-
# The local SOAP header. Expected to be a Hash or respond to #to_s.
-
# Will be merged with the global SOAP header if both are Hashes.
-
# Otherwise the local option will be prefered.
-
1
def soap_header(header)
-
4
@options[:soap_header] = header
-
end
-
-
# The SOAP message to send. Expected to be a Hash or a String.
-
1
def message(message)
-
31
@options[:message] = message
-
end
-
-
# SOAP message tag (formerly known as SOAP input tag). If it's not set, Savon retrieves the name from
-
# the WSDL document (if available). Otherwise, Gyoku converts the operation name into an XML element.
-
1
def message_tag(message_tag)
-
2
@options[:message_tag] = message_tag
-
end
-
-
# Attributes for the SOAP message tag.
-
1
def attributes(attributes)
-
3
@options[:attributes] = attributes
-
end
-
-
# Attachments for the SOAP message (https://www.w3.org/TR/SOAP-attachments)
-
#
-
# should pass an Array or a Hash; items should be path strings or
-
# { filename: 'file.name', content: 'content' } objects
-
# The Content-ID in multipart message sections will be the filename or the key if Hash is given
-
#
-
# usage examples:
-
#
-
# response = client.call :operation1 do
-
# message param1: 'value'
-
# attachments [
-
# { filename: 'x1.xml', content: '<xml>abc</xml>'},
-
# { filename: 'x2.xml', content: '<xml>abc</xml>'}
-
# ]
-
# end
-
# # Content-ID will be x1.xml and x2.xml
-
#
-
# response = client.call :operation1 do
-
# message param1: 'value'
-
# attachments 'x1.xml' => '/tmp/1281ab7d7d.xml', 'x2.xml' => '/tmp/4c5v8e833a.xml'
-
# end
-
# # Content-ID will be x1.xml and x2.xml
-
#
-
# response = client.call :operation1 do
-
# message param1: 'value'
-
# attachments [ '/tmp/1281ab7d7d.xml', '/tmp/4c5v8e833a.xml']
-
# end
-
# # Content-ID will be 1281ab7d7d.xml and 4c5v8e833a.xml
-
#
-
# The Content-ID is important if you want to refer to the attachments from the SOAP request
-
1
def attachments(attachments)
-
3
@options[:attachments] = attachments
-
end
-
-
# Value of the SOAPAction HTTP header.
-
1
def soap_action(soap_action)
-
119
@options[:soap_action] = soap_action
-
end
-
-
# Cookies to be used for the next request.
-
1
def cookies(cookies)
-
2
@options[:cookies] = cookies
-
end
-
-
# The SOAP request XML to send. Expected to be a String.
-
1
def xml(xml)
-
14
@options[:xml] = xml
-
end
-
-
# Instruct Nori to use advanced typecasting.
-
1
def advanced_typecasting(advanced)
-
211
@options[:advanced_typecasting] = advanced
-
end
-
-
# Instruct Nori to use :rexml or :nokogiri to parse the response.
-
1
def response_parser(parser)
-
211
@options[:response_parser] = parser
-
end
-
-
# Instruct Savon to create a multipart response if available.
-
1
def multipart(multipart)
-
211
@options[:multipart] = multipart
-
end
-
-
1
def headers(headers)
-
1
@options[:headers] = headers
-
end
-
end
-
end