Permalink
Browse files

expand StrikeIron to include service for ReversePhoneAddressLookupAdv…

…anced; add lookup_type to PhoneLookup; set advanced lookup as the lookup to use
  • Loading branch information...
Jared Howard
Jared Howard committed Jan 19, 2012
1 parent d4fe279 commit aeb6c5edafda3191007f663583d276d2053e8229
@@ -175,8 +175,7 @@ def check_custom(field_value, reg = self.check_value)
end
def check_phone_lookup(field_value)
- lookup = PhoneLookup.find_or_create_by_phone_number(field_value)
- lookup.acceptable?
+ PhoneLookup.acceptable?(field_value)
end
def check_phone_validity(field_value)
View
@@ -1,17 +1,29 @@
class PhoneLookup < ActiveRecord::Base
+ LOOKUP_TYPE = 'StrikeIron::ReversePhoneAddressLookupAdvanced'
+
validates_format_of :phone_number, :with => /\A\d{10}\Z/, :allow_nil => false, :allow_blank => false
- validates_uniqueness_of :phone_number
+ validates_presence_of :lookup_type
+ validates_uniqueness_of :phone_number, :scope => :lookup_type
before_create :perform_create_lookup
- attr_accessible :phone_number
+ attr_accessible :phone_number, :lookup_type
- def phone_number=(value)
- super(value) if self.lookup_performed_at.nil?
+ def self.get_phone(phone)
+ find_or_create_by_phone_number_and_lookup_type(phone, LOOKUP_TYPE)
+ end
+
+ def self.acceptable?(phone)
+ lookup = get_phone(phone)
+ lookup.acceptable?
end
def acceptable?
- (self.status_nbr != '200' && self.cell_phone == 'F') ? false : true unless self.lookup_performed_at.nil?
+ (self.status_nbr != '200' && self.cell_phone == 'F') ? false : true if self.lookup_performed_at.present?
+ end
+
+ def phone_number=(value)
+ super(value) if self.lookup_performed_at.nil?
end
protected
@@ -21,8 +33,8 @@ def perform_create_lookup
end
def perform_lookup
- unless self.phone_number.nil?
- @lookup = StrikeIron::ReversePhoneAddressLookup.new(self.phone_number)
+ if self.phone_number.present?
+ @lookup = LOOKUP_TYPE.constantize.new(self.phone_number)
@lookup.attributes.each do |key, value|
self.send("#{key}=", value) if self.attributes.include?(key.to_s)
end
@@ -3,10 +3,13 @@ def self.up
create_table :phone_lookups do |t|
t.timestamps
t.string :phone_number, :limit => 10
+ t.string :lookup_type
t.datetime :lookup_performed_at
- t.string :status_description, :status_nbr, :abi_number, :address, :cell_phone, :company_name, :contact_title_code, :country, :date_added, :dwelling_type, :employee_size, :estimated_head_of_household_income, :exchange_code, :fax_phone_number, :first_name, :full_name, :hq_branch_code, :head_of_household_birth_year, :head_of_household_gender, :homeowner_probability, :last_name, :length_of_residency, :local_sales_code, :middle_name, :name_prefix, :name_suffix, :original_phone, :public_company_indicator, :record_type, :sic, :sic_description, :secondary_sic1, :secondary_sic2, :secondary_sic3, :secondary_sic4, :state_dnc, :state_or_province, :sub_parent_number, :ticker_symbol, :time_zone, :total_employee_size, :ultimate_parent_number, :zip_or_postal_code
+ t.string :status_description, :status_nbr, :abi_number, :address, :cell_phone, :city, :company_name, :contact_title_code, :country, :date_added, :dwelling_type, :employee_size, :estimated_head_of_household_income, :exchange_code, :fax_phone_number, :first_name, :full_name, :hq_branch_code, :head_of_household_birth_year, :head_of_household_gender, :homeowner_probability, :last_name, :length_of_residency, :local_sales_code, :middle_name, :name_prefix, :name_suffix, :original_phone, :public_company_indicator, :record_type, :run_type, :sic, :sic_description, :secondary_sic1, :secondary_sic2, :secondary_sic3, :secondary_sic4, :state_dnc, :state_or_province, :sub_parent_number, :ticker_symbol, :time_zone, :total_employee_size, :ultimate_parent_number, :zip_or_postal_code
end
- add_index :phone_lookups, :phone_number, :unique => true
+ add_index :phone_lookups, [:phone_number, :lookup_type], :unique => true
+ add_index :phone_lookups, :phone_number
+ add_index :phone_lookups, :lookup_type
end
def self.down
Oops, something went wrong.

0 comments on commit aeb6c5e

Please sign in to comment.