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

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.



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/savon/options.rb', line 272

def initialize(options = {})
  @option_type = :global

  defaults = {
    encoding: "UTF-8",
    soap_version: 1,
    namespaces: {},
    logger: Logger.new($stdout),
    log: false,
    log_headers: true,
    filters: [],
    pretty_print_xml: false,
    raise_errors: true,
    strip_namespaces: true,
    delete_namespace_attributes: false,
    convert_response_tags_to: ->(tag) { StringUtils.snakecase(tag).to_sym },
    convert_attributes_to: ->(k, v) { [k, v] },
    multipart: false,
    use_wsa_headers: false,
    no_message_tag: false,
    unwrap: false,
    host: nil,
    transport: :httpi,

    # httpi transport defaults
    adapter: nil,
    follow_redirects: false
  }

  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.



452
453
454
# File 'lib/savon/options.rb', line 452

def convert_attributes_to(converter = nil, &block)
  @options[:convert_attributes_to] = block || converter
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.



432
433
434
# File 'lib/savon/options.rb', line 432

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.



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

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.



426
427
428
# File 'lib/savon/options.rb', line 426

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.



360
361
362
# File 'lib/savon/options.rb', line 360

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

#encoding(encoding) ⇒ Object

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



348
349
350
# File 'lib/savon/options.rb', line 348

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

#endpoint(endpoint) ⇒ Object

SOAP endpoint.



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

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.



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

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.



411
412
413
# File 'lib/savon/options.rb', line 411

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

#headers(headers) ⇒ Object

A Hash of HTTP headers sent with every request.



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

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

#host(host) ⇒ Object

Set a different host for actions in the WSDL.



318
319
320
# File 'lib/savon/options.rb', line 318

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

#log(log) ⇒ Object

Whether or not to log.



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

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

#log_headers(log_headers) ⇒ Object

Whether to log headers.



406
407
408
# File 'lib/savon/options.rb', line 406

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

#log_level(level) ⇒ Object

Changes the Logger's log level.



394
395
396
397
398
399
400
401
402
403
# File 'lib/savon/options.rb', line 394

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.



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

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

#multipart(multipart) ⇒ Object

Instruct Savon to create a multipart response if available.



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

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

#namespace(namespace) ⇒ Object

Target namespace.



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

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

#namespace_identifier(identifier) ⇒ Object

The namespace identifier.



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

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

#namespaces(namespaces) ⇒ Object

Namespaces for the SOAP envelope.



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

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

#no_message_tag(bool) ⇒ Object

Suppress the message tag wrapper around the SOAP body.



467
468
469
# File 'lib/savon/options.rb', line 467

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.



416
417
418
# File 'lib/savon/options.rb', line 416

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.



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

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

#soap_header(header) ⇒ Object

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



353
354
355
# File 'lib/savon/options.rb', line 353

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

#soap_version(soap_version) ⇒ Object

Changes the SOAP version to 1 or 2.



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

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.



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

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

#transport(transport) ⇒ Object

HTTP transport to use. Accepts :httpi (default) or :faraday. When set to :faraday, configure transport concerns directly on the Faraday::Connection returned by client.faraday instead of using the HTTPITransportOptions.



475
476
477
# File 'lib/savon/options.rb', line 475

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

#unwrap(unwrap) ⇒ Object

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



438
439
440
# File 'lib/savon/options.rb', line 438

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

#use_wsa_headers(use) ⇒ Object

Enable inclusion of WS-Addressing headers.



462
463
464
# File 'lib/savon/options.rb', line 462

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

#wsdl(wsdl_address) ⇒ Object

Location of the local or remote WSDL document.



313
314
315
# File 'lib/savon/options.rb', line 313

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