Class: NominetEPP::Client
- Inherits:
-
Object
- Object
- NominetEPP::Client
- 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
- #ack(msgID) ⇒ Object
- #check(entity, *names) ⇒ Object
- #check_entity!(entity) ⇒ Object private
- #create(entity, name, attributes = {}) ⇒ Object
- #delete(entity, name) ⇒ Object
- #greeting ⇒ Object
- #hello ⇒ Object
- #info(entity, name) ⇒ Object
-
#initialize(tag, passwd, server = 'epp.nominet.org.uk', options = {}) ⇒ Client
constructor
Create a new instance of NominetEPP::Client.
- #inspect ⇒ Object
-
#instrument(name, payload = {}) ⇒ Object
private
Wrapper for ActiveSupport::Notifications if available to perform instrumentation of methods.
-
#last_error_info ⇒ Hash
Returns the last Nominet failData response found.
-
#last_message ⇒ String
Returns the last EPP message received.
-
#last_request ⇒ EPP::Request
Returns the last EPP::Request sent.
-
#last_response ⇒ EPP::Response
Returns the last EPP::Response received.
- #logger ⇒ Object
- #module_for_type(name) ⇒ Object private
- #new_check ⇒ Object
- #new_create ⇒ Object
- #new_delete ⇒ Object
- #new_info ⇒ Object
- #new_release ⇒ Object
- #new_renew ⇒ Object
- #new_update ⇒ Object
- #old_info_contact(res) ⇒ Object
- #old_info_domain(res) ⇒ Object
- #old_info_host(res) ⇒ Object
- #poll ⇒ Object
- #release(entity, name, tag) ⇒ Object
- #renew(name, expiry_date, period = '2y') ⇒ Object
- #update(entity, name, changes = {}) ⇒ Object
Constructor Details
#initialize(tag, passwd, server = 'epp.nominet.org.uk', options = {}) ⇒ Client
Create a new instance of NominetEPP::Client
30 31 32 33 34 35 36 |
# File 'lib/nominet-epp/client.rb', line 30 def initialize(tag, passwd, server = 'epp.nominet.org.uk', = {}) = {:address_family => } unless .kind_of?(Hash) # maintain backwards compatibility with old method signature = .merge(:services => SERVICE_URNS, :extensions => SERVICE_EXTENSION_URNS) @tag, @server = tag, (server || 'epp.nominet.org.uk') @client = EPP::Client.new(@tag, passwd, @server, ) end |
Class Method Details
.logger ⇒ Object
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 |
#greeting ⇒ Object
86 87 88 |
# File 'lib/nominet-epp/client.rb', line 86 def greeting @client._greeting end |
#hello ⇒ Object
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 |
#inspect ⇒ Object
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.
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_info ⇒ Hash
This is presently only set by certain method calls, so it may not always be present.
Returns the last Nominet failData response found
82 83 84 |
# File 'lib/nominet-epp/client.rb', line 82 def last_error_info @error_info || {} end |
#last_message ⇒ String
Returns the last EPP message received
73 74 75 |
# File 'lib/nominet-epp/client.rb', line 73 def last_response. end |
#last_request ⇒ EPP::Request
Returns the last EPP::Request sent
58 59 60 |
# File 'lib/nominet-epp/client.rb', line 58 def last_request @client.last_request end |
#last_response ⇒ EPP::Response
Returns the last EPP::Response received
65 66 67 |
# File 'lib/nominet-epp/client.rb', line 65 def last_response @client.last_response end |
#logger ⇒ Object
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_check ⇒ Object
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_create ⇒ Object
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_delete ⇒ Object
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_info ⇒ Object
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_release ⇒ Object
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_renew ⇒ Object
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_update ⇒ Object
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 |
#poll ⇒ Object
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 |