module Neustar::WsGetData::PhoneAttributes
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.”
Constants
- BUSINESS_PHONE_INDICATOR_MAP
The assumed purpose for a phone.
- ELEMENT_ID
ID for “Phone Attributes”.
- INDICATORS
Mappings to request certain indicators from the service.
- INDICATOR_MAPPINGS
A map between each attribute and their possible values.
- OUT_OF_DOMAIN_ERROR
Indicates that an invalid phone number was sent to the service.
- PHONE_ATTRIBUTES_REQUESTED_SERVICE_ID
Service ID to specify which attributes we want returned.
- 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.
- PHONE_TYPE_INDICATOR_MAP
The type of phone used.
- PREPAID_PHONE_ATTRIBUTE_MAP
Whether or not a phone is prepaid.
- TELEPHONE_SPECIFICATION_SERVICE_ID
Service ID to specify the telephone number in a request.
Public Instance Methods
Assemble and execute a query using the passed client.
@param [Neustar::WsGetData::Client] client @param [Hash] params @option params [String] :phone_number @option params [String] :indicators
@return [Hash]
# 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
Given a list of indicator symbols, derive the argument to send the service.
@param [Array<Symbol>] indicators @return [String]
# 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
Do element specific processing on response from client.
@param [Hash] response @option response [String] :error_code The stringified number
of the error code
@option response [Hash] :result @param [Hash] params @option params [String] :phone_number
@return [Hash]
# 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
Method used to execute a query against the Phone Attributes element of the WS-GetData Service.
@param [Neustar::WsGetData::Client] client @param [#to_s] phone_number @param [Array<Symbol>] indicators
@return [Hash]
# 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