nominet-epp 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.0.5 / 2011-02-24
2
+ ==================
3
+
4
+ * Many bug fixes in Create operation
5
+ * Support for using `host:update` to modify name server glue information.
6
+
1
7
  0.0.4 / 2011-01-31
2
8
  ==================
3
9
 
data/README.rdoc CHANGED
@@ -1,6 +1,12 @@
1
- = nominet-epp
1
+ = Nominet EPP
2
2
 
3
- Description goes here.
3
+ Ruby interface to the {Nominet EPP}[http://www.nominet.org.uk/registrars/systems/nominetepp] registrar interface.
4
+
5
+ == Initialise a client
6
+
7
+ require 'nominet-epp'
8
+ client = NominetEPP::Client.new('TAGNAME', 'password')
9
+ testclient = NominetEPP::Client.new('TAGNAME', 'password', 'testbed-epp.nominet.org.uk')
4
10
 
5
11
  == Note on Patches/Pull Requests
6
12
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -8,15 +8,15 @@ module NominetEPP
8
8
  def domain_ns_xml(nameservers, ns)
9
9
  ns_el = XML::Node.new('ns', nil, ns)
10
10
 
11
- case nameservers.class
11
+ case nameservers
12
12
  when String
13
- ns_el << (XML::Node.new('host', nil, ns) << XML::Node.new('hostName', nameservers, ns))
13
+ ns_el << domain_host_xml(nameservers, ns)
14
14
  when Array
15
15
  nameservers.each do |nameserver|
16
16
  ns_el << domain_host_xml(nameserver, ns)
17
17
  end
18
18
  else
19
- raise ArgumentError, "nameservers must either be a string or array of strings"
19
+ raise ArgumentError, "nameservers must either be a string or array"
20
20
  end
21
21
 
22
22
  ns_el
@@ -28,7 +28,7 @@ module NominetEPP
28
28
  def domain_host_xml(nameserver, ns)
29
29
  host = XML::Node.new('host', nil, ns)
30
30
 
31
- case nameserver.class
31
+ case nameserver
32
32
  when String
33
33
  host << XML::Node.new('hostName', nameserver, ns)
34
34
  when Hash
@@ -22,8 +22,8 @@ module NominetEPP
22
22
  # - (Integer) +:order+ -- Contacts order in the list of contacts
23
23
  #
24
24
  # @param [String] name Domain name to register
25
- # @param [String] acct
26
- # @param [Array] nameservers Nameservers to set for the domain
25
+ # @param [String, Hash] acct
26
+ # @param [String, Array] nameservers Nameservers to set for the domain
27
27
  # @param [Hash] options Registration options
28
28
  # @option options [String] :period
29
29
  # @option options [String] :first_bill
@@ -57,7 +57,7 @@ module NominetEPP
57
57
 
58
58
  return false unless @resp.success?
59
59
 
60
- creData = @resp.data.find('/domain:creData', namespaces).first
60
+ creData = @resp.data.find('//domain:creData', namespaces).first
61
61
  h = { :name => node_value(creData, 'domain:name'),
62
62
  :crDate => Time.parse(node_value(creData, 'domain:crDate')),
63
63
  :exDate => Time.parse(node_value(creData, 'domain:exDate')) }
@@ -86,11 +86,11 @@ module NominetEPP
86
86
 
87
87
  acct[:contacts].each_with_index do |cont, i|
88
88
  c = XML::Node.new('contact', nil, ns)
89
- c['order'] = i
89
+ c['order'] = i.to_s
90
90
  node << (c << create_account_contact(cont))
91
91
  end
92
92
 
93
- node << create_account_address(acct[:addr], ns)
93
+ node << create_account_address(acct[:addr], ns) unless acct[:addr].nil?
94
94
  end
95
95
  else
96
96
  raise ArgumentError, "acct must be String or Hash"
@@ -104,7 +104,8 @@ module NominetEPP
104
104
  # @raise [ArgumentError] name or email key is missing
105
105
  # @return [XML::Node]
106
106
  def create_account_contact(cont)
107
- raise ArgumentError, "Contact allowed keys are name, email, phone and mobile" unless (cont.keys -[:name, :email, :phone, :mobile]).empty?
107
+ raise ArgumentError, "cont must be a hash" unless cont.is_a?(Hash)
108
+ raise ArgumentError, "Contact allowed keys are name, email, phone and mobile" unless (cont.keys - [:name, :email, :phone, :mobile]).empty?
108
109
  raise ArgumentError, "Contact requires name and email keys" unless cont.has_key?(:name) && cont.has_key?(:email)
109
110
 
110
111
  contact('create') do |node, ns|
@@ -117,9 +118,12 @@ module NominetEPP
117
118
  # Create contact address
118
119
  #
119
120
  # @param [Hash] addr Address fields
121
+ # @param [XML::Namespace] ns XML Namespace
120
122
  # @raise [ArgumentError] invalid keys in addr
121
123
  # @return [XML::Node]
122
124
  def create_account_address(addr, ns)
125
+ raise ArgumentError, "addr must be a hash" unless addr.is_a?(Hash)
126
+ raise ArgumentError, "ns must be an xml namespace" unless ns.is_a?(XML::Namespace)
123
127
  raise ArgumentError, "Address allowed keys are street, locality, city, county, postcode, country" unless (addr.keys - [:street, :locality, :city, :county, :postcode, :country]).empty?
124
128
 
125
129
  addr = XML::Node.new('addr', nil, ns)
@@ -1,10 +1,59 @@
1
1
  module NominetEPP
2
2
  module Operations
3
- # EPP Update Operation
3
+ # == EPP Update Operation
4
+ #
5
+ # === Domain Update
6
+ # The +id+ field for domain updates is the domain name to be modified.
7
+ #
8
+ # Fields options
9
+ # - (Hash) +:account+ -- Hash of account details to be updated
10
+ # - (String,Hash) +:ns+ -- Single or array of nameservers to set on the domain
11
+ # - (String) +:first_bill+ -- Set first-bill
12
+ # - (String) +:recur_bill+ -- Set recur-bill
13
+ # - (String) +:auto_bill+ -- Set auto-bill
14
+ # - (String) +:purchase_order+ -- Set purchase-oder
15
+ # - (String) +:notes+ -- Notes about the domain
16
+ # - (Boolean) +:renew_not_required+ -- Mark a domain as no longer needed
17
+ # - (String) +:reseller+ -- Set reseller
18
+ # ... etc ... any other permitted account fields
19
+ #
20
+ # === Account Update
21
+ # The +id+ field for account updates is the ROID identifying
22
+ # the account record on the remote endpoint.
23
+ #
24
+ # Fields options
25
+ # - (Array) +:contacts+ -- Array of contacts to create on the account
26
+ # - (Hash) +:addr+ -- Hash of address fields to modify on the account
27
+ # - (String) +:name+ -- Account holder name
28
+ # ... etc ... any other permitted account fields
29
+ #
30
+ # === Contact Update
31
+ # The +id+ field for contact updates is the ROID identifying
32
+ # the contact record on the remote endpoint.
33
+ #
34
+ # Fields options
35
+ # - (String) +:name+ -- Contacts new name
36
+ # - (String) +:email+ -- Contacts new email address
37
+ # - (String) +:phone+ -- Contacts new phone number
38
+ # - (String) +:mobile+ -- Contacts new mobile number
39
+ #
40
+ # === Nameserver Update
41
+ # The +id+ field for nameserver updates is the fully qualified
42
+ # hostname for the name server you wish to update.
43
+ #
44
+ # Fields options
45
+ # - (Hash) +:add+ -- Addresses to add to the nameserver
46
+ # - (Hash) +:rem+ -- Addresses to remove from the nameserver
47
+ # - (String) +:chg+ -- New hostname of the nameserver
48
+ #
49
+ # Fields +:add+ and +:rem+ options
50
+ # - (String) +:v4+ -- IPv4 address to add or remove from the nameserver
51
+ # - (String) +:v6+ -- IPv6 address to add or remove from the nameserver
4
52
  module Update
5
- # @param [Symbol] entity Entity to update
6
- # @param [String] id Domain, Account or Contact to update
53
+ # @param [Symbol] entity Entity to update, one of domain, account, contact or nameserver
54
+ # @param [String] id Domain, Account, Contact or Nameserver to update
7
55
  # @param [Hash] fields Fields to update
56
+ # @return [Boolean] request successful
8
57
  def update(entity, id, fields = {})
9
58
  @resp = @client.update do
10
59
  self.send(:"update_#{entity}", id, fields)
@@ -62,6 +111,62 @@ module NominetEPP
62
111
  end
63
112
  end
64
113
  end
114
+
115
+ # Generate +host:update+ payload to modify a nameserver entry
116
+ # ---
117
+ # We need to know nameserver old data as well.
118
+ # If we are changing the nameserver name and keeping the info the same
119
+ # then we do a host:chg. If we are adding an IPv{4,6} address we use
120
+ # the host:add wrapper, and to remove we do a host:rem. As Nominet only
121
+ # allow one IPv{4,6} address per nameserver we should remove the old
122
+ # IP address from the server before adding the one. Alternatively if
123
+ # Nominet will automatically drop previous address then we need only
124
+ # do a host:add call.
125
+ # +++
126
+ #
127
+ # Fields options
128
+ # - (Hash) +:add+ -- Addresses to add to the nameserver
129
+ # - (Hash) +:rem+ -- Addresses to remove from the nameserver
130
+ # - (String) +:chg+ -- New hostname of the nameserver
131
+ #
132
+ # Fields +:add+ and +:rem+ options
133
+ # - (String) +:v4+ -- IPv4 address to add or remove from the nameserver
134
+ # - (String) +:v6+ -- IPv6 address to add or remove from the nameserver
135
+ #
136
+ # @param [String] name Nameserver host to update
137
+ # @param [Hash] fields Nameserver update information
138
+ # @raise [ArgumentError] invalid keys, either on fields or fields[:add] or fields[:rem]
139
+ # @return [XML::Node] +host:update+ payload
140
+ def update_nameserver(name, fields = {})
141
+ raise ArgumentError, "allowed keys :add, :rem, :chg" unless (fields.keys - [:add, :rem, :chg]).empty?
142
+
143
+ host('update') do |node, ns|
144
+ node << XML::Node.new('name', name, ns)
145
+
146
+ if fields.has_key?(:add) && fields[:add].kind_of?(Hash)
147
+ raise ArgumentError, "allowed :add keys are :v4 and :v6" unless (fields[:add].keys - [:v4, :v6]).empty?
148
+ node << (add = XML::Node.new('add', nil, ns))
149
+ fields[:add].each do |k,v|
150
+ add << (n = XML::Node.new('addr', v, ns))
151
+ n['ip'] = k.to_s
152
+ end
153
+ end
154
+
155
+ if fields.has_key?(:rem) && fields[:rem].kind_of?(Hash)
156
+ raise ArgumentError, "allowed :rem keys are :v4 and :v6" unless (fields[:rem].keys - [:v4, :v6]).empty?
157
+ node << (rem = XML::Node.new('rem', nil, ns))
158
+ fields[:rem].each do |k,v|
159
+ rem << (n = XML::Node.new('addr', v, ns))
160
+ n['ip'] = k.to_s
161
+ end
162
+ end
163
+
164
+ if fields.has_key?(:chg) && fields[:chg].kind_of?(String)
165
+ node << (chg = XML::Node.new('chg', nil, ns))
166
+ chg << XML::Node.new('name', fields[:chg], ns)
167
+ end
168
+ end
169
+ end
65
170
  end
66
171
  end
67
172
  end
data/lib/nominet-epp.rb CHANGED
@@ -49,7 +49,8 @@ module NominetEPP
49
49
  :account => 'http://www.nominet.org.uk/epp/xml/nom-account-2.0',
50
50
  :contact => 'http://www.nominet.org.uk/epp/xml/nom-contact-2.0',
51
51
  :tag => 'http://www.nominet.org.uk/epp/xml/nom-tag-1.0',
52
- :n => 'http://www.nominet.org.uk/epp/xml/nom-notifications-2.0' }
52
+ :n => 'http://www.nominet.org.uk/epp/xml/nom-notifications-2.0',
53
+ :host => 'urn:ietf:params:xml:ns:host-1.0' }
53
54
  end
