Class: NominetEPP::RequestExtension

Inherits:
Object
  • Object
show all
Defined in:
lib/nominet-epp/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#namespacesObject (readonly)

Returns the value of attribute namespaces.



35
36
37
# File 'lib/nominet-epp/request.rb', line 35

def namespaces
  @namespaces
end

Instance Method Details

#namespace_nameObject



44
45
46
47
48
49
50
51
# File 'lib/nominet-epp/request.rb', line 44

def namespace_name
  case namespace_uri
  when /\Aurn\:/
    namespace_uri.split(':').last.split('-',2).first.to_sym
  else
    namespace_uri.split('/').last.split('-')[0...-1].join('-').to_sym
  end
end

#namespace_uriObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/nominet-epp/request.rb', line 41

def namespace_uri
  raise NotImplementedError
end

#schema_name(urn) ⇒ String (protected)

Returns the name of the given schema

Parameters:

  • urn (String)

    Schema URN or URI

Returns:

  • (String)

    the name of the given schema



97
98
99
100
101
102
103
104
# File 'lib/nominet-epp/request.rb', line 97

def schema_name(urn)
  case urn
  when /\Aurn\:/
    urn.split(':').last
  else
    urn.split('/').last
  end
end

#schemaLocationObject



53
54
55
# File 'lib/nominet-epp/request.rb', line 53

def schemaLocation
  "#{namespace_uri} #{schema_name(namespace_uri)}.xsd"
end

#set_namespaces(namespaces) ⇒ Object



37
38
39
# File 'lib/nominet-epp/request.rb', line 37

def set_namespaces(namespaces)
  @namespaces = namespaces
end

#x_namespace(node, name = namespace_name, ns = namespace_uri) ⇒ Object (protected)



83
84
85
86
# File 'lib/nominet-epp/request.rb', line 83

def x_namespace(node, name = namespace_name, ns = namespace_uri)
  return @namespaces[name] if @namespaces.has_key?(name)
  @namespaces[name] = xml_namespace(node, name, ns)
end

#x_node(name, value = nil) ⇒ Object (protected)



77
78
79
80
81
# File 'lib/nominet-epp/request.rb', line 77

def x_node(name, value = nil)
  node = xml_node(name, value)
  node.namespaces.namespace = x_namespace(node)
  node
end

#x_schemaLocation(node, sL = schemaLocation) ⇒ Object (protected)



88
89
90
91
# File 'lib/nominet-epp/request.rb', line 88

def x_schemaLocation(node, sL = schemaLocation)
  xattr = XML::Attr.new(node, "schemaLocation", sL)
  xattr.namespaces.namespace = x_namespace(node, 'xsi', 'http://www.w3.org/2001/XMLSchema-instance')
end

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

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)


73
74
75
# File 'lib/nominet-epp/request.rb', line 73

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

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

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)


63
64
65
# File 'lib/nominet-epp/request.rb', line 63

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