Class: Savon::GlobalOptions

Inherits:
Options
  • Object
show all
Includes:
HTTPITransportOptions, SharedOptions
Defined in:
lib/savon/options.rb

Overview

Client-level options applied to every request made by a Savon::Client instance. Covers service location, SOAP configuration, logging, response parsing, and transport selection. HTTPI-specific options (proxy, timeouts, SSL, auth) come from HTTPITransportOptions.

Constant Summary

Constants included from HTTPITransportOptions

HTTPITransportOptions::FARADAY_INCOMPATIBLE_GLOBALS, HTTPITransportOptions::TRANSPORT_DEFAULTS

Instance Attribute Summary

Attributes inherited from Options

#option_type

Instance Method Summary collapse

Methods included from HTTPITransportOptions

#adapter, #basic_auth, #digest_auth, #follow_redirects, #ntlm, #open_timeout, #proxy, #read_timeout, #ssl_ca_cert, #ssl_ca_cert_file, #ssl_ca_cert_path, #ssl_cert, #ssl_cert_file, #ssl_cert_key, #ssl_cert_key_file, #ssl_cert_key_password, #ssl_cert_store, #ssl_ciphers, #ssl_max_version, #ssl_min_version, #ssl_verify_mode, #ssl_version, #validate_transport!, #write_timeout

Methods included from SharedOptions

#wsse_auth, #wsse_signature, #wsse_timestamp

Methods inherited from Options

#[], #[]=, #include?

Constructor Details

#initialize(options = {}) ⇒ GlobalOptions

Returns a new instance of GlobalOptions.



255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/savon/options.rb', line 255

def initialize(options = {})
  @option_type = :global
  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.
  delayed_level = options.delete(:log_level)

  super(options)

  log_level(delayed_level) unless delayed_level.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Savon::Options

Instance Method Details

#convert_attributes_to(converter = nil, &block) ⇒ Object

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.



428
429
430
# File 'lib/savon/options.rb', line 428

def convert_attributes_to(converter = nil, &block)
  @options[:convert_attributes_to] = block || converter
end

#convert_dashes_to_underscores(convert) ⇒ Object

Instruct Nori whether to convert dashes in response tag names to underscores before they become Hash keys. Defaults to true.



395
396
397
# File 'lib/savon/options.rb', line 395

def convert_dashes_to_underscores(convert)
  @options[:convert_dashes_to_underscores] = convert
end

#convert_request_keys_to(converter) ⇒ Object

Tell Gyoku how to convert Hash key Symbols to XML tags. Accepts one of :lower_camelcase, :camelcase, :upcase, or :none.



408
409
410
# File 'lib/savon/options.rb', line 408

def convert_request_keys_to(converter)
  @options[:convert_request_keys_to] = converter
end

#convert_response_tags_to(converter = nil, &block) ⇒ Object

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 converting tags to snakecase Symbols.



421
422
423
# File 'lib/savon/options.rb', line 421

def convert_response_tags_to(converter = nil, &block)
  @options[:convert_response_tags_to] = block || converter
end

#delete_namespace_attributes(delete_namespace_attributes) ⇒ Object

Instruct Nori whether to delete namespace attributes from XML nodes.



382
383
384
# File 'lib/savon/options.rb', line 382

def delete_namespace_attributes(delete_namespace_attributes)
  @options[:delete_namespace_attributes] = delete_namespace_attributes
end

#element_form_default(element_form_default) ⇒ Object

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.



316
317
318
# File 'lib/savon/options.rb', line 316

def element_form_default(element_form_default)
  @options[:element_form_default] = element_form_default
end

#empty_tag_value(value) ⇒ Object

The value Nori assigns to empty XML tags in the SOAP response. Defaults to nil, matching Nori's default; set to "" to map empty tags to an empty String instead.



389
390
391
# File 'lib/savon/options.rb', line 389

def empty_tag_value(value)
  @options[:empty_tag_value] = value
end

#encoding(encoding) ⇒ Object

The encoding to use. Defaults to "UTF-8".



304
305
306
# File 'lib/savon/options.rb', line 304

def encoding(encoding)
  @options[:encoding] = encoding
end

#endpoint(endpoint) ⇒ Object

SOAP endpoint.



279
280
281
# File 'lib/savon/options.rb', line 279

def endpoint(endpoint)
  @options[:endpoint] = endpoint
end

#env_namespace(env_namespace) ⇒ Object

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.



323
324
325
# File 'lib/savon/options.rb', line 323

def env_namespace(env_namespace)
  @options[:env_namespace] = env_namespace
end

#filters(*filters) ⇒ Object

A list of XML tags to filter from logged SOAP messages.



367
368
369
# File 'lib/savon/options.rb', line 367

def filters(*filters)
  @options[:filters] = filters.flatten
end

#headers(headers) ⇒ Object

A Hash of HTTP headers sent with every request.



299
300
301
# File 'lib/savon/options.rb', line 299

def headers(headers)
  @options[:headers] = headers
end

#host(host) ⇒ Object

Set a different host for actions in the WSDL.



