Basic contact check command implementation

This commit is contained in:
Andres Keskküla 2014-07-28 14:30:16 +03:00
parent 65bb5166cc
commit 1f29925004
6 changed files with 106 additions and 0 deletions

View file

@ -40,4 +40,17 @@ module Epp::ContactsHelper
render '/epp/error'
end
end
def check_contact
ph = params_hash['epp']['command']['check']['check']
@contacts = Contact.check_availability( ph[:id] )
if @contacts.any?
render '/epp/contacts/check'
else
@code = '2303'
@msg = "Object does not exist"
render 'epp/error'
end
end
end

View file

@ -14,4 +14,22 @@ class Contact < ActiveRecord::Base
code = Isikukood.new(ident)
errors.add(:ident, 'bad format') unless code.valid?
end
class << self
def check_availability(codes)
codes = [codes] if codes.is_a?(String)
res = []
codes.each do |x|
if Contact.find_by(code: x)
res << {code: x, avail: 0, reason: 'in use'}
else
res << {code: x, avail: 1}
end
end
res
end
end
end

View file

@ -0,0 +1,22 @@
xml.epp_head do
xml.response do
xml.result('code' => '1000') do
xml.msg 'Command completed successfully'
end
xml.resData do
xml.tag!('contact:chkData', 'xmlns:contact' => 'http://www.nic.cz/xml/epp/contact-1.6',
'xsi:schemaLocation' => 'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd') do
#xml.tag!('contact:id', @contact.code)
@contacts.each do |contact|
xml.tag!('contact:cd') do
xml.tag! "contact:id", contact[:code], avail: contact[:avail]
xml.tag!('contact:reason', contact[:reason]) unless contact[:avail] == 1
end
end
end
end
xml << render('/epp/shared/trID')
end
end