Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

expand StrikeIron to include service for ReversePhoneAddressLookupAdv…

…anced; add lookup_type to PhoneLookup; set advanced lookup as the lookup to use
  • Loading branch information...
commit aeb6c5edafda3191007f663583d276d2053e8229 1 parent d4fe279
Jared Howard authored
3  app/models/dynamic_field_check.rb
@@ -175,8 +175,7 @@ def check_custom(field_value, reg = self.check_value)
175 175 end
176 176
177 177 def check_phone_lookup(field_value)
178   - lookup = PhoneLookup.find_or_create_by_phone_number(field_value)
179   - lookup.acceptable?
  178 + PhoneLookup.acceptable?(field_value)
180 179 end
181 180
182 181 def check_phone_validity(field_value)
26 app/models/phone_lookup.rb
... ... @@ -1,17 +1,29 @@
1 1 class PhoneLookup < ActiveRecord::Base
  2 + LOOKUP_TYPE = 'StrikeIron::ReversePhoneAddressLookupAdvanced'
  3 +
2 4 validates_format_of :phone_number, :with => /\A\d{10}\Z/, :allow_nil => false, :allow_blank => false
3   - validates_uniqueness_of :phone_number
  5 + validates_presence_of :lookup_type
  6 + validates_uniqueness_of :phone_number, :scope => :lookup_type
4 7
5 8 before_create :perform_create_lookup
6 9
7   - attr_accessible :phone_number
  10 + attr_accessible :phone_number, :lookup_type
8 11
9   - def phone_number=(value)
10   - super(value) if self.lookup_performed_at.nil?
  12 + def self.get_phone(phone)
  13 + find_or_create_by_phone_number_and_lookup_type(phone, LOOKUP_TYPE)
  14 + end
  15 +
  16 + def self.acceptable?(phone)
  17 + lookup = get_phone(phone)
  18 + lookup.acceptable?
11 19 end
12 20
13 21 def acceptable?
14   - (self.status_nbr != '200' && self.cell_phone == 'F') ? false : true unless self.lookup_performed_at.nil?
  22 + (self.status_nbr != '200' && self.cell_phone == 'F') ? false : true if self.lookup_performed_at.present?
  23 + end
  24 +
  25 + def phone_number=(value)
  26 + super(value) if self.lookup_performed_at.nil?
15 27 end
16 28
17 29 protected
@@ -21,8 +33,8 @@ def perform_create_lookup
21 33 end
22 34
23 35 def perform_lookup
24   - unless self.phone_number.nil?
25   - @lookup = StrikeIron::ReversePhoneAddressLookup.new(self.phone_number)
  36 + if self.phone_number.present?
  37 + @lookup = LOOKUP_TYPE.constantize.new(self.phone_number)
26 38 @lookup.attributes.each do |key, value|
27 39 self.send("#{key}=", value) if self.attributes.include?(key.to_s)
28 40 end
7 db/migrate/20090903173210_create_phone_lookups.rb
@@ -3,10 +3,13 @@ def self.up
3 3 create_table :phone_lookups do |t|
4 4 t.timestamps
5 5 t.string :phone_number, :limit => 10
  6 + t.string :lookup_type
6 7 t.datetime :lookup_performed_at
7   - 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
  8 + 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
8 9 end
9   - add_index :phone_lookups, :phone_number, :unique => true
  10 + add_index :phone_lookups, [:phone_number, :lookup_type], :unique => true
  11 + add_index :phone_lookups, :phone_number
  12 + add_index :phone_lookups, :lookup_type
