Class: NominetEPP::Client

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

Overview

Front end interface Client to the NominetEPP Service

Constant Summary collapse

SERVICE_URNS =

Standard EPP Services to be used

EPP::Client::DEFAULT_SERVICES
SERVICE_EXTENSION_URNS =

Additional Nominet specific service extensions

%w(
urn:ietf:params:xml:ns:secDNS-1.1
http://www.nominet.org.uk/epp/xml/domain-nom-ext-1.2
http://www.nominet.org.uk/epp/xml/contact-nom-ext-1.0
http://www.nominet.org.uk/epp/xml/std-notifications-1.2
http://www.nominet.org.uk/epp/xml/std-handshake-1.0
http://www.nominet.org.uk/epp/xml/std-warning-1.1
http://www.nominet.org.uk/epp/xml/std-release-1.0
http://www.nominet.org.uk/epp/xml/std-unrenew-1.0
http://www.nominet.org.uk/epp/xml/std-list-1.0
http://www.nominet.org.uk/epp/xml/nom-direct-rights-1.0)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, passwd, server = 'epp.nominet.org.uk', address_family = nil) ⇒ Client

Create a new instance of NominetEPP::Client

Parameters:

  • tag (String)

    Nominet TAG

  • passwd (String)

    Nominet TAG EPP Password

  • server (String) (defaults to: 'epp.nominet.org.uk')

    Nominet EPP Server address (nil forces default)

  • address_family (String) (defaults to: nil)

    ‘AF_INET’ or ‘AF_INET6’ or either of the appropriate socket constants. Will cause connections to be limited to this address family. Default try all addresses.



28
29
30
31
32
# File 'lib/nominet-epp/client.rb', line 28

def initialize(tag, passwd, server = 'epp.nominet.org.uk', address_family = nil)
  @tag, @server = tag, (server || 'epp.nominet.org.uk')
  @client = EPP::Client.new(@tag, passwd, @server, :services => SERVICE_URNS,
    :extensions => SERVICE_EXTENSION_URNS, :address_family => address_family)
end

Class Method Details

.loggerObject



42
43
44
45
46
# File 'lib/nominet-epp/client.rb', line 42

def self.logger
  @@logger ||= Logger.new(STDERR).tap do |l|
    l.level = Logger::ERROR
  end
end

.logger=(l) ⇒ Object



39
40
41
# File 'lib/nominet-epp/client.rb', line 39

def self.logger=(l)
  @@logger = l
end

Instance Method Details

#ack(msgID) ⇒ Object



148
149
150
# File 'lib/nominet-epp/client.rb', line 148

def ack(msgID)
  @client.ack(msgID)
end

#check(entity, *names) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/nominet-epp/client.rb', line 90

def check(entity, *names)
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Check.new(*names)
  res = @client.check(req.command, req.extension)

  mod::CheckResponse.new(res)
end

#check_entity!(entity) ⇒ Object (private)



185
186
187
188
189
# File 'lib/nominet-epp/client.rb', line 185

def check_entity!(entity)
  unless [:domain, :contact, :host, 'domain', 'contact', 'host'].include?(entity)
    raise ArgumentError, "Unsupported entity #{entity}"
  end
end

#create(entity, name, attributes = {}) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/nominet-epp/client.rb', line 100

def create(entity, name, attributes = {})
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Create.new(name, attributes)
  res = @client.create(req.command, req.extension)

  mod::CreateResponse.new(res)
end

#delete(entity, name) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/nominet-epp/client.rb', line 110

def delete(entity, name)
  check_entity! entity

  unless entity == :domain || entity == 'domain'
    raise ArgumentError, "#{entity} entity is not supported for the delete operation at this time"
  end

  mod = module_for_type(entity)
  req = mod::Delete.new(name)
  res = @client.delete(req.command, req.extension)

  mod::DeleteResponse.new(res)
end

#greetingObject



82
83
84
# File 'lib/nominet-epp/client.rb', line 82

def greeting
  @client._greeting
end

#helloObject



86
87
88
# File 'lib/nominet-epp/client.rb', line 86

def hello
  @client.hello
end

#info(entity, name) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/nominet-epp/client.rb', line 124

def info(entity, name)
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Info.new(name)
  res = @client.info(req.command, req.extension)

  mod::InfoResponse.new(res)
end

#inspectObject

See Also:

  • Object#inspect


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

def inspect
  "#<#{self.class} #{@tag}@#{@server}>"
end

#instrument(name, payload = {}) ⇒ Object (private)

Wrapper for ActiveSupport::Notifications if available to perform instrumentation of methods.

Parameters:

  • name (String, Symbol)

    Instrument name. Will be prefixed with “request.nominetepp”.

  • payload (Hash) (defaults to: {})

    Extra information to be included with the instrumentation data.



207
208
209
210
211
212
213
214
215
# File 'lib/nominet-epp/client.rb', line 207

def instrument(name, payload = {})
  if defined?(ActiveSupport::Notifications)
    ActiveSupport::Notifications.instrument("request.nominetepp.#{name}", payload) do
      yield
    end
  else
    yield
  end
end

#last_error_infoHash

Note:

This is presently only set by certain method calls, so it may not always be present.

Returns the last Nominet failData response found

Returns:

  • (Hash)

    last failData found



78
79
80
# File 'lib/nominet-epp/client.rb', line 78

def last_error_info
  @error_info || {}
end

#last_messageString

Returns the last EPP message received

Returns:

  • (String)

    last EPP message

See Also:



69
70
71
# File 'lib/nominet-epp/client.rb', line 69

def last_message
  last_response.message
end

#last_requestEPP::Request

Returns the last EPP::Request sent

Returns:

  • (EPP::Request)

    last sent request



54
55
56
# File 'lib/nominet-epp/client.rb', line 54

def last_request
  @client.last_request
end

#last_responseEPP::Response

Returns the last EPP::Response received

Returns:

  • (EPP::Response)

    last received response



61
62
63
# File 'lib/nominet-epp/client.rb', line 61

def last_response
  @client.last_response
end

#loggerObject



47
48
49
# File 'lib/nominet-epp/client.rb', line 47

def logger
  self.class.logger
end

#module_for_type(name) ⇒ Object (private)



190
191
192
193
194
195
196
197
198
199
# File 'lib/nominet-epp/client.rb', line 190

def module_for_type(name)
  case name
  when :domain, 'domain'
    Domain
  when :contact, 'contact'
    Contact
  when :host, 'host'
    Host
  end
end

#new_checkObject



219
220
221
222
223
224
225
226
227
# File 'lib/nominet-epp/client.rb', line 219

def check(entity, *names)
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Check.new(*names)
  res = @client.check(req.command, req.extension)

  mod::CheckResponse.new(res)
end

#new_createObject



220
221
222
223
224
225
226
227
228
# File 'lib/nominet-epp/client.rb', line 220

def create(entity, name, attributes = {})
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Create.new(name, attributes)
  res = @client.create(req.command, req.extension)

  mod::CreateResponse.new(res)
end

#new_deleteObject



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/nominet-epp/client.rb', line 221

def delete(entity, name)
  check_entity! entity

  unless entity == :domain || entity == 'domain'
    raise ArgumentError, "#{entity} entity is not supported for the delete operation at this time"
  end

  mod = module_for_type(entity)
  req = mod::Delete.new(name)
  res = @client.delete(req.command, req.extension)

  mod::DeleteResponse.new(res)
end

#new_infoObject



225
226
227
228
229
230
231
232
233
# File 'lib/nominet-epp/client.rb', line 225

def info(entity, name)
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Info.new(name)
  res = @client.info(req.command, req.extension)

  mod::InfoResponse.new(res)
end

#new_releaseObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/nominet-epp/client.rb', line 222

def release(entity, name, tag)
  entity = :contact if entity == 'registrant' || entity == :registrant
  check_entity! entity

  if entity == 'host' || entity == :host
    raise ArgumentError, "host entity is not support for the release operation"
  end

  mod = module_for_type(entity)
  req = mod::Release.new(name, tag)
  res = @client.update(req.command, req.extension)

  mod::ReleaseResponse.new(res)
end

#new_renewObject



223
224
225
226
227
228
# File 'lib/nominet-epp/client.rb', line 223

def renew(name, expiry_date, period = '2y')
  req = Domain::Renew.new(name, expiry_date, period)
  res = @client.renew(req.command, req.extension)

  Domain::RenewResponse.new(res)
end

#new_updateObject



224
225
226
227
228
229
230
231
232
# File 'lib/nominet-epp/client.rb', line 224

def update(entity, name, changes = {})
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Update.new(name, changes)
  res = @client.update(req.command, req.extension)

  mod::UpdateResponse.new(res)
end

#old_info_contact(res) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/nominet-epp/client.rb', line 328

def old_info_contact(res)
  {
    :id => res.id,
    :roid => res.roid,
    :status => res.status[0],
    :postal_info => res.postal_info,
    :voice => res.voice,
    :email => res.email,
    :clID => res.client_id,
    :crID => res.creator_id,
    :crDate => res.created_date,
    :type => res.type,
    :trad_name => res.trad_name,
    :co_no => res.co_no,
    :opt_out => res.opt_out
  }
end

#old_info_domain(res) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/nominet-epp/client.rb', line 296

def old_info_domain(res)
  nameservers = res.nameservers.map do |ns|
    h = { :name => ns['name'] }
    h[:v4] = ns['ipv4'] if ns['ipv4']
    h[:v6] = ns['ipv6'] if ns['ipv6']
    h
  end

  {
    :name => res.name,
    :roid => res.roid,
    :registrant => res.registrant,
    :ns => nameservers,
    :host => res.hosts,
    :clID => res.client_id,
    :crID => res.creator_id,
    :crDate => res.created_date,
    :upDate => res.updated_date,
    :exDate => res.expiration_date,
    :reg_status => res.reg_status,
    :first_bill => res.first_bill,
    :recur_bill => res.recur_bill,
    :auto_bill  => res.auto_bill,
    :auto_period => res.auto_period,
    :next_bill  => res.next_bill,
    :next_period => res.next_period,
    :renew_not_required => res.renew_not_required,
    :notes => res.notes,
    :reseller => res.reseller,
    :ds => res.ds
  }
end

#old_info_host(res) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/nominet-epp/client.rb', line 345

def old_info_host(res)
  addrs = res.addresses.try(:dup) || {}
  addrs[:v4] = addrs.delete('ipv4')
  addrs[:v6] = addrs.delete('ipv6')

  addrs[:v4] = addrs[:v4][0] if addrs[:v4].kind_of?(Array)
  addrs[:v6] = addrs[:v6][0] if addrs[:v6].kind_of?(Array)

  {
    :name => res.name,
    :roid => res.roid,
    :status => res.status[0],
    :clID => res.client_id,
    :crID => res.creator_id,
    :crDate => res.created_date,
    :addr => addrs
  }
end

#pollObject



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/nominet-epp/client.rb', line 134

def poll
  while res = @client.poll
    res = Notification.new(res)

    return if res.code != 1301 || res.msgQ['count'] == '0'
    return [res.msgQ['id'], res] unless block_given?

    result = yield res
    return if result == false

    raise AckError, "failed to acknowledge #{res.msgQ['id']}" unless @client.ack(res.msgQ['id'])
  end
end

#release(entity, name, tag) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/nominet-epp/client.rb', line 152

def release(entity, name, tag)
  entity = :contact if entity == 'registrant' || entity == :registrant
  check_entity! entity

  if entity == 'host' || entity == :host
    raise ArgumentError, "host entity is not support for the release operation"
  end

  mod = module_for_type(entity)
  req = mod::Release.new(name, tag)
  res = @client.update(req.command, req.extension)

  mod::ReleaseResponse.new(res)
end

#renew(name, expiry_date, period = '2y') ⇒ Object



167
168
169
170
171
172
# File 'lib/nominet-epp/client.rb', line 167

def renew(name, expiry_date, period = '2y')
  req = Domain::Renew.new(name, expiry_date, period)
  res = @client.renew(req.command, req.extension)

  Domain::RenewResponse.new(res)
end

#update(entity, name, changes = {}) ⇒ Object



174
175
176
177
178
179
180
181
182
# File 'lib/nominet-epp/client.rb', line 174

def update(entity, name, changes = {})
  check_entity! entity

  mod = module_for_type(entity)
  req = mod::Update.new(name, changes)
  res = @client.update(req.command, req.extension)

  mod::UpdateResponse.new(res)
end