Class: Savon::Builder
- Inherits:
-
Object
- Object
- Savon::Builder
- Defined in:
- lib/savon/builder.rb
Overview
Builds the SOAP request for an operation: the XML envelope, or a multipart/related message when the request carries attachments (SOAP with Attachments, https://www.w3.org/TR/SOAP-attachments).
It owns the envelope structure, its namespace declarations, and the body, and signs the document when a WSSE signature is present. Message-body serialization is delegated to Message, the Header element to Header, and Hash-to-XML conversion to Gyoku.
Constant Summary collapse
- SCHEMA_TYPES =
{ "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance" }.freeze
- SOAP_NAMESPACE =
{ 1 => "http://schemas.xmlsoap.org/soap/envelope/", 2 => "http://www.w3.org/2003/05/soap-envelope" }.freeze
- WSA_NAMESPACE =
Deprecated.
Use Addressing::NAMESPACE instead. This alias will be removed in Savon 3.0.
Addressing::NAMESPACE
Instance Attribute Summary collapse
-
#multipart ⇒ Object
readonly
Returns the value of attribute multipart.
Instance Method Summary collapse
- #body_attributes ⇒ Object
- #build_document ⇒ Object
-
#header_attributes ⇒ Hash{String => String}
Returns the XML attributes of the envelope's Header element, provided by the header's sections.
-
#initialize(operation_name, wsdl, globals, locals) ⇒ Builder
constructor
A new instance of Builder.
- #pretty ⇒ Object
-
#to_s ⇒ Object
Returns the request body as a String.
Constructor Details
#initialize(operation_name, wsdl, globals, locals) ⇒ Builder
Returns a new instance of Builder.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/savon/builder.rb', line 42 def initialize(operation_name, wsdl, globals, locals) @operation_name = operation_name @wsdl = wsdl @globals = globals @locals = locals @effective = EffectiveOptions.new(operation_name, wsdl, globals, locals) @signature = @effective.wsse_signature @types = convert_type_definitions_to_hash @used_namespaces = convert_type_namespaces_to_hash end |
Instance Attribute Details
#multipart ⇒ Object (readonly)
Returns the value of attribute multipart.
21 22 23 |
# File 'lib/savon/builder.rb', line 21 def multipart @multipart end |
Instance Method Details
#body_attributes ⇒ Object
91 92 93 |
# File 'lib/savon/builder.rb', line 91 def body_attributes @body_attributes ||= @signature.nil? ? {} : @signature.body_attributes end |
#build_document ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/savon/builder.rb', line 59 def build_document xml_result = build_xml # if we have a signature sign the document if @signature @signature.document = xml_result 2.times do @header = nil @signature.document = build_xml end xml_result = @signature.document end # if there are attachments for the request, we should build a multipart message according to # https://www.w3.org/TR/SOAP-attachments if @locals[:attachments] (xml_result) else xml_result end end |
#header_attributes ⇒ Hash{String => String}
Returns the XML attributes of the envelope's Header element, provided by the header's sections.
87 88 89 |
# File 'lib/savon/builder.rb', line 87 def header_attributes header.attributes end |
#pretty ⇒ Object
55 56 57 |
# File 'lib/savon/builder.rb', line 55 def pretty Nokogiri.XML(to_s).to_xml(indent: 2) end |
#to_s ⇒ Object
Returns the request body as a String. When the caller supplies a pre-built envelope via the :xml local option it is used verbatim, but it must still be wrapped in a multipart message when :attachments are present. Otherwise the attachments are silently dropped.
99 100 101 102 103 104 105 106 |
# File 'lib/savon/builder.rb', line 99 def to_s if @locals.include?(:xml) xml = @locals[:xml] @locals[:attachments] ? (xml) : xml else build_document end end |