mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Refactor
This commit is contained in:
parent
2187be6364
commit
acb65c47d6
7 changed files with 39 additions and 70 deletions
|
@ -15,19 +15,7 @@ module Epp::Common
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_params_hash(path)
|
def get_params_hash(path)
|
||||||
node_set = parsed_frame.css(path).children.select{ |x| x.element? && x.element_children.empty? }
|
Hash.from_xml(parsed_frame.css(path).to_xml).with_indifferent_access
|
||||||
|
|
||||||
node_set.inject({}) do |hash, obj|
|
|
||||||
#convert to array if 1 or more attributes with same name
|
|
||||||
if hash[obj.name.to_sym] && !hash[obj.name.to_sym].is_a?(Array)
|
|
||||||
hash[obj.name.to_sym] = [hash[obj.name.to_sym]]
|
|
||||||
hash[obj.name.to_sym] << obj.text.strip
|
|
||||||
else
|
|
||||||
hash[obj.name.to_sym] = obj.text.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
hash
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def epp_session
|
def epp_session
|
||||||
|
|
|
@ -10,12 +10,14 @@ class Epp::CommandsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
def create
|
def create
|
||||||
type = OBJECT_TYPES[parsed_frame.css('create create').attr('schemaLocation').value]
|
ph = get_params_hash('create create')[:create]
|
||||||
|
type = OBJECT_TYPES[ph[:schemaLocation]]
|
||||||
send("create_#{type}")
|
send("create_#{type}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
type = OBJECT_TYPES[parsed_frame.css('check check').attr('schemaLocation').value]
|
ph = get_params_hash('check check')[:check]
|
||||||
|
type = OBJECT_TYPES[ph[:schemaLocation]]
|
||||||
send("check_#{type}")
|
send("check_#{type}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Epp::SessionsController < ApplicationController
|
||||||
### HELPER METHODS ###
|
### HELPER METHODS ###
|
||||||
|
|
||||||
def login_params
|
def login_params
|
||||||
login_params = parsed_frame.css('epp command login')
|
ph = get_params_hash('epp command login')[:login]
|
||||||
{ username: login_params.css('clID').text, password: login_params.css('pw').text }
|
{ username: ph[:clID], password: ph[:pw] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
module Epp::ContactsHelper
|
module Epp::ContactsHelper
|
||||||
def create_contact
|
def create_contact
|
||||||
ccp = contact_create_params
|
cp = Hash.from_xml(parsed_frame.css("epp command create create").to_xml).with_indifferent_access
|
||||||
end
|
|
||||||
|
|
||||||
### HELPER METHODS ###
|
|
||||||
|
|
||||||
def contact_create_params
|
|
||||||
{
|
|
||||||
addr: get_params_hash('epp command create create postalInfo addr')
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,28 +5,23 @@ module Epp::DomainsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_domain
|
def check_domain
|
||||||
@domains = Domain.check_availability(domain_check_params[:names])
|
ph = get_params_hash('epp command check check')[:check]
|
||||||
|
@domains = Domain.check_availability(ph[:name])
|
||||||
render '/epp/domains/check'
|
render '/epp/domains/check'
|
||||||
end
|
end
|
||||||
|
|
||||||
### HELPER METHODS ###
|
### HELPER METHODS ###
|
||||||
|
|
||||||
def domain_create_params
|
def domain_create_params
|
||||||
node_set = parsed_frame.css("epp command create create").children.select(&:element?)
|
ph = get_params_hash('epp command create create')[:create]
|
||||||
command_params = node_set.inject({}) {|hash, obj| hash[obj.name.to_sym] = obj.text;hash }
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name: command_params[:name],
|
name: ph[:name],
|
||||||
registrar_id: current_epp_user.registrar.try(:id),
|
registrar_id: current_epp_user.registrar.try(:id),
|
||||||
registered_at: Time.now,
|
registered_at: Time.now,
|
||||||
valid_from: Date.today,
|
valid_from: Date.today,
|
||||||
valid_to: Date.today + command_params[:period].to_i.years,
|
valid_to: Date.today + ph[:period].to_i.years,
|
||||||
auth_info: command_params[:authInfo]
|
auth_info: ph[:authInfo]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_check_params
|
|
||||||
node_set = parsed_frame.css('epp command check check name')
|
|
||||||
node_set.inject({names: []}){ |hash, obj| hash[:names] << obj.text; hash }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,6 +20,8 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def check_availability(domains)
|
def check_availability(domains)
|
||||||
|
domains = [domains] if domains.is_a?(String)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
domains.each do |x|
|
domains.each do |x|
|
||||||
if !DomainNameValidator.validate(x)
|
if !DomainNameValidator.validate(x)
|
||||||
|
|
|
@ -1,34 +1,24 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?><epp
|
||||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
|
xmlns="urn:ietf:params:xml:ns:epp-1.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<command>
|
xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-
|
||||||
<create>
|
1.0.xsd"><command><create><contact:create
|
||||||
<contact:create 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">
|
xmlns:contact="http://www.nic.cz/xml/epp/contact-1.6"
|
||||||
<contact:id>sh8013</contact:id>
|
xsi:schemaLocation="http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd">
|
||||||
<contact:postalInfo type="int">
|
<contact:id>CID:TEST:10</contact:id>
|
||||||
<contact:name>John Doe</contact:name>
|
<contact:postalInfo>
|
||||||
<contact:org>Example Inc.</contact:org>
|
<contact:name>Test</contact:name>
|
||||||
<contact:addr>
|
<contact:addr><contact:street>Test Street 11-2</contact:street>
|
||||||
<contact:street>123 Example Dr.</contact:street>
|
<contact:city>Test City</contact:city>
|
||||||
<contact:street>Suite 100</contact:street>
|
<contact:pc>123456</contact:pc>
|
||||||
<contact:city>Dulles</contact:city>
|
<contact:cc>EE</contact:cc>
|
||||||
<contact:sp>VA</contact:sp>
|
</contact:addr>
|
||||||
<contact:pc>20166-6503</contact:pc>
|
</contact:postalInfo>
|
||||||
<contact:cc>US</contact:cc>
|
<contact:voice>+372.5555555</contact:voice>
|
||||||
</contact:addr>
|
<contact:email>test@test.com</contact:email>
|
||||||
</contact:postalInfo>
|
<contact:ident type="op">37812124567</contact:ident>
|
||||||
<contact:voice x="1234">+1.7035555555</contact:voice>
|
</contact:create>
|
||||||
<contact:fax>+1.7035555556</contact:fax>
|
</create>
|
||||||
<contact:email>jdoe@example.com</contact:email>
|
<clTRID>neka005#10-02-08at13:51:37</clTRID>
|
||||||
<contact:authInfo>
|
</command>
|
||||||
<contact:pw>2fooBAR</contact:pw>
|
|
||||||
</contact:authInfo>
|
|
||||||
<contact:disclose flag="0">
|
|
||||||
<contact:voice/>
|
|
||||||
<contact:email/>
|
|
||||||
</contact:disclose>
|
|
||||||
</contact:create>
|
|
||||||
</create>
|
|
||||||
<clTRID>ABC-12345</clTRID>
|
|
||||||
</command>
|
|
||||||
</epp>
|
</epp>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue