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', options = {}) ⇒ 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)

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

    Options

Options Hash (options):

  • :address_family (String)

    ‘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.

  • :ssl_context (OpenSSL::SSL::SSLContext)

    For client certificate auth



30
31
32
33
34
35
36
# File 'lib/nominet-epp/client.rb', line 30

def initialize(tag, passwd, server = 'epp.nominet.org.uk', options = {})
  options = {:address_family => options} unless options.kind_of?(Hash) # maintain backwards compatibility with old method signature
  options = options.merge(:services => SERVICE_URNS, :extensions => SERVICE_EXTENSION_URNS)

  @tag, @server = tag, (server || 'epp.nominet.org.uk')
  @client = EPP::Client.new(@tag, passwd, @server, options)
end

Class Method Details

.loggerObject



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

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

.logger=(l) ⇒ Object



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

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

Instance Method Details

#ack(msgID) ⇒ Object



152
153
154
# File 'lib/nominet-epp/client.rb', line 152

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

#check(entity, *names) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/nominet-epp/client.rb', line 94

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)



189
190
191
192
193
# File 'lib/nominet-epp/client.rb', line 189

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



104
105
106
107
108
109
110
111
112
# File 'lib/nominet-epp/client.rb', line 104

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



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/nominet-epp/client.rb', line 114

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



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

def greeting
  @client._greeting
end

#helloObject



90
91
92
# File 'lib/nominet-epp/client.rb', line 90

def hello
  @client.hello
end

#info(entity, name) ⇒ Object



128
129
130
131
132
133
134
135
136
# File 'lib/nominet-epp/client.rb', line 128

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


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

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.



211
212
213
214
215
216
217
218
219
# File 'lib/nominet-epp/client.rb', line 211

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



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

def last_error_info
  @error_info || {}
end

#last_messageString

Returns the last EPP message received

Returns:

  • (String)

    last EPP message

See Also:



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

def last_message
  last_response.message
end

#last_requestEPP::Request

Returns the last EPP::Request sent

Returns:

  • (EPP::Request)

    last sent request



58
59
60
# File 'lib/nominet-epp/client.rb', line 58

def last_request
  @client.last_request
end

#last_responseEPP::Response

Returns the last EPP::Response received

Returns:

  • (EPP::Response)

    last received response



65
66
67
# File 'lib/nominet-epp/client.rb', line 65

def last_response
  @client.last_response
end

#loggerObject



51
52
53
# File 'lib/nominet-epp/client.rb', line 51

def logger
  self.class.logger
end

#module_for_type(name) ⇒ Object (private)



194
195
196
197
198
199
200
201
202
203
# File 'lib/nominet-epp/client.rb', line 194

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

#new_checkObject



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

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



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

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



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

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



229
230
231
232
233
234
235
236
237
# File 'lib/nominet-epp/client.rb', line 229

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



226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/nominet-epp/client.rb', line 226

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



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

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



228
229
230
231
232
233
234
235
236
# File 'lib/nominet-epp/client.rb', line 228

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



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/nominet-epp/client.rb', line 332

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



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
328
329
330
331
# File 'lib/nominet-epp/client.rb', line 300

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



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/nominet-epp/client.rb', line 349

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



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/nominet-epp/client.rb', line 138

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



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/nominet-epp/client.rb', line 156

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



171
172
173
174
175
176
# File 'lib/nominet-epp/client.rb', line 171

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



178
179
180
181
182
183
184
185
186
# File 'lib/nominet-epp/client.rb', line 178

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