10 13 end
11 14
12 15 def self.down
323 lib/strike_iron.rb
@@ -15,327 +15,4 @@ def self.normalize_result_value(value)
15 15 value unless value.class == SOAP::Mapping::Object
16 16 end
17 17
18   -
19   - class ReversePhoneAddressLookup
20   - WSDL = "#{parent::WSDL_PREFIX}ReversePhoneAddressLookup?WSDL"
21   -
22   - def initialize(phone)
23   - @phone = self.class.parent.validate_and_normalize_phone(phone)
24   - end
25   -
26   - def result
27   - if @result.nil?
28   - unless @phone.nil?
29   - driver = SOAP::WSDLDriverFactory.new(self.class::WSDL).create_rpc_driver
30   - @result = driver.reverseLookupByPhoneNumber({'UserID' => self.class.parent::USER_ID, 'Password' => self.class.parent::PASSWORD, 'PhoneNumber' => @phone})
31   - end
32   - end
33   - @result
34   - end
35   -
36   - def attributes
37   - attrs = {}
38   - (methods - Object.methods - ['attributes','result']).each do |m|
39   - attrs[m.to_sym] = self.send(m)
40   - end
41   - attrs
42   - end
43   -
44   - # This field returns the description of the status number.
45   - def status_description
46   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceStatus.statusDescription) if result && result.reverseLookupByPhoneNumberResult.serviceStatus.methods.include?('statusDescription')
47   - end
48   -
49   - # This field returns a number referring to the status of this request.
50   - def status_nbr
51   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceStatus.statusNbr) if result && result.reverseLookupByPhoneNumberResult.serviceStatus.methods.include?('statusNbr')
52   - end
53   -
54   - # This field returns an ABI Number which provides a unique identifier for each business in the infoUSA database.
55   - def abi_number
56   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.aBINumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('aBINumber')
57   - end
58   -
59   - # This field returns the street address associated to the phone number provided.
60   - def address
61   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.address) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('address')
62   - end
63   -
64   - # If the phone number provided as input is for a cell phone, the output returned for this field is true. Otherwise, the output returned for this field is false.
65   - # (values = T or F)
66   - def cell_phone
67   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.cellPhone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('cellPhone')
68   - end
69   -
70   - # This field returns the name of the company.
71   - def company_name
72   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.companyName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('companyName')
73   - end
74   -
75   - # This field returns a code corresponding to the title of the designated contact.
76   - # 1 Owner
77   - # 2 President
78   - # 3 Manager
79   - # 4 Executive Director
80   - # 5 Principal
81   - # 6 Publisher
82   - # 7 Administrator
83   - # 8 Religious Leader
84   - # 9 Partner
85   - # A Chairman
86   - # B Vice Chairman
87   - # C Chief Executive Officer
88   - # D Director (Public Co)
89   - # E Chief Operating Officer (COO)
90   - # F Chief Financial Officer (CFO)
91   - # G Treasurer
92   - # H Controller
93   - # I Executive Vice President
94   - # J Senior Vice President
95   - # K Vice President
96   - # L Administration Executive
97   - # M Corporate Communications Executive
98   - # N Data Processing Executive
99   - # O Finance Executive
100   - # P Human Resources Executive
101   - # Q Telecommunication Executive
102   - # R Marketing Executive
103   - # S Operations Executive
104   - # T Sales Executive
105   - # U Corporate Secretary
106   - # V General Counsel
107   - # W Executive Officer
108   - # X Plant Manager
109   - # Y Purchasing Agent
110   - # Z Auditor
111   - def contact_title_code
112   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.contactTitleCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('contactTitleCode')
113   - end
114   -
115   - # This field returns the country.
116   - def country
117   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.country) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('country')
118   - end
119   -
120   - # This field returns the date when this information was last updated.
121   - def date_added
122   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.dateAdded) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('dateAdded')
123   - end
124   -
125   - # This field returns the dwelling type.
126   - # Dwellings types:
127   - # C= Single Family
128   - # D-K = 2-9 Residences at Same Address
129   - # L= 10-19 Residences at Same Address
130   - # M= 20-49 Residences at Same Address
131   - # N= 50-100 Residences at Same Address
132   - # O= 100+ Residences at Same Address
133   - def dwelling_type
134   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.dwellingType) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('dwellingType')
135   - end
136   -
137   - # This field returns the number of employees at the location specified above.
138   - def employee_size
139   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.employeeSize) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('employeeSize')
140   - end
141   -
142   - # This field returns the estimated household income, if available.
143   - def estimated_head_of_household_income
144   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.estimatedHeadOfHouseholdIncome) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('estimatedHeadOfHouseholdIncome')
145   - end
146   -
147   - # This field returns the stock exchange that carries the stock symbol.
148   - def exchange_code
149   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.exchangeCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('exchangeCode')
150   - end
151   -
152   - # This field returns the fax number for the company.
153   - def fax_phone_number
154   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.faxPhoneNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('faxPhoneNumber')
155   - end
156   -
157   - # This field returns the first name.
158   - def first_name
159   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.firstName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('firstName')
160   - end
161   -
162   - # This field returns the full name.
163   - def full_name
164   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.fullName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('fullName')
165   - end
166   -
167   - # This field indicates if this address represents a single location, headquarters or branch of the company.
168   - # 1 = Headquarters
169   - # 2 = Branches
170   - # 3 = Subsidiary Headquarters
171   - # Blank = None of the above
172   - def hq_branch_code
173   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.hQBranchCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('hQBranchCode')
174   - end
175   -
176   - # This field returns the year of birth of the head of the household, if available.
177   - def head_of_household_birth_year
178   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.headOfHouseholdBirthYear) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('headOfHouseholdBirthYear')
179   - end
180   -
181   - # This field returns the gender of the head of the household.
182   - def head_of_household_gender
183   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.headOfHouseholdGender) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('headOfHouseholdGender')
184   - end
185   -
186   - # This field returns the homeowner probability.
187   - # Types:
188   - # H= Homeowner
189   - # 9= probable homeowner 90-100%
190   - # 8= probable homeowner 80-89%
191   - # 7= probable homeowner 70-79%
192   - # 6= Likely Homeowner
193   - # R= Renter
194   - # T, 0-4 = Probably Renter
195   - # U, 5= Unknown
196   - def homeowner_probability
197   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.homeownerProbability) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('homeownerProbability')
198   - end
199   -
200   - # This field returns the last name.
201   - def last_name
202   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.lastName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('lastName')
203   - end
204   -
205   - # This field returns the length of time the person has lived at the residence.
206   - def length_of_residency
207   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.lengthOfResidency) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('lengthOfResidency')
208   - end
209   -
210   - # This field returns an alpha code corresponding to the estimated sales of the business in thousands of dollars.
211   - # A 1 - 499
212   - # B 500 - 999
213   - # C 1,000 - 2,499
214   - # D 2,500 - 4,999
215   - # E 5,000 - 9,999
216   - # F 10,000 - 19,999
217   - # G 20,000 - 49,999
218   - # H 50,000 - 99,999
219   - # I 100,000 - 499,999
220   - # J 500,000 - 999,999
221   - # K 1,000,000 +
222   - def local_sales_code
223   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.localSalesCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('localSalesCode')
224   - end
225   -
226   - # This field returns the middle name or initial.
227   - def middle_name
228   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.middleName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('middleName')
229   - end
230   -
231   - # This field returns the name prefix. (DR., REV., MR, MRS.)
232   - def name_prefix
233   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.namePrefix) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('namePrefix')
234   - end
235   -
236   - # This field returns the name suffix (if applicable)
237   - def name_suffix
238   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.nameSuffix) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('nameSuffix')
239   - end
240   -
241   - # This field returns the phone number provided as input.
242   - def original_phone
243   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.originalPhone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('originalPhone')
244   - end
245   -
246   - # This field returns whether or not the company is public, if available.
247   - def public_company_indicator
248   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.publicCompanyIndicator) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('publicCompanyIndicator')
249   - end
250   -
251   - # Indicates if the number provided is a business or residential number. The demographic data returned will correspond to the record type.
252   - # Potential Values:
253   - # IS or IP= Residential Match
254   - # BS or BP= Business Match
255   - # IC= Residential Canadian Match
256   - # BC= Business Canadian Match
257   - def record_type
258   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.recordType) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('recordType')
259   - end
260   -
261   - # Standard Industry Code for the Company.
262   - def sic
263   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.sIC) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('sIC')
264   - end
265   -
266   - # Description of the Standard Industry Code for the Company.
267   - def sic_description
268   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.sICDescription) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('sICDescription')
269   - end
270   -
271   - # This field returns any additional activity of the business.
272   - def secondary_sic1
273   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC1) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC1')
274   - end
275   -
276   - # This field returns any additional activity of the business.
277   - def secondary_sic2
278   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC2) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC2')
279   - end
280   -
281   - # This field returns any additional activity of the business.
282   - def secondary_sic3
283   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC3) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC3')
284   - end
285   -
286   - # This field returns any additional activity of the business.
287   - def secondary_sic4
288   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC4) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC4')
289   - end
290   -
291   - # This field returns a ‘Yes, ‘No’ or (blank) indicating whether or not the phone number is on the specific state or Direct Marketing Association Do Not Call list.
292   - # (*NOTE: this field does not return information from the National Do Not Call List.).
293   - def state_dnc
294   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.stateDNC) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('stateDNC')
295   - end
296   -
297   - # This field returns the state or province.
298   - def state_or_province
299   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.stateOrProvince) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('stateOrProvince')
300   - end
301   -
302   - # The subsidiary parent number identifies the business as a regional or subsidiary headquarters for the corporate family. The subsidiary will always have an ultimate parent and may or may not have braches assigned to it.
303   - def sub_parent_number
304   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.subParentNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('subParentNumber')
305   - end
306   -
307   - # This field returns the stock ticker symbol.
308   - def ticker_symbol
309   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.tickerSymbol) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('tickerSymbol')
310   - end
311   -
312   - # This field returns the time zone.
313   - # Values:
314   - # E= Eastern
315   - # C= Central
316   - # M= Mountain
317   - # P= Pacific
318   - # A= Alaska
319   - # H= Hawaii
320   - def time_zone
321   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.timeZone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('timeZone')
322   - end
323   -
324   - # This field returns the number of employees in the company.
325   - def total_employee_size
326   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.totalEmployeeSize) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('totalEmployeeSize')
327   - end
328   -
329   - # The ultimate parent number identifies the corporate parent of the business and also serves as the ABI number for the headquarters site of the ultimate parent. Since all locations if a business have the same ultimate parent number, this field provides ‘corporate ownership’ linkage information. This information is not collected or maintained for the types of organizations for which ownership is ambiguous- churches, and schools in particular, are not linked in the file for this reason.
330   - def ultimate_parent_number
331   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.ultimateParentNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('ultimateParentNumber')
332   - end
333   -
334   - # This field returns the ZIP or postal code.
335   - def zip_or_postal_code
336   - self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.zIPOrPostalCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('zIPOrPostalCode')
337   - end
338   -
339   - end
340   -
341 18 end
40 lib/strike_iron/reverse_phone_address_lookup.rb
... ... @@ -0,0 +1,40 @@
  1 +class StrikeIron::ReversePhoneAddressLookup
  2 + include StrikeIron::ReversePhoneAddressLookupCommon
  3 +
  4 + WSDL = "#{parent::WSDL_PREFIX}ReversePhoneAddressLookup?WSDL"
  5 +
  6 + def initialize(phone)
  7 + @phone = self.class.parent.validate_and_normalize_phone(phone)
  8 + end
  9 +
  10 + def result
  11 + if @result.nil?
  12 + unless @phone.nil?
  13 + driver = SOAP::WSDLDriverFactory.new(self.class::WSDL).create_rpc_driver
  14 + @result = driver.reverseLookupByPhoneNumber({'UserID' => self.class.parent::USER_ID, 'Password' => self.class.parent::PASSWORD, 'PhoneNumber' => @phone})
  15 + end
  16 + end
  17 + @result
  18 + end
  19 +
  20 + def attributes
  21 + attrs = {}
  22 + (methods - Object.methods - ['attributes','result']).each do |m|
  23 + attrs[m.to_sym] = self.send(m)
  24 + end
  25 + attrs
  26 + end
  27 +
  28 + # These methods aren't listed in the Common module.
  29 +
  30 + # This field returns the name of the company.
  31 + def company_name
  32 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.companyName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('companyName')
  33 + end
  34 +
  35 + # This field returns the name prefix. (DR., REV., MR, MRS.)
  36 + def name_prefix
  37 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.namePrefix) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('namePrefix')
  38 + end
  39 +
  40 +end