54
55
 
55
56
  # @return [Hash] Nominet Schema Locations by prefix
@@ -97,7 +98,7 @@ module NominetEPP
97
98
  def new_node(name, ns_prefix, &block)
98
99
  node = XML::Node.new(name)
99
100
  node.namespaces.namespace = ns = XML::Namespace.new(node, ns_prefix.to_s, namespaces[ns_prefix])
100
- node['xsi:schemaLocation'] = schemaLocations[ns_prefix]
101
+ node['xsi:schemaLocation'] = schemaLocations[ns_prefix] if schemaLocations.has_key?(ns_prefix)
101
102
 
102
103
  case block.arity
103
104
  when 0
@@ -150,5 +151,13 @@ module NominetEPP
150
151
  def notification(node_name, &block)
151
152
  new_node(node_name, :n, &block)
152
153
  end
154
+
155
+ # @param [String] node_name XML Element name
156
+ # @yield [node, ns] block to populate node
157
+ # @return [XML::Node] new node in :host namespace
158
+ # @see new_node
159
+ def host(node_name, &block)
160
+ new_node(node_name, :host, &block)
161
+ end
153
162
  end
154
163
  end
data/nominet-epp.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nominet-epp}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Geoff Garside"]
12
- s.date = %q{2011-01-31}
12
+ s.date = %q{2011-02-24}
13
13
  s.description = %q{Client for communicating with the Nominet EPP}
14
14
  s.email = %q{geoff@geoffgarside.co.uk}
15
15
  s.extra_rdoc_files = [
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  ]
48
48
  s.homepage = %q{http://github.com/geoffgarside/nominet-epp}
49
49
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.4.2}
50
+ s.rubygems_version = %q{1.5.2}
51
51
  s.summary = %q{Nominet EPP (Extensible Provisioning Protocol) Client}
52
52
  s.test_files = [
53
53
  "test/helper.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nominet-epp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Geoff Garside
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 +00:00
18
+ date: 2011-02-24 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements: []
128
128
 
129
129
  rubyforge_project:
130
- rubygems_version: 1.4.2
130
+ rubygems_version: 1.5.2
131
131
  signing_key:
132
132
  specification_version: 3
133
133
  summary: Nominet EPP (Extensible Provisioning Protocol) Client