module WSDL
module Request
class RPCWrapper
def initialize(operation_name:, namespace_uri:)
@operation_name = operation_name
@namespace_uri = namespace_uri
end
def wrap(document)
return document if document.body.empty?
return document if already_wrapped?(document.body)
build_wrapped_document(document)
end
private
def already_wrapped?(body_nodes)
body_nodes.length == 1 && body_nodes.first.local_name == @operation_name
end
def build_wrapped_document(document)
wrapped = Envelope.new
wrapped.namespace_decls.concat(document.namespace_decls)
wrapped..concat(document.)
wrapped.body << build_wrapper(document.body)
wrapped
end
def build_wrapper(children)
wrapper = Node.new(
name: @operation_name,
prefix: nil,
local_name: @operation_name,
namespace_uri: @namespace_uri
)
wrapper.children.concat(children)
wrapper
end
end
end
end