experian_consumer_view 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2f9bc4cb3b7210d1974ad2558dbdfcd2ef74bb34b3fd4a493be72e1fae473dd
4
+ data.tar.gz: e31c691987efd36d8233ee176de48c6e588e91e5b2f47c273d250eb5c7a384dc
5
+ SHA512:
6
+ metadata.gz: 03200c8c322988ad29fddaa6cf0a478e7831dcf282724cfa1da129dee8887c67b9b4d6a33dde1d72b9a7909a6c139bf7346eda67cf218d40f996835cfd874e53
7
+ data.tar.gz: 68cc86a3af3b91be3d74e845e654a632afc1629345b6f506dc72986af24fc290a94748be2174bf7f028edaa2c05a61b96710b59efb2dc0889c812eab62dac887
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,28 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://docs.rubocop.org/rubocop/configuration
11
+
12
+ AllCops:
13
+ NewCops: enable
14
+
15
+ Metrics/AbcSize:
16
+ Max: 34 # double the default
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - 'spec/**/*_spec.rb'
21
+ - '*.gemspec'
22
+
23
+ Metrics/CyclomaticComplexity:
24
+ Max: 14 # double the default
25
+
26
+ Metrics/MethodLength:
27
+ Max: 20 # double the default
28
+ CountAsOne: ['array', 'hash', 'heredoc']
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in experian_consumer_view.gemspec
6
+ gemspec
@@ -0,0 +1,103 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ experian_consumer_view (1.0.0)
5
+ activesupport (>= 5.2)
6
+ faraday (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.3.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ ast (2.4.1)
20
+ codecov (0.2.11)
21
+ json
22
+ simplecov
23
+ coderay (1.1.3)
24
+ concurrent-ruby (1.1.7)
25
+ crack (0.4.4)
26
+ diff-lcs (1.4.4)
27
+ docile (1.3.2)
28
+ faraday (1.0.1)
29
+ multipart-post (>= 1.2, < 3)
30
+ hashdiff (1.0.1)
31
+ i18n (1.8.5)
32
+ concurrent-ruby (~> 1.0)
33
+ json (2.3.1)
34
+ method_source (1.0.0)
35
+ minitest (5.14.2)
36
+ multipart-post (2.1.1)
37
+ parallel (1.19.2)
38
+ parser (2.7.1.4)
39
+ ast (~> 2.4.1)
40
+ pry (0.13.1)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
43
+ public_suffix (4.0.6)
44
+ rainbow (3.0.0)
45
+ rake (13.0.1)
46
+ regexp_parser (1.8.0)
47
+ rexml (3.2.4)
48
+ rspec (3.9.0)
49
+ rspec-core (~> 3.9.0)
50
+ rspec-expectations (~> 3.9.0)
51
+ rspec-mocks (~> 3.9.0)
52
+ rspec-core (3.9.2)
53
+ rspec-support (~> 3.9.3)
54
+ rspec-expectations (3.9.2)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.9.0)
57
+ rspec-mocks (3.9.1)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.9.0)
60
+ rspec-support (3.9.3)
61
+ rubocop (0.91.0)
62
+ parallel (~> 1.10)
63
+ parser (>= 2.7.1.1)
64
+ rainbow (>= 2.2.2, < 4.0)
65
+ regexp_parser (>= 1.7)
66
+ rexml
67
+ rubocop-ast (>= 0.4.0, < 1.0)
68
+ ruby-progressbar (~> 1.7)
69
+ unicode-display_width (>= 1.4.0, < 2.0)
70
+ rubocop-ast (0.4.2)
71
+ parser (>= 2.7.1.4)
72
+ ruby-progressbar (1.10.1)
73
+ simplecov (0.19.0)
74
+ docile (~> 1.1)
75
+ simplecov-html (~> 0.11)
76
+ simplecov-html (0.12.2)
77
+ thread_safe (0.3.6)
78
+ tzinfo (1.2.7)
79
+ thread_safe (~> 0.1)
80
+ unicode-display_width (1.7.0)
81
+ webmock (3.9.1)
82
+ addressable (>= 2.3.6)
83
+ crack (>= 0.3.2)
84
+ hashdiff (>= 0.4.0, < 2.0.0)
85
+ yard (0.9.25)
86
+ zeitwerk (2.4.0)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ bundler (~> 2.1)
93
+ codecov (>= 0.2)
94
+ experian_consumer_view!
95
+ pry (>= 0.12)
96
+ rake (>= 12.0)
97
+ rspec (~> 3.0)
98
+ rubocop (~> 0.91.0)
99
+ webmock (~> 3.9)
100
+ yard (~> 0.9.25)
101
+
102
+ BUNDLED WITH
103
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020, 38 Degrees Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,319 @@
1
+ # ExperianConsumerView
2
+
3
+ ExperianConsumerView is a Ruby Gem client for the [Experian](https://www.experian.co.uk/) ConsumerView API. This is a product licensed by Experian, and as such this client is only useful if you have a license key for the ConsumerView API product.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'experian_consumer_view'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install experian_consumer_view
20
+
21
+ ## Usage
22
+
23
+ ### Basic example
24
+
25
+ ```ruby
26
+ # Create the client
27
+ # Experian will send your user_id, password, client_id, & asset_id when you purchase a license
28
+ client = ExperianConsumerView::Client.new(
29
+ user_id: 'YOUR_USER_ID',
30
+ password: 'YOUR_PASSWORD',
31
+ client_id: 'YOUR_CLIENT_ID',
32
+ asset_id: 'YOUR_ASSET_ID'
33
+ )
34
+
35
+ # Lookup a single item from the API:
36
+ result = client.lookup(search_items: { "MyPostcode" => { "postcode" => "SW1A 0AA" } })
37
+ # result will be something like:
38
+ # {
39
+ # "MyPostcode" => {
40
+ # "pc_mosaic_uk_7_group" => { api_code: 'A', group: 'A', description: 'City Prosperity' },
41
+ # "pc_mosaic_uk_7_type" => { api_code: '03', type: 'A03', description: 'Penthouse Chic' },
42
+ # "Match" => { api_code: 'PC', match_level: 'postcode' }
43
+ # }
44
+ # }
45
+
46
+ # Lookup a batch of items from the API:
47
+ batch_result = client.lookup(search_items: {
48
+ "Postcode1" => { "postcode" => "SW1A 0AA" },
49
+ "Address2" => { "addressline" => "10 Downing Street", "postcode" => "SW1A 2AA" },
50
+ "Person3" => { "email" => "example@example.com" }
51
+ })
52
+ # batch_result will be something like:
53
+ # {
54
+ # "Postcode1" => {
55
+ # "pc_mosaic_uk_7_group" => { api_code: 'A', group: 'A', description: 'City Prosperity' },
56
+ # "pc_mosaic_uk_7_type" => { api_code: '03', type: 'A03', description: 'Penthouse Chic' },
57
+ # "Match" => { api_code: 'PC', match_level: 'postcode' }
58
+ # },
59
+ # "Address2" => {
60
+ # "pc_mosaic_uk_7_group" => { api_code: 'A', group: 'A', description: 'City Prosperity' },
61
+ # "pc_mosaic_uk_7_type" => { api_code: '02', type: 'A02', description: 'Uptown Elite' },
62
+ # "Match" => { api_code: 'H', match_level: 'household' }
63
+ # },
64
+ # "Person3" => {
65
+ # "pc_mosaic_uk_7_group" => { api_code: 'O', group: 'O', description: 'Rental Hubs' },
66
+ # "pc_mosaic_uk_7_type" => { api_code: '66', type: 'O66', description: 'Student Scene' },
67
+ # "Match" => { api_code: 'P', match_level: 'person' }
68
+ # }
69
+ # }
70
+ ```
71
+
72
+ ### Understanding what to pass to the lookup method
73
+
74
+ Calls to `lookup` require the `search_items` named parameter - this is a hash of items to lookup in the API. Eg. as per the example above:
75
+
76
+ ```ruby
77
+ client.lookup(search_items: {
78
+ "Postcode1" => { "postcode" => "SW1A 0AA" },
79
+ "Address2" => { "addressline" => "10 Downing Street", "postcode" => "SW1A 2AA" },
80
+ "Person3" => { "email" => "example@example.com" }
81
+ })
82
+ ```
83
+
84
+ The keys are arbitrary names you assign to each search item for reference. For example they could be the ID of a postcode or person in your application database. The example above uses "Postcode1", "Address2", etc.
85
+
86
+ The values are the items you wish to search for in the API, in order to get demographic data about them. The ConsumerView API allows searching for demographic data at various levels, such as postcode, household, or an individual person. Each value must itself be a hash, as you can see in the examples above. They must contain a valid combination of search keys which the ConsumerView API supports. Eg:
87
+
88
+ - Providing just a `postcode` would search for data at the postcode level.
89
+ - Providing an `addressline` and a `postcode` would search for data at the household level.
90
+ - Providing an `email` would search for data at the person level.
91
+
92
+ There are other valid combinations of search keys - refer to the ConsumerView API Developer Guide. Note, search keys may change over time as the ConsumerView API changes.
93
+
94
+ ### Understanding what is returned from the lookup method
95
+
96
+ Each successful call to `lookup` will return a hash containing the same keys as were provided in the `search_items` argument, as well as the results returned by the ConsumerView API for each search item.
97
+
98
+ For example:
99
+
100
+ ```ruby
101
+ client.lookup(search_items: {
102
+ "Postcode1" => { "postcode" => "SW1A 0AA" },
103
+ "Address2" => { "addressline" => "10 Downing Street", "postcode" => "SW1A 2AA" },
104
+ "Person3" => { "email" => "example@example.com" }
105
+ })
106
+
107
+ # Outputs something like:
108
+ {
109
+ "Postcode1" => {
110
+ "pc_mosaic_uk_7_group" => { api_code: 'A', group: 'A', description: 'City Prosperity' },
111
+ "pc_mosaic_uk_7_type" => { api_code: '03', type: 'A03', description: 'Penthouse Chic' },
112
+ "Match" => { api_code: 'PC', match_level: 'postcode' }
113
+ },
114
+ "Address2" => {
115
+ "pc_mosaic_uk_7_group" => { api_code: 'A', group: 'A', description: 'City Prosperity' },
116
+ "pc_mosaic_uk_7_type" => { api_code: '02', type: 'A02', description: 'Uptown Elite' },
117
+ "Match" => { api_code: 'H', match_level: 'household' }
118
+ },
119
+ "Person3" => {
120
+ "pc_mosaic_uk_7_group" => { api_code: 'O', group: 'O', description: 'Rental Hubs' },
121
+ "pc_mosaic_uk_7_type" => { api_code: '66', type: 'O66', description: 'Student Scene' },
122
+ "Match" => { api_code: 'P', match_level: 'person' }
123
+ }
124
+ }
125
+ ```
126
+
127
+ In this example, the keys "Postcode1", "Address2" & "Person3" were provided in the `search_items`, so these are also be used as the keys in the result hash.
128
+
129
+ Each search item has a hash containing all the data returned by the ConsumerView API for that search item. For example, here we can see each search item has the mosaic group (`pc_mosaic_uk_7_group`) & type (`pc_mosaic_uk_7_type`), as well as the match level (`Match`).
130
+
131
+ If a search item is not successfully looked up in the Experian API, that search item will have an empty hash.
132
+
133
+ Note, your license with Experian will determine the exact attributes the ConsumerView API will return. Refer to the ConsumerView API Variables and Propensities Reference Guide for details on what is available, and all possible values.
134
+
135
+ #### Mapping attributes
136
+
137
+ By default, some attributes are automatically transformed from single values into richer objects.
138
+
139
+ In the example above, the ConsumerView API returned `pc_mosaic_uk_7_group`, `pc_mosaic_uk_7_type`, and `Match` attributes. For the "Postcode1" search item, the raw values from the API would have been `A`, `03`, and `PC` respectively - these are not very informative.
140
+
141
+ Instead, they have been automatically transformed into richer hashes containing more meaningful information - eg. we can see from the richer hashes that the mosaic group `A` means "City Prosperity", and the mosaic type `03` means "Penthouse Chic".
142
+
143
+ See the [Transformers::Attributes classes](lib/experian_consumer_view/transformers/attributes) to see exactly which attributes are transformed, and how.
144
+
145
+ Attributes without transformers will still be returned, but they will just have the raw value from the API.
146
+
147
+ _You can also apply custom transformations to the data returned by the ConsumerView API, in order to automatically transform the data into a richer or more useable format for consumption by your application. This is described further in the advanced useage section of this documentation._
148
+
149
+ #### The Match attribute
150
+
151
+ Note that `Match` is a special attribute which is always returned if the search was successful, and indicates at what level a match was found.
152
+
153
+ For example, if searching for a household, it may be that demographic data for the specific household could not be found, but demographic data for the postcode was found, in which case the `Match` attribute would be 'PC' (postcode) rather than 'H' (household).
154
+
155
+ ## Advanced Useage
156
+
157
+ ### Providing a token cache
158
+
159
+ If you are using this code in a multi-server / cloud-based setup, then it is recommended that you override the default in-memory token cache. A distributed cache, eg. Redis, is recommended.
160
+
161
+ Using the in-memory token cache in such environments may lead to multiple servers logging into the ConsumerView API with the same credentials, invalidating the others' API tokens.
162
+
163
+ You may override the default by initializing the `Client` with the `token_cache` option. This must be an `ActiveSupport::Cache` object.
164
+
165
+ For example, in a Rails app, if the default Rails cache has already been configured to use a distributed cache like Redis, you may use:
166
+
167
+ ```ruby
168
+ client = ExperianConsumerView::Client.new(
169
+ user_id: 'YOUR_USER_ID',
170
+ password: 'YOUR_PASSWORD',
171
+ client_id: 'YOUR_CLIENT_ID',
172
+ asset_id: 'YOUR_ASSET_ID',
173
+ options: { token_cache: Rails.cache }
174
+ )
175
+ ```
176
+
177
+ ### Using a non-standard API URL
178
+
179
+ This can be useful if you need to test your code, eg. against Experians Staging server. Override the default URL by initializing the `Client` with the `api_base_url` option:
180
+
181
+ ```ruby
182
+ client = ExperianConsumerView::Client.new(
183
+ user_id: 'YOUR_USER_ID',
184
+ password: 'YOUR_PASSWORD',
185
+ client_id: 'YOUR_CLIENT_ID',
186
+ asset_id: 'YOUR_ASSET_ID',
187
+ options: { api_base_url: ExperianConsumerView::Api::STAGING_URL }
188
+ )
189
+ ```
190
+
191
+ ### Mapping / transforming the returned data
192
+
193
+ By default, this gem maps _some_ of the raw attributes returned by the ConsumerView API into richer objects for ease of use by other applications.
194
+
195
+ However, you can provide your own transformer by initializing the `Client` with the `result_transformer` option.
196
+
197
+ #### Turning off result transforming
198
+
199
+ Transforming will have some performance impact. If you just want the raw data provided by the API, then use the provided `NoOpTransformer`.
200
+
201
+ ```ruby
202
+ client = ExperianConsumerView::Client.new(
203
+ user_id: 'YOUR_USER_ID',
204
+ password: 'YOUR_PASSWORD',
205
+ client_id: 'YOUR_CLIENT_ID',
206
+ asset_id: 'YOUR_ASSET_ID',
207
+ options: { result_transformer: ExperianConsumerView::Transformers::NoOpTransformer.new }
208
+ )
209
+
210
+ result = client.lookup(search_items: { "MyPostcode" => { "postcode" => "SW1A 0AA" } })
211
+ # result will be something like:
212
+ # { "MyPostcode" => { "pc_mosaic_uk_7_group" => "A", "pc_mosaic_uk_7_type" => "03", "Match" => "PC" } }
213
+ ```
214
+
215
+ Note that the results will still be parsed from a JSON String into a Ruby Hash, which will be keyed on the search item keys. If you want the _completely_ raw API results, you may use the `ExperianConsumerView::Api` class directly.
216
+
217
+ #### Using your own attribute transformers
218
+
219
+ If you simply want to transform more attributes, or transform them in a slightly different manner, you can use the provided `ResultTransformer` as a base, and register as many custom attribute transformers as you wish on it.
220
+
221
+ Each attribute transformer must provide an `attribute_name` method, and a `transform_attribute` method, and examples can be seen in the [Transformers::Attributes module](lib/experian_consumer_view/transformers/attributes).
222
+
223
+ New attribute transformers can be easily created by extending `ExperianConsumerView::Transformers::Attributes::Base`, but this is not required as long as the necessary methods are implemented.
224
+
225
+ An example of creating & using a custom attribute transformer:
226
+
227
+ ```ruby
228
+ class CustomAttributeTransformer
229
+ def attribute_name
230
+ "p_head_of_household" # Transform attributes returned by the API with this name
231
+ end
232
+ def transform_attribute(value)
233
+ case value
234
+ when '0'
235
+ 'Not head of household' # The API Code of 0 means 'Not head of household'
236
+ when '1'
237
+ 'Head of household' # The API Code of 1 means 'Head of household'
238
+ else
239
+ 'Unclassified' # Any other API Code means 'Unclassified'
240
+ end
241
+ end
242
+ end
243
+
244
+ my_result_transformer = ExperianConsumerView::Transformers::ResultTransformer.new
245
+ my_result_transformer.register_attribute_transformer(CustomAttributeTransformer.new)
246
+
247
+ client = ExperianConsumerView::Client.new(
248
+ user_id: 'YOUR_USER_ID',
249
+ password: 'YOUR_PASSWORD',
250
+ client_id: 'YOUR_CLIENT_ID',
251
+ asset_id: 'YOUR_ASSET_ID',
252
+ options: { result_transformer: my_result_transformer }
253
+ )
254
+
255
+ result = client.lookup(search_items: { "PersonA" => { "email" => "example@example.com" } })
256
+ # result will be something like this (assuming your license gives access to "p_head_of_household"):
257
+ # {
258
+ # "PersonA" => {
259
+ # "p_head_of_household" => 'Head of household',
260
+ # "pc_mosaic_uk_7_group" => 'G',
261
+ # "pc_mosaic_uk_7_type" => '28',
262
+ # "Match" => 'P'
263
+ # }
264
+ # }
265
+ ```
266
+
267
+ #### Using a completely custom result transformer
268
+
269
+ If you want _complete_ control of how the result hash is transformed, you may implement your own result transformer.
270
+
271
+ A result transformer has to provide the `transform` method. This must accept a hash which is the parsed JSON for a _single_ search item, and should return the transformed hash for that search item.
272
+
273
+ A simple example:
274
+
275
+ ```ruby
276
+ class CustomResultTranslator
277
+ # Exact attributes will depend on the Experian license, but input will be something like this...
278
+ # { "pc_mosaic_uk_7_group" => "A", "pc_mosaic_uk_7_type" => "02", "Match" => "PC" }
279
+ def transform(result_hash)
280
+ new_hash = {}
281
+ # Discard the Match attribute, then transform keys from Strings into symbols
282
+ result_hash.select { |k| k != 'Match' }.each { |k,v| new_hash[k.to_sym] = v }
283
+ new_hash
284
+ end
285
+ end
286
+
287
+ client = ExperianConsumerView::Client.new(
288
+ user_id: 'YOUR_USER_ID',
289
+ password: 'YOUR_PASSWORD',
290
+ client_id: 'YOUR_CLIENT_ID',
291
+ asset_id: 'YOUR_ASSET_ID',
292
+ options: { result_transformer: CustomResultTranslator.new }
293
+ )
294
+
295
+ result = client.lookup(search_items: { "MyPostcode" => { "postcode" => "SW1A 0AA" } })
296
+ # result will be something like:
297
+ # { "MyPostcode" => { pc_mosaic_uk_7_group: "A", pc_mosaic_uk_7_type: "03" } }
298
+ ```
299
+
300
+ ## License
301
+
302
+ [MIT License](LICENSE.md)
303
+
304
+ Copyright (c) 2020, 38 Degrees Ltd
305
+
306
+ ## Development
307
+
308
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
309
+
310
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
311
+
312
+ ## Contributing
313
+
314
+ Bug reports and pull requests are welcome on GitHub at https://github.com/38degrees/experian_consumer_view. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
315
+
316
+
317
+ ## Code of Conduct
318
+
319
+ Everyone interacting in the ExperianConsumerView project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).