Module: FullContact::Client::BatchProcess

Included in:
FullContact::Client
Defined in:
lib/fullcontact/client/batch_process.rb

Instance Method Summary collapse

Instance Method Details

#batch(options = {}) ⇒ Object

Public: The Batch Process endpoint allows you to batch several API requests into a single request to improve performance by eliminating excess network overhead. This endpoint will proxy requests (up to 20 per batch) on your behalf to any other API endpoint which accepts GET requests.

Yields array of URLs to api endpoints

Example

respnose = FullContact.batch do 
  [FullContact.normalize('Mr. John Michael Smith'),
   FullContact.deduce_by_email('[email protected]')]
  end
'response' contains batch response from the api

Returns response from different api methods in the batch



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fullcontact/client/batch_process.rb', line 21

def batch(options = {})
  FullContact.configure do |config|
    config.get_request_url_only = true
  end
  batch_method_list = yield
  FullContact.configure do |config|
    config.get_request_url_only = false
  end
  options[:content_type] = 'application/json'
  options[:request_body] = {:requests => batch_method_list}.to_json
  post("batch", options)
end