Module: Neustar::WsGetData::PhoneAttributes
- Extended by:
- PhoneAttributes
- Included in:
- PhoneAttributes
- Defined in:
- lib/neustar-ws_get_data/elements/phone_attributes.rb
Overview
From the documentation:
“Element ID 1320 accepts a phone number and returns attributes associated with the phone number. Currently, the following attributes are available: Prepaid Phone Indicator, Business Phone Indicator (BPI), Phone In-Service Indicator, and Phone Type Indicator.”
Defined Under Namespace
Classes: OutOfDomainError
Constant Summary collapse
- ELEMENT_ID =
ID for “Phone Attributes”.
1320
- TELEPHONE_SPECIFICATION_SERVICE_ID =
Service ID to specify the telephone number in a request.
1
- PHONE_ATTRIBUTES_REQUESTED_SERVICE_ID =
Service ID to specify which attributes we want returned.
599
- INDICATORS =
Mappings to request certain indicators from the service.
{ :prepaid_phone => 1, :business_phone => 2, :phone_in_service => 3, :phone_type => 4, }
- PREPAID_PHONE_ATTRIBUTE_MAP =
Whether or not a phone is prepaid.
{ 'Y' => true, 'N' => false }
- BUSINESS_PHONE_INDICATOR_MAP =
The assumed purpose for a phone.
{ 'B' => :business_phone, 'C' => :residential_phone, 'D' => :dual_phone, 'U' => :unknown }
- PHONE_IN_SERVICE_INDICATOR_MAP =
The Phone In-Service field indicates whether the phone is active and provides a range indicator for the active/inactive status.
{ 'A1' => "Active for 1 month or less", 'A2' => "Active for 2 months", 'A3' => "Active for 3 months", 'A4' => "Active for between 4-6 months", 'A5' => "Active for between 7-9 months", 'A6' => "Active for between 10-11 months", 'A7' => "Active for 12 months or longer", 'I1' => "Inactive for 1 month or less", 'I2' => "Inactive for 2 months", 'I3' => "Inactive for 3 months", 'I4' => "Inactive for between 4-6 months", 'I5' => "Inactive for between 7-9 months", 'I6' => "Inactive for between 10-11 months", 'I7' => "Inactive for 12 months or longer", 'U' => "Status Unknown", }
- PHONE_TYPE_INDICATOR_MAP =
The type of phone used.
{ 'W' => :wireless, 'L' => :landline, 'U' => :unknown }
- INDICATOR_MAPPINGS =
A map between each attribute and their possible values.
{ :prepaid_phone => PREPAID_PHONE_ATTRIBUTE_MAP, :business_phone => BUSINESS_PHONE_INDICATOR_MAP, :phone_in_service => PHONE_IN_SERVICE_INDICATOR_MAP, :phone_type => PHONE_TYPE_INDICATOR_MAP }
- OUT_OF_DOMAIN_ERROR =
Indicates that an invalid phone number was sent to the service.
"6"
Instance Method Summary collapse
-
#execute_request(client, params) ⇒ Hash
Assemble and execute a query using the passed client.
-
#parse_indicators(indicators) ⇒ String
Given a list of indicator symbols, derive the argument to send the service.
-
#process_response(response, params) ⇒ Hash
Do element specific processing on response from client.
-
#query(client, phone_number, indicators = []) ⇒ Hash
Method used to execute a query against the Phone Attributes element of the WS-GetData Service.
Instance Method Details
#execute_request(client, params) ⇒ Hash
Assemble and execute a query using the passed client.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/neustar-ws_get_data/elements/phone_attributes.rb', line 109 def execute_request(client, params) client.query( :elements => { :id => ELEMENT_ID }, :serviceKeys => { :serviceKey => [ { :id => TELEPHONE_SPECIFICATION_SERVICE_ID, :value => params[:phone_number] }, { :id => PHONE_ATTRIBUTES_REQUESTED_SERVICE_ID, :value => params[:indicators] } ] } ) end |
#parse_indicators(indicators) ⇒ String
Given a list of indicator symbols, derive the argument to send the service.
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/neustar-ws_get_data/elements/phone_attributes.rb', line 158 def parse_indicators(indicators) vals = if indicators.empty? INDICATORS.values else INDICATORS.values_at(*indicators) end vals.join(',') end |
#process_response(response, params) ⇒ Hash
Do element specific processing on response from client.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/neustar-ws_get_data/elements/phone_attributes.rb', line 137 def process_response(response, params) if response[:error_code] == OUT_OF_DOMAIN_ERROR raise OutOfDomainError, params[:phone_number] else string = response[:result][:element][:value] result = {} INDICATOR_MAPPINGS.each do |name, mapping| mapping.detect do |key, value| result[name] = value if string.index(key) end end result end end |
#query(client, phone_number, indicators = []) ⇒ Hash
Method used to execute a query against the Phone Attributes element of the WS-GetData Service.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/neustar-ws_get_data/elements/phone_attributes.rb', line 90 def query(client, phone_number, indicators = []) indicators = parse_indicators(indicators) params = { :phone_number => phone_number, :indicators => indicators } process_response(execute_request(client, params), params) end |