50 lib/strike_iron/reverse_phone_address_lookup_advanced.rb
... ... @@ -0,0 +1,50 @@
  1 +require 'soap/header/simplehandler'
  2 +class StrikeIron::ReversePhoneAddressLookupAdvanced
  3 + include StrikeIron::ReversePhoneAddressLookupCommon
  4 +
  5 + WSDL = "http://ws.strikeiron.com/PhoneandAddressAdvanced?WSDL"
  6 +
  7 + class WsseAuthHeader < SOAP::Header::SimpleHandler
  8 + def initialize
  9 + super(XSD::QName.new('http://ws.strikeiron.com', 'LicenseInfo'))
  10 + end
  11 +
  12 + def on_simple_outbound
  13 + {"RegisteredUser" => {"UserID" => self.class.parent.parent::USER_ID, "Password" => self.class.parent.parent::PASSWORD}}
  14 + end
  15 + end
  16 +
  17 + def initialize(phone)
  18 + @phone = self.class.parent.validate_and_normalize_phone(phone)
  19 + end
  20 +
  21 + def result
  22 + if @result.nil? && @phone.present?
  23 + driver = SOAP::WSDLDriverFactory.new(self.class::WSDL).create_rpc_driver
  24 + # driver.wiredump_dev = STDOUT
  25 + driver.headerhandler << WsseAuthHeader.new
  26 +
  27 + @result = driver.reverseLookupByPhoneNumber({'PhoneNumber' => @phone})
  28 + end
  29 + @result
  30 + end
  31 +
  32 + def attributes
  33 + attrs = {}
  34 + (methods - Object.methods - ['attributes','result']).each do |m|
  35 + attrs[m.to_sym] = self.send(m)
  36 + end
  37 + attrs
  38 + end
  39 +
  40 + # These methods aren't listed in the Common module.
  41 +
  42 + def city
  43 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.city) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('city')
  44 + end
  45 +
  46 + def run_type
  47 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.runType) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('runType')
  48 + end
  49 +
  50 +end
