Module: NominetEPP::Helpers

Included in:
Client
Defined in:
lib/nominet-epp/helpers.rb

Overview

Helper methods

Instance Method Summary collapse

Instance Method Details

#account_fields_xml(fields, node, ns) ⇒ Object

Adds the attributes from the fields to the node.

Parameters:

  • fields (Hash)

    Account attributes to marshal

  • node (XML::Node)

    XML Node to add the attributes to

  • ns (XML::Namespace)

    XML Namespace to create the elements under



56
57
58
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/nominet-epp/helpers.rb', line 56

def (fields, node, ns)
  fields.each do |k,v|
    case k
    when :contacts
      v.each do |c|
        node << (c_node = XML::Node.new('contact', nil, ns))
        c_node['order'] = c.delete(:order)
        c_node['type'] = 'admin'

        c_node << contact(c.delete(:action) || 'create') do |cn, cns|
          c.each do |l,w|
            cn << XML::Node.new(l, w, cns)
          end
        end
      end
    when :addr  # Limitation, can only handle one addr at a time
      node << (a_node = XML::Node.new('addr', nil, ns))
      a_node['type'] = 'admin'
      v.each do |l,w|
        a_node << XML::Node.new(l, w, ns)
      end
    else
      node << XML::Node.new(k.to_s.gsub('_', '-'), v, ns)
    end
  end
end

#domain_host_xml(nameserver, ns) ⇒ XML::Node

Returns host element with hostName and optionally ip subelements.

Parameters:

  • nameserver (String, Hash)

    Nameserver host name or hash of :name and :v4 or :v6 address

  • ns (XML::Namespace)

    XML Namespace to create the elements with

Returns:

  • (XML::Node)

    host element with hostName and optionally ip subelements



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nominet-epp/helpers.rb', line 28

def domain_host_xml(nameserver, ns)
  host = XML::Node.new('host', nil, ns)

  case nameserver
  when String
    host << XML::Node.new('hostName', nameserver, ns)
  when Hash
    host << XML::Node.new('hostName', nameserver[:name], ns)
    if nameserver[:v4]
      n = XML::Node.new('hostAddr', nameserver[:v4], ns)
      n['ip'] = 'v4'
      host << n
    end
    if nameserver[:v6]
      n = XML::Node.new('hostAddr', nameserver[:v6], ns)
      n['ip'] = 'v6'
      host << n
    end
  end

  host
end

#domain_ns_xml(nameservers, ns) ⇒ XML::Node

Returns ns element of host elements.

Parameters:

  • nameservers (String, Array)

    Nameserver host name or array of host names or hashes

  • ns (XML::Namespace)

    XML Namespace to create the elements with

Returns:

  • (XML::Node)

    ns element of host elements

See Also:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nominet-epp/helpers.rb', line 8

def domain_ns_xml(nameservers, ns)
  ns_el = XML::Node.new('ns', nil, ns)

  case nameservers
  when String
    ns_el << domain_host_xml(nameservers, ns)
  when Array
    nameservers.each do |nameserver|
      ns_el << domain_host_xml(nameserver, ns)
    end
  else
    raise ArgumentError, "nameservers must either be a string or array"
  end

  ns_el
end