Module: EPPClient::Domain

Included in:
Base
Defined in:
lib/epp-client/domain.rb

Overview

This module handles all the Domain interactions.!

See RFC 5731 for more informations

Instance Method Summary collapse

Instance Method Details

#domain_check(*domains) ⇒ Object

Check the availability of domains

takes a list of domains as arguments

returns an array of hashes containing three fields :

:name

The domain name

:avail

Wether the domain is available or not.

:reason

The reason for non availability, if given.



29
30
31
32
33
34
# File 'lib/epp-client/domain.rb', line 29

def domain_check(*domains)
  domains.flatten!
  response = send_request(domain_check_xml(*domains))

  get_result(:xml => response, :callback => :domain_check_process)
end

#domain_check_process(xml) ⇒ Object

:nodoc:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/epp-client/domain.rb', line 36

def domain_check_process(xml) # :nodoc:
  xml.xpath('epp:resData/domain:chkData/domain:cd', EPPClient::SCHEMAS_URL).map do |dom|
    ret = {
      :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
      :avail => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).attr('avail').value == '1',
    }
    unless (reason = dom.xpath('domain:reason', EPPClient::SCHEMAS_URL).text).empty?
      ret[:reason] = reason
    end
    ret
  end
end

#domain_check_xml(*domains) ⇒ Object

:nodoc:



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/epp-client/domain.rb', line 9

