Module: EPP::XMLHelpers

Included in:
Commands::Command, Contact::Command, Domain::Command, Host::Command, Request, Requests::Abstract
Defined in:
lib/epp-client/xml_helper.rb

Instance Method Summary collapse

Instance Method Details

#as_xml(obj) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/epp-client/xml_helper.rb', line 58

def as_xml(obj)
  return obj.to_xml if obj.respond_to?(:to_xml)

  case obj
  when String
    XML::Document.string(obj).root
  when XML::Node
    obj
  when XML::Document
    obj.root
  end
end

#epp_namespace(node, name = nil, namespaces = {}) ⇒ XML::Namespace

Creates and returns an instance of the EPP 1.0 namespace

Parameters:

  • node (XML::Node)

    to create the namespace on

  • Name (String, nil)

    to give the namespace

Returns:

  • (XML::Namespace)

    EPP 1.0 namespace



8
9
10
11
# File 'lib/epp-client/xml_helper.rb', line 8

def epp_namespace(node, name = nil, namespaces = {})
  return namespaces['epp'] if namespaces.has_key?('epp')
  xml_namespace(node, name, 'urn:ietf:params:xml:ns:epp-1.0')
end

#epp_node(name, value = nil, namespaces = {}) ⇒ XML::Node

Creates and returns a new node in the EPP 1.0 namespace

Parameters:

  • name (String)

    of the node to create

  • value (String, XML::Node, nil) (defaults to: nil)

    of the node

Returns:

  • (XML::Node)


18
19
20
21
22
23
24
# File 'lib/epp-client/xml_helper.rb', line 18

def epp_node(name, value = nil, namespaces = {})
  value, namespaces = nil, value if value.kind_of?(Hash)

  node = xml_node(name, value)
  node.namespaces.namespace = epp_namespace(node, nil, namespaces)
  node
end

#xml_document(obj) ⇒ XML::Document

Creates and returns a new XML document

Parameters:

  • obj (XML::Document, String)

    Object to create the document with

Returns:

  • (XML::Document)


49
50
51
52
53
54
55
56
# File 'lib/epp-client/xml_helper.rb', line 49

def xml_document(obj)
  case obj
  when XML::Document
    XML::Document.document(obj)
  else
    XML::Document.new('1.0')
  end
end

#xml_namespace(node, name, uri, namespaces = {}) ⇒ XML::Namespace

Creates and returns a new XML namespace

Parameters:

  • node (XML::Node)

    XML node to add the namespace to

  • name (String)

    Name of the namespace to create

  • uri (String)

    URI of the namespace to create

Returns:

  • (XML::Namespace)


41
42
43
# File 'lib/epp-client/xml_helper.rb', line 41

def xml_namespace(node, name, uri, namespaces = {})
  XML::Namespace.new(node, name, uri)
end

#xml_node(name, value = nil) ⇒ XML::Node

Creates and returns a new XML node

Parameters:

  • name (String)

    of the node to create

  • value (String, XML::Node, nil) (defaults to: nil)

    of the node

Returns:

  • (XML::Node)


31
32
33
# File 'lib/epp-client/xml_helper.rb', line 31

def xml_node(name, value = nil)
  XML::Node.new(name, value)
end