11031910-callbacks_for_whois_server

This commit is contained in:
Stas 2016-01-06 15:04:02 +02:00
parent 2d35556f2b
commit a440169eaf
3 changed files with 42 additions and 1 deletions

View file

@ -24,7 +24,7 @@ class Admin::ReservedDomainsController < AdminController
ReservedDomain.transaction do ReservedDomain.transaction do
# removing old ones # removing old ones
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id) existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
ReservedDomain.where.not(id: existing).delete_all ReservedDomain.where.not(id: existing).destroy_all
#updating and adding #updating and adding
names.each do |name, psw| names.each do |name, psw|

View file

@ -1,6 +1,9 @@
class ReservedDomain < ActiveRecord::Base class ReservedDomain < ActiveRecord::Base
include Versions # version/reserved_domain_version.rb include Versions # version/reserved_domain_version.rb
before_save :fill_empty_passwords before_save :fill_empty_passwords
before_save :generate_data
before_destroy :remove_data
class << self class << self
def pw_for(domain_name) def pw_for(domain_name)
@ -25,4 +28,34 @@ class ReservedDomain < ActiveRecord::Base
def name= val def name= val
super SimpleIDN.to_unicode(val) super SimpleIDN.to_unicode(val)
end end
def generate_data
@json = generate_json
@body = generate_body
update_whois_server
end
def update_whois_server
wr = Whois::Record.find_or_initialize_by(name: name)
wr.body = @body
wr.json = @json
wr.save
end
def generate_body
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
ERB.new(template.read, nil, "-").result(binding)
end
def generate_json
h = HashWithIndifferentAccess.new
h[:name] = self.name
h[:status] = 'Reserved'
h
end
def remove_data
Whois::Record.where(name: name).delete_all
end
end end

View file

@ -0,0 +1,8 @@
Estonia .ee Top Level Domain WHOIS server
Domain:
name: <%= @json['name'] %>
status: <%= @json['status'] %>
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee