Class: AccountDomain
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AccountDomain
show all
- Includes:
- ActiveUUID::UUID
- Defined in:
- app/models/account_domain.rb
Instance Method Summary
collapse
#fix_uuid_strings, included
Instance Method Details
#calculate_token ⇒ Object
36
37
38
39
|
# File 'app/models/account_domain.rb', line 36
def calculate_token
url = normalize_host
Digest::SHA1.hexdigest( "#{id}#{url}" )[8..24]
end
|
#normalize_host ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/models/account_domain.rb', line 23
def normalize_host
begin
normalized_url = url
normalized_url = normalized_url.gsub('www.','')
normalized_url = normalized_url.gsub('http://','')
normalized_url = normalized_url.gsub('https://','')
normalized_url = 'http://' + normalized_url
URI.parse(normalized_url).host
rescue
nil
end
end
|
#set_primary ⇒ Object
61
62
63
64
65
66
|
# File 'app/models/account_domain.rb', line 61
def set_primary
if verified == true
AccountDomain.where(:account_id => account_id).update_all(:primary => false)
update_attribute(:primary, true)
end
end
|
#verify ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/models/account_domain.rb', line 41
def verify
url = normalize_host
ref_id = self.calculate_token
checked=false
begin
Socket.gethostbyname( "#{ref_id}.#{url}" )
checked=true
rescue SocketError
end
begin
response = Net::HTTP.start(url, 80) {|http| http.head("/#{ref_id}.html") }
checked = true if response.code == "200"
rescue
end
AccountDomain.where(:url => self.url).update_all(:verified => false) if checked == true
update_attribute(:verified, checked)
set_first_domain
checked
end
|