Module: EPPClient::Contact

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

Instance Method Summary collapse

Instance Method Details

#contact_check(*contacts) ⇒ Object

Check the availability of contacts

takes list of contacts as arguments

returns an array of hashes containing three fields :

:id

the contact id

:avail

wether the contact id can be provisionned.

:reason

the server-specific text to help explain why the object cannot be provisioned.



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

def contact_check(*contacts)
  contacts.flatten!

  response = send_request(contact_check_xml(*contacts))
  get_result(:xml => response, :callback => :contact_check_process)
end

#contact_check_process(xml) ⇒ Object

:nodoc:



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

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

#contact_check_xml(*contacts) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/epp-client/contact.rb', line 5

def contact_check_xml(*contacts) #:nodoc:
  command do |xml|
	xml.check do
	  xml.check('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do
 contacts.each do |c|
   xml.id(c)
 end
	  end
	end
  end
end

#contact_create(contact) ⇒ Object

Creates a contact

Takes a hash as an argument containing the following keys :

:id

the server-unique identifier of the contact object. Most of the time, the nic handle.

:postalInfo

a hash containing one or two keys, loc and int representing the localized and internationalized version of the postal address information. The value is a hash with the following keys :

:name

the name of the individual or role represented by the contact.

:org

the name of the organization with which the contact is affiliated.

:addr

a hash with the following keys :

:street

an array that contains the contact’s street address.

:city

the contact’s city.

:sp

the contact’s state or province.

:pc

the contact’s postal code.

:cc

the contact’s country code.

:voice

the contact’s optional voice telephone number.

:fax

the contact’s optional facsimile telephone number.

:email

the contact’s email address.

:authInfo

authorization information associated with the contact object.

:disclose

an optional array that identifies elements that require exceptional server-operator handling to allow or restrict disclosure to third parties. See section 2.9 of RFC 5733 for details.

Returns a hash with the following keys :

:id

the nic handle.

:crDate

the date and time of contact-object creation.



275
276
277
278
279
# File 'lib/epp-client/contact.rb', line 275

def contact_create(contact)
  response = send_request(contact_create_xml(contact))

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

#contact_create_process(xml) ⇒ Object

:nodoc:



281
282
283
284
285
286
287
# File 'lib/epp-client/contact.rb', line 281

def contact_create_process(xml) #:nodoc:
  contact = xml.xpath('epp:resData/contact:creData', EPPClient::SCHEMAS_URL)
  {
	:id => contact.xpath('contact:id', EPPClient::SCHEMAS_URL).text,
	:crDate => DateTime.parse(contact.xpath('contact:crDate', EPPClient::SCHEMAS_URL).text),
  }
end

#contact_create_xml(contact) ⇒ Object

:nodoc:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/epp-client/contact.rb', line 188

def contact_create_xml(contact) #:nodoc:
  command do |xml|
	xml.create do
	  xml.create('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do
 if contact.key?(:id)
   xml.id(contact[:id])
 else
   xml.id('invalid')
 end
 contact[:postalInfo].each do |type,infos|
   xml.postalInfo :type => type do
		xml.name(infos[:name])
		xml.org(infos[:org]) if infos.key?(:org)
		xml.addr do
infos[:addr][:street].each do |street|
  xml.street(street)
end
xml.city(infos[:addr][:city])
[:sp, :pc].each do |val|
  xml.__send__(val, infos[:addr][val]) if infos[:addr].key?(val)
end
xml.cc(infos[:addr][:cc])
		end
   end
 end
 [:voice, :fax].each do |val|
   xml.__send__(val, contact[val]) if contact.key?(val)
 end
 xml.email(contact[:email])
 xml.authInfo do
   xml.pw(contact[:authInfo])
 end
 if contact.key?(:disclose)
   xml.disclose do
		contact[:disclose].each do |disc|
if disc.key?(:type)
  xml.__send__(disc[:name], :type => disc[:type])
else
  xml.__send__(disc[:name])
end
		end
   end
 end
	  end
	end
  end
end

#contact_delete(contact) ⇒ Object

Deletes a contact

Takes a single nic handle for argument.

Returns true on success, or raises an exception.



304
305
306
307
308
# File 'lib/epp-client/contact.rb', line 304

def contact_delete(contact)
  response = send_request(contact_delete_xml(contact))

  get_result(response)
end

#contact_delete_xml(contact) ⇒ Object

:nodoc:



289
290
291
292
293
294
295
296
297
# File 'lib/epp-client/contact.rb', line 289

def contact_delete_xml(contact) #:nodoc:
  command do |xml|
	xml.delete do
	  xml.delete('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do
 xml.id(contact)
	  end
	end
  end
end

#contact_info(args) ⇒ Object

Returns the informations about a contact

Takes either a unique argument, either a string, representing the contact id or a hash with the following keys :

:id

the contact id, and optionnaly

:authInfo

an optional authentication information.

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

:id

the server-unique identifier of the contact object. Most of the time, the nic handle.

:roid

the Repository Object IDentifier assigned to the contact object when the object was created.

:status

the status of the contact object.

:postalInfo

a hash containing one or two keys, loc and int representing the localized and internationalized version of the postal address information. The value is a hash with the following keys :

:name

the name of the individual or role represented by the contact.

:org

the name of the organization with which the contact is affiliated.

:addr

a hash with the following keys :

:street

an array that contains the contact’s street address.

:city

the contact’s city.

:sp

the contact’s state or province.

:pc

the contact’s postal code.

:cc

the contact’s country code.

:voice

the contact’s optional voice telephone number.

:fax

the contact’s optional facsimile telephone number.

:email

the contact’s email address.

:clID

the identifier of the sponsoring client.

:crID

the identifier of the client that created the contact object.

:crDate

the date and time of contact-object creation.

:upID

the optional identifier of the client that last updated the contact object.

:upDate

the optional date and time of the most recent contact-object modification.

:trDate

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

:authInfo

authorization information associated with the contact object.

:disclose

an optional array that identifies elements that require exceptional server-operator handling to allow or restrict disclosure to third parties. See section 2.9 of RFC 5733 for details.



120
121
122
123
124
125
126
127
# File 'lib/epp-client/contact.rb', line 120

def contact_info(args)
  if String === args
	args = {:id => args}
  end
  response = send_request(contact_info_xml(args))

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

#contact_info_process(xml) ⇒ Object

:nodoc:



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
179
180
181
182
183
184
185
186
# File 'lib/epp-client/contact.rb', line 129

def contact_info_process(xml) #:nodoc:
  contact = xml.xpath('epp:resData/contact:infData', EPPClient::SCHEMAS_URL)
  ret = {
	:id => contact.xpath('contact:id', EPPClient::SCHEMAS_URL).text,
	:roid => contact.xpath('contact:roid', EPPClient::SCHEMAS_URL).text,
  }
  if (status = contact.xpath('contact:status', EPPClient::SCHEMAS_URL)).size > 0
	ret[:status] = status.map {|s| s.attr('s')}
  end

  if (postalInfo = contact.xpath('contact:postalInfo', EPPClient::SCHEMAS_URL)).size > 0
	ret[:postalInfo] = postalInfo.inject({}) do |acc, p|
	  type = p.attr('type').to_sym
	  acc[type] = { :name => p.xpath('contact:name', EPPClient::SCHEMAS_URL).text, :addr => {} }
	  if (org = p.xpath('contact:org', EPPClient::SCHEMAS_URL)).size > 0
 acc[type][:org] = org.text
	  end
	  addr = p.xpath('contact:addr', EPPClient::SCHEMAS_URL)

	  acc[type][:addr][:street] = addr.xpath('contact:street', EPPClient::SCHEMAS_URL).map {|s| s.text}
	  %w(city cc).each do |val|
 acc[type][:addr][val.to_sym] = addr.xpath("contact:#{val}", EPPClient::SCHEMAS_URL).text
	  end
	  %w(sp pc).each do |val|
 if (r = addr.xpath("contact:#{val}", EPPClient::SCHEMAS_URL)).size > 0
   acc[type][:addr][val.to_sym] = r.text
 end
	  end

	  acc
	end
  end

  %w(voice fax email clID crID upID).each do |val|
	if (value = contact.xpath("contact:#{val}", EPPClient::SCHEMAS_URL)).size > 0
	  ret[val.to_sym] = value.text
	end
  end
  %w(crDate upDate trDate).each do |val|
	if (date = contact.xpath("contact:#{val}", EPPClient::SCHEMAS_URL)).size > 0
	  ret[val.to_sym] = DateTime.parse(date.text)
	end
  end
  if (authInfo = contact.xpath('contact:authInfo', EPPClient::SCHEMAS_URL)).size > 0
	ret[:authInfo] = authInfo.xpath('contact:pw', EPPClient::SCHEMAS_URL).text
  end
  if (disclose = contact.xpath('contact:disclose', EPPClient::SCHEMAS_URL)).size > 0
	ret[:disclose] = { :flag => disclose.attr('flag').value == '1', :elements => [] }
	disclose.children.each do |c|
	  r = { :name => c.name }
	  unless (type = c.attr('type').value).nil?
 r[:type] == type
	  end
	  ret[:disclose][:elements] << r
	end
  end
  ret
end

#contact_info_xml(args) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/epp-client/contact.rb', line 48

def contact_info_xml(args) #:nodoc:
  command do |xml|
	xml.info do
	  xml.info('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do
 xml.id(args[:id])
 if args.key?(:authInfo)
   xml.authInfo do
		xml.pw(args[:authInfo])
   end
 end
	  end
	end
  end
end

#contact_update(args) ⇒ Object

Updates a contact

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

:id

the server-unique identifier of the contact object to be updated.

:add/:rem

adds or removes the following data from the contact object :

:status

an array of status to add to/remove from the object.

:chg

changes the datas of the contact object, takes the same arguments as the creation of the contact, except the id, with the small change that each first level key is now optional. (Meaning that you don’t have to supply a :postalInfo if you don’t need to, but if you do, all it’s mandatory fields are mandatory.)

Returns true on success, or raises an exception.



392
393
394
395
396
# File 'lib/epp-client/contact.rb', line 392

def contact_update(args)
  response = send_request(contact_update_xml(args))

  get_result(response)
end

#contact_update_xml(args) ⇒ Object

:nodoc:



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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/epp-client/contact.rb', line 310

def contact_update_xml(args) #:nodoc:
  command do |xml|
	xml.update do
	  xml.update('xmlns' => EPPClient::SCHEMAS_URL['contact-1.0']) do
 xml.id args[:id]
 if args.key?(:add) && args[:add].key?(:status)
   xml.add do
		args[:add][:status].each do |s|
xml.status :s => s
		end
   end
 end
 if args.key?(:rem) && args[:rem].key?(:status)
   xml.rem do
		args[:rem][:status].each do |s|
xml.status :s => s
		end
   end
 end
 if args.key?(:chg)
   contact = args[:chg]
   xml.chg do
		if contact.key?(:postalInfo)
contact[:postalInfo].each do |type,infos|
  xml.postalInfo :type => type do
    xml.name(infos[:name])
    xml.org(infos[:org]) if infos.key?(:org)
    xml.addr do
			infos[:addr][:street].each do |street|
 xml.street(street)
			end
			xml.city(infos[:addr][:city])
			[:sp, :pc].each do |val|
 xml.__send__(val, infos[:addr][val]) if infos[:addr].key?(val)
			end
			xml.cc(infos[:addr][:cc])
    end
  end
end
		end
		[:voice, :fax, :email].each do |val|
xml.__send__(val, contact[val]) if contact.key?(val)
		end
		if contact.key?(:authInfo)
xml.authInfo do
  xml.pw(contact[:authInfo])
end
		end
		if contact.key?(:disclose)
xml.disclose do
  contact[:disclose].each do |disc|
    if disc.key?(:type)
			xml.__send__(disc[:name], :type => disc[:type])
    else
			xml.__send__(disc[:name])
    end
  end
end
		end
   end
 end
	  end
	end
  end
end