Skip to content

Instantly share code, notes, and snippets.

@stephenjudkins
Created May 1, 2009 19:48
Show Gist options
  • Save stephenjudkins/105213 to your computer and use it in GitHub Desktop.
Save stephenjudkins/105213 to your computer and use it in GitHub Desktop.
require 'electric_sheep/whois/parser_wrapper'
require 'dm_test'
class Contact
include DataMapper::Resource
property :page_id, Integer, :key => true
property :address, String
property :city, String
property :state, String
property :postal_code, String
property :email, String
property :country, String
property :phone, String
attr_accessor :protected_email
attr_accessor :page
def protected_email
begin
@protected_email ||= !self.email.blank? ? GraphicProtection.encrypt(self.email) : nil
rescue
return nil
end
end
before :save, :decrypt_email
def decrypt_email
begin
self.email = GraphicProtection.decrypt(self.protected_email) if self.protected_email and not self.email
rescue
end
end
def changed?
dirty?
end
def build_from_whois
wi = WhoisImporter.new
contact_record = wi.fetch_for_domain(self.page.page_title)
if contact_record
self.address = contact_record.registrant.address.join "\n"
self.address = contact_record.registrant.raw_address if self.address.blank?
self.city = contact_record.registrant.city
self.state = contact_record.registrant.state_or_province
self.postal_code = contact_record.registrant.postal_code
self.phone = contact_record.registrant.phone_number
self.email = contact_record.registrant.email
end
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment