Class: Savon::EffectiveOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/effective_options.rb

Overview

Resolves the effective value of options whose answer combines more than one source: the per-request options, the client options, the WSDL document, and built-in defaults.

GlobalOptions and LocalOptions store what the caller said. EffectiveOptions answers what the request uses. It owns the precedence rules and exposes one reader per resolvable option, so every consumer of an option resolves it identically. Resolution is a pure read. It never mutates the options or the WSDL document.

Instance Method Summary collapse

Constructor Details

#initialize(operation_name, wsdl, globals, locals) ⇒ EffectiveOptions

Returns a new instance of EffectiveOptions.

Parameters:

  • operation_name (Symbol)

    the SOAP operation being called

  • wsdl (Wasabi::Document)

    the parsed WSDL, or an empty document when the client was configured without one

  • globals (Savon::GlobalOptions)

    the client-level options

  • locals (Savon::LocalOptions)

    the per-request options



22
23
24
25
26
27
# File 'lib/savon/effective_options.rb', line 22

def initialize(operation_name, wsdl, globals, locals)
  @operation_name = operation_name
  @wsdl           = wsdl
  @globals        = globals
  @locals         = locals
end

Instance Method Details

#endpointURI, ...

Resolves the endpoint URL the request is sent to.

A global :endpoint wins over the service address of the WSDL. The global :host option replaces host and port of the WSDL address and keeps scheme, path and query. The override is applied to a copy. The WSDL document keeps its parsed address.

Returns:

  • (URI, String, nil)

    the endpoint as provided by the winning source



54
55
56
57
58
59
60
61
62
63
# File 'lib/savon/effective_options.rb', line 54

def endpoint
  return @globals[:endpoint] if @globals[:endpoint]
  return @wsdl.endpoint unless @globals[:host]

  host_url = URI.parse(@globals[:host])
  url      = @wsdl.endpoint.dup
  url.host = host_url.host
  url.port = host_url.port
  url
end

#soap_actionString?

Resolves the SOAPAction of the request (SOAP 1.1 §6.1.1).

An explicit local :soap_action wins. A local false or nil disables the action, so no SOAPAction HTTP header is sent and an enabled wsa:Action header stays empty. Without a local value the WSDL provides the soapAction of the operation. Without a WSDL document the operation name is converted to an XML tag as a best-effort default.

Returns:

  • (String, nil)

    the action, or nil when explicitly disabled



38
39
40
41
42
43
44
# File 'lib/savon/effective_options.rb', line 38

def soap_action
  return if @locals.include?(:soap_action) && !@locals[:soap_action]

  @locals[:soap_action] ||
    (@wsdl.document? && @wsdl.soap_action(@operation_name.to_sym)) ||
    Gyoku.xml_tag(@operation_name, key_converter: @globals[:convert_request_keys_to])
end

#soap_headerHash, ...

Resolves the SOAP header content. When both scopes provide a Hash the two are merged and local keys win. Otherwise the local value is preferred and falls back to the global one. A Hash is rendered to XML by Gyoku. A String, or any object responding to #to_s, is used verbatim.

Returns:

  • (Hash, String, nil)


101
102
103
104
105
106
107
108
109
110
# File 'lib/savon/effective_options.rb', line 101

def soap_header
  global = @globals[:soap_header]
  local  = @locals[:soap_header]

  if global.is_a?(Hash) && local.is_a?(Hash)
    global.merge(local)
  else
    local || global
  end
end

#wsse_authArray<String>, ...

Resolves the WSSE auth credentials passed to Akami. A local value takes precedence over the global one. A local false disables auth even when a global value is set. A local nil leaves the option unset and falls through to the global value.

Returns:

  • (Array<String>, false, nil)

    the credentials, false to disable, or nil when unset in both scopes



72
73
74
# File 'lib/savon/effective_options.rb', line 72

def wsse_auth
  prefer_local(:wsse_auth)
end

#wsse_signatureAkami::WSSE::Signature?

Resolves the WSSE signature used to sign the request. This option is a signature object or nil and has no "disable" value, so any falsy local value falls back to the global one. Builder and Header both read it and must resolve it identically.

Returns:

  • (Akami::WSSE::Signature, nil)


91
92
93
# File 'lib/savon/effective_options.rb', line 91

def wsse_signature
  @locals[:wsse_signature] || @globals[:wsse_signature]
end

#wsse_timestampBoolean?

Resolves whether Akami emits a wsu:Timestamp header, using the same local-over-global rule as #wsse_auth. A local false disables it and a local nil keeps the global value.

Returns:

  • (Boolean, nil)


81
82
83
# File 'lib/savon/effective_options.rb', line 81

def wsse_timestamp
  prefer_local(:wsse_timestamp)
end