Class: ExperianConsumerView::Api

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/experian_consumer_view/api.rb

Overview

Low-level class for accessing the Experian ConsumerView API. It is not recommended to use this class directly. The ExperianConsumerView::Client class is designed to be directly used by applications.

This class provides low-level access to make specific HTTP calls to the ConsumerView API, such as logging in to get an authorisation token, and performing lookups of an individual / household / postcode.

Constant Summary collapse

PRODUCTION_URL =
'https://neartime.experian.co.uk'
STAGING_URL =
'https://stg.neartime.experian.co.uk'
LOGIN_PATH =
'/overture/login'
SINGLE_LOOKUP_PATH =
'/overture/lookup'
BATCH_LOOKUP_PATH =
'/overture/batch'

Instance Method Summary collapse

Constructor Details

#initialize(url: nil) ⇒ Api



26
27
28
29
30
31
# File 'lib/experian_consumer_view/api.rb', line 26

def initialize(url: nil)
  @httpclient = Faraday.new(
    url: url || PRODUCTION_URL,
    headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
  )
end

Instance Method Details

#batch_lookup(user_id:, token:, client_id:, asset_id:, batched_search_keys:) ⇒ Array<Hash>

Looks up demographic data for a batch of individuals / households / postcodes.

Note that the demographic / propensity keys returned will only be those which the given client & asset have access to. Refer to the Experian ConsumerView API Documentation for exact details of the keys & possible values.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/experian_consumer_view/api.rb', line 95

def batch_lookup(user_id:, token:, client_id:, asset_id:, batched_search_keys:)
  raise ApiBatchTooBigError if batched_search_keys.length > ExperianConsumerView::MAX_LOOKUP_BATCH_SIZE

  query_params = {
    'ssoId' => user_id,
    'token' => token,
    'clientId' => client_id,
    'assetId' => asset_id,
    'batch' => batched_search_keys
  }

  result = @httpclient.post(BATCH_LOOKUP_PATH, query_params.to_json)
  check_http_result_status(result)

  JSON.parse(result.body)
end

#get_auth_token(user_id:, password:) ⇒ Object

Logs in to the Experian ConsumerView API, and gets an authorization token.



37
38
39
40
41
42
43
44
# File 'lib/experian_consumer_view/api.rb', line 37

def get_auth_token(user_id:, password:)
  query_params = { 'userid' => user_id, 'password' => password }

  result = @httpclient.post(, query_params.to_json)
  check_http_result_status(result)

  JSON.parse(result.body)['token']
end

#single_lookup(user_id:, token:, client_id:, asset_id:, search_keys:) ⇒ Hash

Looks up demographic data for a single individual / household / postcode.

Note that the demographic / propensity keys returned will only be those which the given client & asset have access to. Refer to the Experian ConsumerView API Documentation for exact details of the keys & possible values.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/experian_consumer_view/api.rb', line 60

def single_lookup(user_id:, token:, client_id:, asset_id:, search_keys:)
  # TODO: Delete this if looking up a single item via the batch method isn't any slower - no point supporting both!

  query_params = {
    'ssoId' => user_id,
    'token' => token,
    'clientId' => client_id,
    'assetId' => asset_id
  }
  query_params.merge!(search_keys)

  result = @httpclient.post(SINGLE_LOOKUP_PATH, query_params.to_json)
  check_http_result_status(result)

  JSON.parse(result.body)
end