288 lib/strike_iron/reverse_phone_address_lookup_common.rb
... ... @@ -0,0 +1,288 @@
  1 +module StrikeIron::ReversePhoneAddressLookupCommon
  2 +
  3 + # This field returns the description of the status number.
  4 + def status_description
  5 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceStatus.statusDescription) if result && result.reverseLookupByPhoneNumberResult.serviceStatus.methods.include?('statusDescription')
  6 + end
  7 +
  8 + # This field returns a number referring to the status of this request.
  9 + def status_nbr
  10 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceStatus.statusNbr) if result && result.reverseLookupByPhoneNumberResult.serviceStatus.methods.include?('statusNbr')
  11 + end
  12 +
  13 + # This field returns an ABI Number which provides a unique identifier for each business in the infoUSA database.
  14 + def abi_number
  15 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.aBINumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('aBINumber')
  16 + end
  17 +
  18 + # This field returns the street address associated to the phone number provided.
  19 + def address
  20 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.address) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('address')
  21 + end
  22 +
  23 + # If the phone number provided as input is for a cell phone, the output returned for this field is true. Otherwise, the output returned for this field is false.
  24 + # (values = T or F)
  25 + def cell_phone
  26 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.cellPhone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('cellPhone')
  27 + end
  28 +
  29 + # This field returns a code corresponding to the title of the designated contact.
  30 + # 1 Owner
  31 + # 2 President
  32 + # 3 Manager
  33 + # 4 Executive Director
  34 + # 5 Principal
  35 + # 6 Publisher
  36 + # 7 Administrator
  37 + # 8 Religious Leader
  38 + # 9 Partner
  39 + # A Chairman
  40 + # B Vice Chairman
  41 + # C Chief Executive Officer
  42 + # D Director (Public Co)
  43 + # E Chief Operating Officer (COO)
  44 + # F Chief Financial Officer (CFO)
  45 + # G Treasurer
  46 + # H Controller
  47 + # I Executive Vice President
  48 + # J Senior Vice President
  49 + # K Vice President
  50 + # L Administration Executive
  51 + # M Corporate Communications Executive
  52 + # N Data Processing Executive
  53 + # O Finance Executive
  54 + # P Human Resources Executive
  55 + # Q Telecommunication Executive
  56 + # R Marketing Executive
  57 + # S Operations Executive
  58 + # T Sales Executive
  59 + # U Corporate Secretary
  60 + # V General Counsel
  61 + # W Executive Officer
  62 + # X Plant Manager
  63 + # Y Purchasing Agent
  64 + # Z Auditor
  65 + def contact_title_code
  66 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.contactTitleCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('contactTitleCode')
  67 + end
  68 +
  69 + # This field returns the country.
  70 + def country
  71 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.country) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('country')
  72 + end
  73 +
  74 + # This field returns the date when this information was last updated.
  75 + def date_added
  76 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.dateAdded) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('dateAdded')
  77 + end
  78 +
  79 + # This field returns the dwelling type.
  80 + # Dwellings types:
  81 + # C= Single Family
  82 + # D-K = 2-9 Residences at Same Address
  83 + # L= 10-19 Residences at Same Address
  84 + # M= 20-49 Residences at Same Address
  85 + # N= 50-100 Residences at Same Address
  86 + # O= 100+ Residences at Same Address
  87 + def dwelling_type
  88 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.dwellingType) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('dwellingType')
  89 + end
  90 +
  91 + # This field returns the number of employees at the location specified above.
  92 + def employee_size
  93 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.employeeSize) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('employeeSize')
  94 + end
  95 +
  96 + # This field returns the estimated household income, if available.
  97 + def estimated_head_of_household_income
  98 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.estimatedHeadOfHouseholdIncome) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('estimatedHeadOfHouseholdIncome')
  99 + end
  100 +
  101 + # This field returns the stock exchange that carries the stock symbol.
  102 + def exchange_code
  103 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.exchangeCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('exchangeCode')
  104 + end
  105 +
  106 + # This field returns the fax number for the company.
  107 + def fax_phone_number
  108 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.faxPhoneNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('faxPhoneNumber')
  109 + end
  110 +
  111 + # This field returns the first name.
  112 + def first_name
  113 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.firstName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('firstName')
  114 + end
  115 +
  116 + # This field returns the full name.
  117 + def full_name
  118 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.fullName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('fullName')
  119 + end
  120 +
  121 + # This field indicates if this address represents a single location, headquarters or branch of the company.
  122 + # 1 = Headquarters
  123 + # 2 = Branches
  124 + # 3 = Subsidiary Headquarters
  125 + # Blank = None of the above
  126 + def hq_branch_code
  127 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.hQBranchCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('hQBranchCode')
  128 + end
  129 +
  130 + # This field returns the year of birth of the head of the household, if available.
  131 + def head_of_household_birth_year
  132 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.headOfHouseholdBirthYear) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('headOfHouseholdBirthYear')
  133 + end
  134 +
  135 + # This field returns the gender of the head of the household.
  136 + def head_of_household_gender
  137 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.headOfHouseholdGender) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('headOfHouseholdGender')
  138 + end
  139 +
  140 + # This field returns the homeowner probability.
  141 + # Types:
  142 + # H= Homeowner
  143 + # 9= probable homeowner 90-100%
  144 + # 8= probable homeowner 80-89%
  145 + # 7= probable homeowner 70-79%
  146 + # 6= Likely Homeowner
  147 + # R= Renter
  148 + # T, 0-4 = Probably Renter
  149 + # U, 5= Unknown
  150 + def homeowner_probability
  151 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.homeownerProbability) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('homeownerProbability')
  152 + end
  153 +
  154 + # This field returns the last name.
  155 + def last_name
  156 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.lastName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('lastName')
  157 + end
  158 +
  159 + # This field returns the length of time the person has lived at the residence.
  160 + def length_of_residency
  161 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.lengthOfResidency) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('lengthOfResidency')
  162 + end
  163 +
  164 + # This field returns an alpha code corresponding to the estimated sales of the business in thousands of dollars.
  165 + # A 1 - 499
  166 + # B 500 - 999
  167 + # C 1,000 - 2,499
  168 + # D 2,500 - 4,999
  169 + # E 5,000 - 9,999
  170 + # F 10,000 - 19,999
  171 + # G 20,000 - 49,999
  172 + # H 50,000 - 99,999
  173 + # I 100,000 - 499,999
  174 + # J 500,000 - 999,999
  175 + # K 1,000,000 +
  176 + def local_sales_code
  177 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.localSalesCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('localSalesCode')
  178 + end
  179 +
  180 + # This field returns the middle name or initial.
  181 + def middle_name
  182 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.middleName) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('middleName')
  183 + end
  184 +
  185 + # This field returns the name suffix (if applicable)
  186 + def name_suffix
  187 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.nameSuffix) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('nameSuffix')
  188 + end
  189 +
  190 + # This field returns the phone number provided as input.
  191 + def original_phone
  192 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.originalPhone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('originalPhone')
  193 + end
  194 +
  195 + # This field returns whether or not the company is public, if available.
  196 + def public_company_indicator
  197 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.publicCompanyIndicator) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('publicCompanyIndicator')
  198 + end
  199 +
  200 + # Indicates if the number provided is a business or residential number. The demographic data returned will correspond to the record type.
  201 + # Potential Values:
  202 + # IS or IP= Residential Match
  203 + # BS or BP= Business Match
  204 + # IC= Residential Canadian Match
  205 + # BC= Business Canadian Match
  206 + def record_type
  207 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.recordType) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('recordType')
  208 + end
  209 +
  210 + # Standard Industry Code for the Company.
  211 + def sic
  212 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.sIC) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('sIC')
  213 + end
  214 +
  215 + # Description of the Standard Industry Code for the Company.
  216 + def sic_description
  217 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.sICDescription) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('sICDescription')
  218 + end
  219 +
  220 + # This field returns any additional activity of the business.
  221 + def secondary_sic1
  222 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC1) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC1')
  223 + end
  224 +
  225 + # This field returns any additional activity of the business.
  226 + def secondary_sic2
  227 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC2) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC2')
  228 + end
  229 +
  230 + # This field returns any additional activity of the business.
  231 + def secondary_sic3
  232 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC3) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC3')
  233 + end
  234 +
  235 + # This field returns any additional activity of the business.
  236 + def secondary_sic4
  237 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.secondarySIC4) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('secondarySIC4')
  238 + end
  239 +
  240 + # This field returns a ‘Yes, ‘No’ or (blank) indicating whether or not the phone number is on the specific state or Direct Marketing Association Do Not Call list.
  241 + # (*NOTE: this field does not return information from the National Do Not Call List.).
  242 + def state_dnc
  243 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.stateDNC) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('stateDNC')
  244 + end
  245 +
  246 + # This field returns the state or province.
  247 + def state_or_province
  248 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.stateOrProvince) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('stateOrProvince')
  249 + end
  250 +
  251 + # The subsidiary parent number identifies the business as a regional or subsidiary headquarters for the corporate family. The subsidiary will always have an ultimate parent and may or may not have braches assigned to it.
  252 + def sub_parent_number
  253 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.subParentNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('subParentNumber')
  254 + end
  255 +
  256 + # This field returns the stock ticker symbol.
  257 + def ticker_symbol
  258 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.tickerSymbol) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('tickerSymbol')
  259 + end
  260 +
  261 + # This field returns the time zone.
  262 + # Values:
  263 + # E= Eastern
  264 + # C= Central
  265 + # M= Mountain
  266 + # P= Pacific
  267 + # A= Alaska
  268 + # H= Hawaii
  269 + def time_zone
  270 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.timeZone) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('timeZone')
  271 + end
  272 +
  273 + # This field returns the number of employees in the company.
  274 + def total_employee_size
  275 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.totalEmployeeSize) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('totalEmployeeSize')
  276 + end
  277 +
  278 + # The ultimate parent number identifies the corporate parent of the business and also serves as the ABI number for the headquarters site of the ultimate parent. Since all locations if a business have the same ultimate parent number, this field provides ‘corporate ownership’ linkage information. This information is not collected or maintained for the types of organizations for which ownership is ambiguous- churches, and schools in particular, are not linked in the file for this reason.
  279 + def ultimate_parent_number
  280 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.ultimateParentNumber) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('ultimateParentNumber')
  281 + end
  282 +
  283 + # This field returns the ZIP or postal code.
  284 + def zip_or_postal_code
  285 + self.class.parent.normalize_result_value(result.reverseLookupByPhoneNumberResult.serviceResult.zIPOrPostalCode) if result && result.reverseLookupByPhoneNumberResult.serviceResult.methods.include?('zIPOrPostalCode')
  286 + end
  287 +
  288 +end

0 comments on commit aeb6c5e

Please sign in to comment.
Something went wrong with that request. Please try again.