class Savon::Builder
Constants
- SCHEMA_TYPES
- SOAP_NAMESPACE
Public Class Methods
new(operation_name, wsdl, globals, locals)
click to toggle source
# File lib/savon/builder.rb, line 20 def initialize(operation_name, wsdl, globals, locals) @operation_name = operation_name @wsdl = wsdl @globals = globals @locals = locals @types = convert_type_definitions_to_hash @used_namespaces = convert_type_namespaces_to_hash end
Public Instance Methods
pretty()
click to toggle source
# File lib/savon/builder.rb, line 31 def pretty Nokogiri.XML(to_s).to_xml(:indent => 2) end
to_s()
click to toggle source
# File lib/savon/builder.rb, line 35 def to_s return @locals[:xml] if @locals.include? :xml tag(builder, :Envelope, namespaces_with_globals) do |xml| tag(xml, :Header) { xml << header.to_s } unless header.empty? tag(xml, :Body) { xml.tag!(*namespaced_message_tag) { xml << message.to_s } } end end
Private Instance Methods
builder()
click to toggle source
# File lib/savon/builder.rb, line 151 def builder builder = ::Builder::XmlMarkup.new builder.instruct!(:xml, :encoding => @globals[:encoding]) builder end
convert_type_definitions_to_hash()
click to toggle source
# File lib/savon/builder.rb, line 46 def convert_type_definitions_to_hash @wsdl.type_definitions.inject({}) do |memo, (path, type)| memo[path] = type memo end end
convert_type_namespaces_to_hash()
click to toggle source
# File lib/savon/builder.rb, line 53 def convert_type_namespaces_to_hash @wsdl.type_namespaces.inject({}) do |memo, (path, uri)| key, value = use_namespace(path, uri) memo[key] = value memo end end
env_namespace()
click to toggle source
# File lib/savon/builder.rb, line 95 def env_namespace @env_namespace ||= @globals[:env_namespace] || :env end
header()
click to toggle source
# File lib/savon/builder.rb, line 99 def header @header ||= Header.new(@globals, @locals) end
message()
click to toggle source
# File lib/savon/builder.rb, line 126 def message element_form_default = @globals[:element_form_default] || @wsdl.element_form_default # TODO: clean this up! [dh, 2012-12-17] Message.new(message_tag, namespace_identifier, @types, @used_namespaces, @locals[:message], element_form_default, @globals[:convert_request_keys_to]) end
message_attributes()
click to toggle source
# File lib/savon/builder.rb, line 122 def message_attributes @locals[:attributes] || {} end
message_tag()
click to toggle source
# File lib/savon/builder.rb, line 114 def message_tag message_tag = @locals[:message_tag] message_tag ||= @wsdl.soap_input(@operation_name.to_sym) if @wsdl.document? message_tag ||= Gyoku.xml_tag(@operation_name, :key_converter => @globals[:convert_request_keys_to]) @message_tag = message_tag.to_sym end
namespace_by_uri(uri)
click to toggle source
# File lib/savon/builder.rb, line 144 def namespace_by_uri(uri) namespaces.each do |candidate_identifier, candidate_uri| return candidate_identifier.gsub(/^xmlns:/, '') if candidate_uri == uri end nil end
namespace_identifier()
click to toggle source
# File lib/savon/builder.rb, line 133 def namespace_identifier return @globals[:namespace_identifier] if @globals.include? :namespace_identifier return @namespace_identifier if @namespace_identifier operation = @wsdl.operations[@operation_name] if @wsdl.document? namespace_identifier = operation[:namespace_identifier] if operation namespace_identifier ||= "wsdl" @namespace_identifier = namespace_identifier.to_sym end
namespaced_message_tag()
click to toggle source
# File lib/savon/builder.rb, line 103 def namespaced_message_tag tag_name = message_tag if namespace_identifier == nil [tag_name, message_attributes] elsif @used_namespaces[[tag_name.to_s]] [@used_namespaces[[tag_name.to_s]], tag_name, message_attributes] else [namespace_identifier, tag_name, message_attributes] end end
namespaces()
click to toggle source
# File lib/savon/builder.rb, line 77 def namespaces @namespaces ||= begin namespaces = SCHEMA_TYPES.dup if namespace_identifier == nil namespaces["xmlns"] = @globals[:namespace] || @wsdl.namespace else namespaces["xmlns:#{namespace_identifier}"] = @globals[:namespace] || @wsdl.namespace end key = ["xmlns"] key << env_namespace if env_namespace && env_namespace != "" namespaces[key.join(":")] = SOAP_NAMESPACE[@globals[:soap_version]] namespaces end end
namespaces_with_globals()
click to toggle source
# File lib/savon/builder.rb, line 73 def namespaces_with_globals namespaces.merge @globals[:namespaces] end
tag(xml, name, namespaces = {}, &block)
click to toggle source
# File lib/savon/builder.rb, line 157 def tag(xml, name, namespaces = {}, &block) if env_namespace && env_namespace != "" xml.tag! env_namespace, name, namespaces, &block else xml.tag! name, namespaces, &block end end
use_namespace(path, uri)
click to toggle source
# File lib/savon/builder.rb, line 61 def use_namespace(path, uri) @internal_namespace_count ||= 0 unless identifier = namespace_by_uri(uri) identifier = "ins#{@internal_namespace_count}" namespaces["xmlns:#{identifier}"] = uri @internal_namespace_count += 1 end [path, identifier] end