def domain_check_xml(*domains) # :nodoc:
  command do |xml|
    xml.check do
      xml.check('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        domains.each do |dom|
          xml.name(dom)
        end
      end
    end
  end
end

#domain_contacts_xml(xml, args) ⇒ Object

:nodoc:



206
207
208
209
210
211
212
# File 'lib/epp-client/domain.rb', line 206

def domain_contacts_xml(xml, args) #:nodoc:
  args.each do |type, contacts|
    contacts.each do |c|
      xml.contact({ :type => type }, c)
    end
  end
end

#domain_create(args) ⇒ Object

Creates a domain

Takes a hash as an argument, containing the following keys :

:name

the domain name

:period

an optionnal hash containing the period for witch the domain is registered with the following keys :

:unit

the unit of time, either “m”onth or “y”ear.

:number

the number of unit of time.

:ns

an optional array containing nameservers informations, which can either be an array of strings containing the nameserver’s hostname, or an array of hashes containing the following keys :

:hostName

the hostname of the nameserver.

:hostAddrv4

an optionnal array of ipv4 addresses.

:hostAddrv6

an optionnal array of ipv6 addresses.

:registrant

an optionnal registrant nic handle.

:contacts

an optionnal hash which keys are choosen between admin, billing and tech and which values are arrays of nic handles for the corresponding contact types.

:authInfo

the password associated with the domain.

Returns a hash with the following keys :

:name

the fully qualified name of the domain object.

:crDate

the date and time of domain object creation.

:exDate

the date and time identifying the end of the domain object’s registration period.



269
270
271
272
273
# File 'lib/epp-client/domain.rb', line 269

def domain_create(args)
  response = send_request(domain_create_xml(args))

  get_result(:xml => response, :callback => :domain_create_process)
end

#domain_create_process(xml) ⇒ Object

:nodoc:



275
276
277
278
279
280
281
282
283
# File 'lib/epp-client/domain.rb', line 275

def domain_create_process(xml) #:nodoc:
  dom = xml.xpath('epp:resData/domain:creData', EPPClient::SCHEMAS_URL)
  ret = {
    :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    :crDate => DateTime.parse(dom.xpath('domain:crDate', EPPClient::SCHEMAS_URL).text),
    :upDate => DateTime.parse(dom.xpath('domain:crDate', EPPClient::SCHEMAS_URL).text),
  }
  ret
end

#domain_create_xml(args) ⇒ Object

:nodoc:



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/epp-client/domain.rb', line 214

def domain_create_xml(args) #:nodoc:
  command do |xml|
    xml.create do
      xml.create('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        xml.name args[:name]

        if args.key?(:period)
          xml.period({ :unit => args[:period][:unit] }, args[:period][:number])
        end

        domain_nss_xml(xml, args[:ns]) if args.key?(:ns)

        xml.registrant args[:registrant] if args.key?(:registrant)

        domain_contacts_xml(xml, args[:contacts]) if args.key?(:contacts)

        xml.authInfo do
          xml.pw args[:authInfo]
        end
      end
    end
  end
end

#domain_delete(domain) ⇒ Object

Deletes a domain

Takes a single fully qualified domain name for argument.

Returns true on success, or raises an exception.



300
301
302
303
304
# File 'lib/epp-client/domain.rb', line 300

def domain_delete(domain)
  response = send_request(domain_delete_xml(domain))

  get_result(response)
end

#domain_delete_xml(domain) ⇒ Object

:nodoc:



285
286
287
288
289
290
291
292
293
# File 'lib/epp-client/domain.rb', line 285

def domain_delete_xml(domain) #:nodoc:
  command do |xml|
    xml.delete do
      xml.delete('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        xml.name domain
      end
    end
  end
end

#domain_info(args) ⇒ Object

Returns the informations about a domain

Takes either a unique argument, a string, representing the domain, or a hash with : :name the domain name, and optionnaly :authInfo the authentication information and possibly :roid the contact the authInfo is about.

Returned is a hash mapping as closely as possible the result expected from the command as per Section 3.1.2 of RFC 5731 :

:name

The fully qualified name of the domain object.

:roid

The Repository Object IDentifier assigned to the domain object when the object was created.

:status

an optionnal array of elements that contain the current status descriptors associated with the domain.

:registrant

one optionnal registrant nic handle.

:contacts

an optionnal hash which keys are choosen between admin, billing and tech and which values are arrays of nic handles for the corresponding contact types.

:ns

an optional array containing nameservers informations, which can either be an array of strings containing the the fully qualified name of a host, or an array of hashes containing the following keys :

:hostName

the fully qualified name of a host.

:hostAddrv4

an optionnal array of ipv4 addresses to be associated with the host.

:hostAddrv6

an optionnal array of ipv6 addresses to be associated with the host.

:host

an optionnal array of fully qualified names of the subordinate host objects that exist under this superordinate domain object.

:clID

the identifier of the sponsoring client.

:crID

an optional identifier of the client that created the domain object.

:crDate

an optional date and time of domain object creation.

:exDate

the date and time identifying the end of the domain object’s registration period.

:upID

the identifier of the client that last updated the domain object.

:upDate

the date and time of the most recent domain-object modification.

:trDate

the date and time of the most recent successful domain-object transfer.

:authInfo

authorization information associated with the domain object.



118
119
120
121
122
123
# File 'lib/epp-client/domain.rb', line 118

def domain_info(args)
  args = { :name => args } if args.is_a?(String)
  response = send_request(domain_info_xml(args))

  get_result(:xml => response, :callback => :domain_info_process)
end

#domain_info_process(xml) ⇒ Object

:nodoc:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/epp-client/domain.rb', line 125

def domain_info_process(xml) # :nodoc:
  dom = xml.xpath('epp:resData/domain:infData', EPPClient::SCHEMAS_URL)
  ret = {
    :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    :roid => dom.xpath('domain:roid', EPPClient::SCHEMAS_URL).text,
  }
  unless (status = dom.xpath('domain:status', EPPClient::SCHEMAS_URL)).empty?
    ret[:status] = status.map { |s| s.attr('s') }
  end
  unless (registrant = dom.xpath('domain:registrant', EPPClient::SCHEMAS_URL)).empty?
    ret[:registrant] = registrant.text
  end
  unless (contact = dom.xpath('domain:contact', EPPClient::SCHEMAS_URL)).empty?
    ret[:contacts] = contact.inject({}) do |a, c|
      s = c.attr('type').to_sym
      a[s] ||= []
      a[s] << c.text
      a
    end
  end
  unless (ns = dom.xpath('domain:ns', EPPClient::SCHEMAS_URL)).empty?
    if !(hostObj = ns.xpath('domain:hostObj', EPPClient::SCHEMAS_URL)).empty?
      ret[:ns] = hostObj.map(&:text)
    elsif !(hostAttr = ns.xpath('domain:hostAttr', EPPClient::SCHEMAS_URL)).empty?
      ret[:ns] = hostAttr.map do |h|
        r = { :hostName => h.xpath('domain:hostName', EPPClient::SCHEMAS_URL).text }
        unless (v4 = h.xpath('domain:hostAddr[@ip="v4"]', EPPClient::SCHEMAS_URL)).empty?
          r[:hostAddrv4] = v4.map(&:text)
        end
        unless (v6 = h.xpath('domain:hostAddr[@ip="v6"]', EPPClient::SCHEMAS_URL)).empty?
          r[:hostAddrv6] = v6.map(&:text)
        end
        r
      end
    end
  end
  unless (host = dom.xpath('domain:host', EPPClient::SCHEMAS_URL)).empty?
    ret[:host] = host.map(&:text)
  end
  %w(clID upID).each do |val|
    unless (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).empty?
      ret[val.to_sym] = r.text
    end
  end
  %w(crDate exDate upDate trDate).each do |val|
    unless (r = dom.xpath("domain:#{val}", EPPClient::SCHEMAS_URL)).empty?
      ret[val.to_sym] = DateTime.parse(r.text)
    end
  end
  unless (authInfo = dom.xpath('domain:authInfo', EPPClient::SCHEMAS_URL)).empty?
    ret[:authInfo] = authInfo.xpath('domain:pw', EPPClient::SCHEMAS_URL).text
  end
  ret
end

#domain_info_xml(args) ⇒ Object

:nodoc:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/epp-client/domain.rb', line 49

def domain_info_xml(args) # :nodoc:
  command do |xml|
    xml.info do
      xml.info('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        xml.name(args[:name])
        if args.key?(:authInfo)
          xml.authInfo do
            if args.key?(:roid)
              xml.pw({ :roid => args[:roid] }, args[:authInfo])
            else
              xml.pw(args[:authInfo])
            end
          end
        end
      end
    end
  end
end

#domain_nss_xml(xml, nss) ⇒ Object

:nodoc:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/epp-client/domain.rb', line 180

def domain_nss_xml(xml, nss) #:nodoc:
  xml.ns do
    if nss.first.is_a?(Hash)
      nss.each do |ns|
        xml.hostAttr do
          xml.hostName ns[:hostName]
          if ns.key?(:hostAddrv4)
            ns[:hostAddrv4].each do |v4|
              xml.hostAddr({ :ip => :v4 }, v4)
            end
          end
          if ns.key?(:hostAddrv6)
            ns[:hostAddrv6].each do |v6|
              xml.hostAddr({ :ip => :v6 }, v6)
            end
          end
        end
      end
    else
      nss.each do |ns|
        xml.hostObj ns
      end
    end
  end
end

#domain_pending_action_process(xml) ⇒ Object

:nodoc:



381
382
383
384
385
386
387
388
389
390
# File 'lib/epp-client/domain.rb', line 381

def domain_pending_action_process(xml) #:nodoc:
  dom = xml.xpath('epp:resData/domain:panData', EPPClient::SCHEMAS_URL)
  ret = {
    :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    :paResult => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).attribute('paResult').value,
    :paTRID => get_trid(dom.xpath('domain:paTRID', EPPClient::SCHEMAS_URL)),
    :paDate => DateTime.parse(dom.xpath('domain:paDate', EPPClient::SCHEMAS_URL).text),
  }
  ret
end

#domain_transfer(args) ⇒ Object

Transfers a domain

Takes a hash with :

:name

The domain name

:op

An operation that can either be “query” or “request”.

:authInfo

The authentication information and possibly :roid the contact the authInfo is about. The :authInfo information is optional when the operation type is “query” and mandatory when it is “request”.

:period

An optionnal hash containing the period for witch the domain is registered with the following keys :

:unit

the unit of time, either “m”onth or “y”ear.

:number

the number of unit of time.

Returned is a hash mapping as closely as possible the result expected from the command as per Section 3.1.3 and 3.2.4 of RFC 5731 :

:name

The fully qualified name of the domain object.

:trStatus

The state of the most recent transfer request.

:reID

The identifier of the client that requested the object transfer.

:reDate

The date and time that the transfer was requested.

:acID

The identifier of the client that SHOULD act upon a PENDING transfer request. For all other status types, the value identifies the client that took the indicated action.

:acDate

The date and time of a required or completed response. For a PENDING request, the value identifies the date and time by which a response is required before an automated response action will be taken by the server. For all other status types, the value identifies the date and time when the request was completed.

:exDate

Optionnaly, the end of the domain object’s validity period if the <transfer> command caused or causes a change in the validity period.



472
473
474
475
476
# File 'lib/epp-client/domain.rb', line 472

def domain_transfer(args)
  response = send_request(domain_transfer_xml(args))

  get_result(:xml => response, :callback => :domain_transfer_response)
end

#domain_transfer_response(xml) ⇒ Object

:nodoc:



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/epp-client/domain.rb', line 392

def domain_transfer_response(xml) #:nodoc:
  dom = xml.xpath('epp:resData/domain:trnData', EPPClient::SCHEMAS_URL)
  ret = {
    :name => dom.xpath('domain:name', EPPClient::SCHEMAS_URL).text,
    :trStatus => dom.xpath('domain:trStatus', EPPClient::SCHEMAS_URL).text,
    :reID => dom.xpath('domain:reID', EPPClient::SCHEMAS_URL).text,
    :reDate => DateTime.parse(dom.xpath('domain:reDate', EPPClient::SCHEMAS_URL).text),
    :acID => dom.xpath('domain:acID', EPPClient::SCHEMAS_URL).text,
    :acDate => DateTime.parse(dom.xpath('domain:acDate', EPPClient::SCHEMAS_URL).text),
  }
  unless (exDate = dom.xpath('domain:exDate', EPPClient::SCHEMAS_URL)).empty?
    ret[:exDate] = DateTime.parse(exDate)
  end
  ret
end

#domain_transfer_xml(args) ⇒ Object

:nodoc:



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/epp-client/domain.rb', line 408

def domain_transfer_xml(args) # :nodoc:
  command do |xml|
    xml.transfer('op' => args[:op]) do
      xml.transfer('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        xml.name(args[:name])
        if args.key?(:period)
          xml.period('unit' => args[:period][:unit]) do
            args[:period][:number]
          end
        end
        if args.key?(:authInfo)
          xml.authInfo do
            if args.key?(:roid)
              xml.pw({ :roid => args[:roid] }, args[:authInfo])
            else
              xml.pw(args[:authInfo])
            end
          end
        end
      end
    end
  end
end

#domain_update(args) ⇒ Object

Updates a domain

Takes a hash with the name, and at least one of the following keys :

:name

the fully qualified name of the domain object to be updated.

:add/:rem

adds / removes the following data to/from the domain object :

:ns

an optional array containing nameservers informations, which can either be an array of strings containing the nameserver’s hostname, or an array of hashes containing the following keys :

:hostName

the hostname of the nameserver.

:hostAddrv4

an optionnal array of ipv4 addresses.

:hostAddrv6

an optionnal array of ipv6 addresses.

:contacts

an optionnal hash which keys are choosen between admin, billing and tech and which values are arrays of nic handles for the corresponding contact types.

:status

an optional hash with status values to be applied to or removed from the object. When specifying a value to be removed, only the attribute value is significant; element text is not required to match a value for removal.

:chg

changes the following in the domain object.

:registrant

an optionnal registrant nic handle.

:authInfo

an optional password associated with the domain.

Returns true on success, or raises an exception.



375
376
377
378
379
# File 'lib/epp-client/domain.rb', line 375

def domain_update(args)
  response = send_request(domain_update_xml(args))

  get_result(response)
end

#domain_update_xml(args) ⇒ Object

:nodoc:



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
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/epp-client/domain.rb', line 306

def domain_update_xml(args) #:nodoc:
  command do |xml|
    xml.update do
      xml.update('xmlns' => EPPClient::SCHEMAS_URL['domain-1.0']) do
        xml.name args[:name]
        [:add, :rem].each do |ar|
          next unless args.key?(ar) && (args[ar].key?(:ns) || args[ar].key?(:contacts) || args[ar].key?(:status))
          xml.__send__(ar) do
            domain_nss_xml(xml, args[ar][:ns]) if args[ar].key?(:ns)
            if args[ar].key?(:contacts)
              domain_contacts_xml(xml, args[ar][:contacts])
            end
            if args[ar].key?(:status)
              args[ar][:status].each do |st, text|
                if text.nil?
                  xml.status(:s => st)
                else
                  xml.status({ :s => st }, text)
                end
              end
            end
          end
        end
        if args.key?(:chg) && (args[:chg].key?(:registrant) || args[:chg].key?(:authInfo))
          xml.chg do
            if args[:chg].key?(:registrant)
              xml.registrant args[:chg][:registrant]
            end
            if args[:chg].key?(:authInfo)
              xml.authInfo do
                xml.pw args[:chg][:authInfo]
              end
            end
          end
        end
      end
    end
  end
end