274
275
276
# File 'lib/savon/options.rb', line 274

def host(host)
  @options[:host] = host
end

#log(log) ⇒ Object

Whether or not to log.



338
339
340
341
# File 'lib/savon/options.rb', line 338

def log(log)
  HTTPI.log = log
  @options[:log] = log
end

#log_headers(log_headers) ⇒ Object

Whether to log headers.



362
363
364
# File 'lib/savon/options.rb', line 362

def log_headers(log_headers)
  @options[:log_headers] = log_headers
end

#log_level(level) ⇒ Object

Changes the Logger's log level.



350
351
352
353
354
355
356
357
358
359
# File 'lib/savon/options.rb', line 350

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

#logger(logger) ⇒ Object

The logger to use. Defaults to a Savon::Logger instance.



344
345
346
347
# File 'lib/savon/options.rb', line 344

def logger(logger)
  HTTPI.logger = logger
  @options[:logger] = logger
end

#multipart(multipart) ⇒ Object

Instruct Savon to create a multipart response if available.



433
434
435
436
437
438
439
440
441
# File 'lib/savon/options.rb', line 433

def multipart(multipart)
  if multipart
    warn "The global :multipart option has been a no-op since v2.13.0. " \
      "Savon detects whether the response is multipart by checking if the " \
      "response Content-Type header contains 'multipart'. You can remove" \
      "this option from your code to make this warning disappear.", uplevel: 1
  end
  @options[:multipart] = multipart
end

#namespace(namespace) ⇒ Object

Target namespace.



284
285
286
# File 'lib/savon/options.rb', line 284

def namespace(namespace)
  @options[:namespace] = namespace
end

#namespace_identifier(identifier) ⇒ Object

The namespace identifier.



289
290
291
# File 'lib/savon/options.rb', line 289

def namespace_identifier(identifier)
  @options[:namespace_identifier] = identifier
end

#namespaces(namespaces) ⇒ Object

Namespaces for the SOAP envelope.



294
295
296
# File 'lib/savon/options.rb', line 294

def namespaces(namespaces)
  @options[:namespaces] = namespaces
end

#no_message_tag(bool) ⇒ Object

Suppress the message tag wrapper around the SOAP body.



449
450
451
# File 'lib/savon/options.rb', line 449

def no_message_tag(bool)
  @options[:no_message_tag] = bool
end

#pretty_print_xml(pretty_print_xml) ⇒ Object

Whether to pretty print request and response XML log messages.



372
373
374
# File 'lib/savon/options.rb', line 372

def pretty_print_xml(pretty_print_xml)
  @options[:pretty_print_xml] = pretty_print_xml
end

#raise_errors(raise_errors) ⇒ Object

Whether or not to raise SOAP fault and HTTP errors.



333
334
335
# File 'lib/savon/options.rb', line 333

def raise_errors(raise_errors)
  @options[:raise_errors] = raise_errors
end

#scrub_xml(scrub) ⇒ Object

Instruct Nori whether to scrub invalid byte sequences from the response body before parsing it. Defaults to true, which lets responses containing invalid characters still be parsed.



402
403
404
# File 'lib/savon/options.rb', line 402

def scrub_xml(scrub)
  @options[:scrub_xml] = scrub
end

#soap_header(header) ⇒ Object

The global SOAP header. Expected to be a Hash or responding to #to_s.



309
310
311
# File 'lib/savon/options.rb', line 309

def soap_header(header)
  @options[:soap_header] = header
end

#soap_version(soap_version) ⇒ Object

Changes the SOAP version to 1 or 2.



328
329
330
# File 'lib/savon/options.rb', line 328

def soap_version(soap_version)
  @options[:soap_version] = soap_version
end

#strip_namespaces(strip_namespaces) ⇒ Object

Instruct Nori whether to strip namespaces from XML nodes.



377
378
379
# File 'lib/savon/options.rb', line 377

def strip_namespaces(strip_namespaces)
  @options[:strip_namespaces] = strip_namespaces
end

#transport(transport) ⇒ Object

HTTP transport to use. Accepts :httpi (default) or :faraday. With :faraday, set proxy, timeout, TLS, auth, redirect, and adapter details on client.faraday; the HTTPI transport options are not copied.



456
457
458
# File 'lib/savon/options.rb', line 456

def transport(transport)
  @options[:transport] = transport
end

#unwrap(unwrap) ⇒ Object

Tell Gyoku to unwrap Array of Hashes. Accepts a boolean, defaults to false.



414
415
416
# File 'lib/savon/options.rb', line 414

def unwrap(unwrap)
  @options[:unwrap] = unwrap
end

#use_wsa_headers(use) ⇒ Object

Enable inclusion of WS-Addressing headers.



444
445
446
# File 'lib/savon/options.rb', line 444

def use_wsa_headers(use)
  @options[:use_wsa_headers] = use
end

#wsdl(wsdl_address) ⇒ Object

Location of the local or remote WSDL document.



269
270
271
# File 'lib/savon/options.rb', line 269

def wsdl(wsdl_address)
  @options[:wsdl] = wsdl_address
end