class Neustar::WsGetData::Client

Base client used to interface with WS-GetData query and batch_query services.

Constants

MAX_TRANSACTION_ID

Maximum transaction ID:

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options The configuration options @option options [String] :username Name of the Neustar account @option options [String] :password Password for the Neustar account @option options [String] ::service_id Service ID for the Neustar account

# File lib/neustar-ws_get_data/client.rb, line 10
def initialize(options = {})
  @service    = Savon.client(:wsdl => Neustar::WsGetData::WSDL)
  @username   = options[:username] or
                  raise ConfigurationError, "Username required"
  @password   = options[:password] or
                  raise ConfigurationError, "Password required"
  @service_id = options[:service_id] or
                  raise ConfigurationError, "Service ID required"
end

Public Instance Methods

batch_query(params) click to toggle source

Execute a batch query.

@param [Hash] params @return [Hash]

# File lib/neustar-ws_get_data/client.rb, line 39
def batch_query(params)
  call(:batch_query, params)
end
build_transaction_id() click to toggle source

Returns a unique transaction ID to send with each request.

@return [String]

# File lib/neustar-ws_get_data/client.rb, line 97
def build_transaction_id
  SecureRandom.random_number(MAX_TRANSACTION_ID)
end
call(service, params) click to toggle source

Execute a call to the given service type.

@param [Symbol] service @return [Hash]

# File lib/neustar-ws_get_data/client.rb, line 47
def call(service, params)
  transaction_id = params.fetch(:transaction_id) { build_transaction_id }

  message = origination_params.
            merge(:transId => transaction_id).
            merge(params)

  begin
    response = @service.call(service, :message => message)
    process_response(service, response)
  rescue Savon::SOAPFault => error
    raise Neustar::Error, extract_fault_message(error)
  end
end
operations() click to toggle source

List the operations available to the client.

@return [Array<Symbol>]

# File lib/neustar-ws_get_data/client.rb, line 23
def operations
  @service.operations
end
origination_params() click to toggle source

Parameters used to authenticate the client.

@return [Hash]

# File lib/neustar-ws_get_data/client.rb, line 85
def origination_params
  {
    :origination => {
      :username => @username, :password => @password
    },
    :serviceId   => @service_id.to_s
  }
end
phone_attributes(phone_number, indicators = []) click to toggle source

Helper to access PhoneAttributes element. TODO: Refactor out of here

@param [#to_s] phone_number @param [Array<Symbol>] indicators

# File lib/neustar-ws_get_data/client.rb, line 78
def phone_attributes(phone_number, indicators = [])
  Neustar::WsGetData::PhoneAttributes.query(self, phone_number, indicators)
end
process_response(service, response) click to toggle source

Execute initial post-processing and error handling on the response.

@param [Symbol] service @param [Savon::Response] response

@return [Hash]

# File lib/neustar-ws_get_data/client.rb, line 68
def process_response(service, response)
  response_wrapper = response.body[:"#{service}_response"]
  response_wrapper && response_wrapper[:response]
end
query(params) click to toggle source

Execute an ‘interactive’ query.

@param [Hash] params @return [Hash]

# File lib/neustar-ws_get_data/client.rb, line 31
def query(params)
  call(:query, params)
end

Private Instance Methods

extract_fault_message(error) click to toggle source

Pulls the error message from a Savon::SOAPFault exception.

@param [Savon::SOAPFault] error @return [String]

# File lib/neustar-ws_get_data/client.rb, line 105
def extract_fault_message(error)
  data = error.to_hash

  if (fault = data[:fault]) and (faultstring = fault[:faultstring]) then
    faultstring
  else
    "Unknown Error"
  end
end