experian_consumer_view 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExperianConsumerView
4
+ module Transformers
5
+ module Attributes
6
+ # Base mpdule for Attribute Transformers.
7
+ # Mixin to Attribute Transformer classes with +extend ExperianConsumerView::Transformers::Attributes::Base+.
8
+ #
9
+ # Expects the class to provide two constants:
10
+ # - +ATTRIBUTE_NAME+ - the name of the attribute, as returned by the ConsumerView API, which the class can
11
+ # transform.
12
+ # - +CODE_MAP+ - a hash whose keys are all the String codes which the ConsumerView API may return for the
13
+ # attribute in question, and whose values are the what the attribute should be mapped to when the matching
14
+ # code is returned.
15
+ #
16
+ # This module will then provide two class-level methods:
17
+ # - +attribute_name+ - simply returns the value of the +ATTRIBUTE_NAME+ constant.
18
+ # - +transform_attribute+ - transforms the given +value+ based on the +CODE_MAP+, or raises a
19
+ # +AttributeValueUnrecognisedError+ if the value is not foung in the +CODE_MAP+.
20
+ module Base
21
+ def attribute_name
22
+ self::ATTRIBUTE_NAME
23
+ end
24
+
25
+ def transform_attribute(value)
26
+ return self::CODE_MAP[value] if self::CODE_MAP[value]
27
+
28
+ raise ExperianConsumerView::Errors::AttributeValueUnrecognisedError
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module ExperianConsumerView
6
+ module Transformers
7
+ module Attributes
8
+ # An Attribute Transformer to tranform the ConsumerView 'Match' field
9
+ class Match
10
+ extend Base
11
+
12
+ ATTRIBUTE_NAME = 'Match'
13
+
14
+ CODE_MAP = {
15
+ 'PC' => { api_code: 'PC', match_level: 'postcode' },
16
+ 'H' => { api_code: 'H', match_level: 'household' },
17
+ 'P' => { api_code: 'P', match_level: 'person' }
18
+ }.freeze
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated by grabbing all values from the table in the Experian docs, and running this search/replace:
4
+ # ([A-Z0-9]+) ([A-Z0-9]+) (.*)$
5
+ # '$1' => { api_code: '$1', group: '$2', description: '$3' },
6
+
7
+ require_relative 'base'
8
+
9
+ module ExperianConsumerView
10
+ module Transformers
11
+ module Attributes
12
+ # An Attribute Transformer to tranform the ConsumerView 'pc_mosaic_uk_7_group' field
13
+ class PostcodeMosaicUk7Group
14
+ extend Base
15
+
16
+ ATTRIBUTE_NAME = 'pc_mosaic_uk_7_group'
17
+
18
+ CODE_MAP = {
19
+ 'A' => { api_code: 'A', group: 'A', description: 'City Prosperity' },
20
+ 'B' => { api_code: 'B', group: 'B', description: 'Prestige Positions' },
21
+ 'C' => { api_code: 'C', group: 'C', description: 'Country Living' },
22
+ 'D' => { api_code: 'D', group: 'D', description: 'Rural Reality' },
23
+ 'E' => { api_code: 'E', group: 'E', description: 'Senior Security' },
24
+ 'F' => { api_code: 'F', group: 'F', description: 'Suburban Stability' },
25
+ 'G' => { api_code: 'G', group: 'G', description: 'Domestic Success' },
26
+ 'H' => { api_code: 'H', group: 'H', description: 'Aspiring Homemakers' },
27
+ 'I' => { api_code: 'I', group: 'I', description: 'Family Basics' },
28
+ 'J' => { api_code: 'J', group: 'J', description: 'Transient Renters' },
29
+ 'K' => { api_code: 'K', group: 'K', description: 'Municipal Tenants' },
30
+ 'L' => { api_code: 'L', group: 'L', description: 'Vintage Value' },
31
+ 'M' => { api_code: 'M', group: 'M', description: 'Modest Traditions' },
32
+ 'N' => { api_code: 'N', group: 'N', description: 'Urban Cohesion' },
33
+ 'O' => { api_code: 'O', group: 'O', description: 'Rental Hubs' },
34
+ 'U' => { api_code: 'U', group: 'U', description: 'Unclassified' }
35
+ }.freeze
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated by grabbing all values from the table in the Experian docs, and running this search/replace:
4
+ # ([A-Z0-9]+) ([A-Z0-9]+) (.*)$
5
+ # '$1' => { api_code: '$1', type: '$2', description: '$3' },
6
+
7
+ require_relative 'base'
8
+
9
+ module ExperianConsumerView
10
+ module Transformers
11
+ module Attributes
12
+ # An Attribute Transformer to tranform the ConsumerView 'pc_mosaic_uk_7_type' field
13
+ class PostcodeMosaicUk7Type
14
+ extend Base
15
+
16
+ ATTRIBUTE_NAME = 'pc_mosaic_uk_7_type'
17
+
18
+ CODE_MAP = {
19
+ '01' => { api_code: '01', type: 'A01', description: 'World-Class Wealth' },
20
+ '02' => { api_code: '02', type: 'A02', description: 'Uptown Elite' },
21
+ '03' => { api_code: '03', type: 'A03', description: 'Penthouse Chic' },
22
+ '04' => { api_code: '04', type: 'A04', description: 'Metro High-Flyers' },
23
+ '05' => { api_code: '05', type: 'B05', description: 'Premium Fortunes' },
24
+ '06' => { api_code: '06', type: 'B06', description: 'Diamond Days' },
25
+ '07' => { api_code: '07', type: 'B07', description: 'Alpha Families' },
26
+ '08' => { api_code: '08', type: 'B08', description: 'Bank of Mum and Dad' },
27
+ '09' => { api_code: '09', type: 'B09', description: 'Empty-Nest Adventure' },
28
+ '10' => { api_code: '10', type: 'C10', description: 'Wealthy Landowners' },
29
+ '11' => { api_code: '11', type: 'C11', description: 'Rural Vogue' },
30
+ '12' => { api_code: '12', type: 'C12', description: 'Scattered Homesteads' },
31
+ '13' => { api_code: '13', type: 'C13', description: 'Village Retirement' },
32
+ '14' => { api_code: '14', type: 'D14', description: 'Satellite Settlers' },
33
+ '15' => { api_code: '15', type: 'D15', description: 'Local Focus' },
34
+ '16' => { api_code: '16', type: 'D16', description: 'Outlying Seniors' },
35
+ '17' => { api_code: '17', type: 'D17', description: 'Far-Flung Outposts' },
36
+ '18' => { api_code: '18', type: 'E18', description: 'Legacy Elders' },
37
+ '19' => { api_code: '19', type: 'E19', description: 'Bungalow Haven' },
38
+ '20' => { api_code: '20', type: 'E20', description: 'Classic Grandparents' },
39
+ '21' => { api_code: '21', type: 'E21', description: 'Solo Retirees' },
40
+ '22' => { api_code: '22', type: 'F22', description: 'Boomerang Boarders' },
41
+ '23' => { api_code: '23', type: 'F23', description: 'Family Ties' },
42
+ '24' => { api_code: '24', type: 'F24', description: 'Fledgling Free' },
43
+ '25' => { api_code: '25', type: 'F25', description: 'Dependable Me' },
44
+ '26' => { api_code: '26', type: 'G26', description: 'Cafés and Catchments' },
45
+ '27' => { api_code: '27', type: 'G27', description: 'Thriving Independence' },
46
+ '28' => { api_code: '28', type: 'G28', description: 'Modern Parents' },
47
+ '29' => { api_code: '29', type: 'G29', description: 'Mid-Career Convention' },
48
+ '30' => { api_code: '30', type: 'H30', description: 'Primary Ambitions' },
49
+ '31' => { api_code: '31', type: 'H31', description: 'Affordable Fringe' },
50
+ '32' => { api_code: '32', type: 'H32', description: 'First-Rung Futures' },
51
+ '33' => { api_code: '33', type: 'H33', description: 'Contemporary Starts' },
52
+ '34' => { api_code: '34', type: 'H34', description: 'New Foundations' },
53
+ '35' => { api_code: '35', type: 'H35', description: 'Flying Solo' },
54
+ '36' => { api_code: '36', type: 'I36', description: 'Solid Economy' },
55
+ '37' => { api_code: '37', type: 'I37', description: 'Budget Generations' },
56
+ '38' => { api_code: '38', type: 'I38', description: 'Economical Families' },
57
+ '39' => { api_code: '39', type: 'I39', description: 'Families on a Budget' },
58
+ '40' => { api_code: '40', type: 'J40', description: 'Value Rentals' },
59
+ '41' => { api_code: '41', type: 'J41', description: 'Youthful Endeavours' },
60
+ '42' => { api_code: '42', type: 'J42', description: 'Midlife Renters' },
61
+ '43' => { api_code: '43', type: 'J43', description: 'Renting Rooms' },
62
+ '44' => { api_code: '44', type: 'K44', description: 'Inner City Stalwarts' },
63
+ '45' => { api_code: '45', type: 'K45', description: 'City Diversity' },
64
+ '46' => { api_code: '46', type: 'K46', description: 'High Rise Residents' },
65
+ '47' => { api_code: '47', type: 'K47', description: 'Single Essentials' },
66
+ '48' => { api_code: '48', type: 'K48', description: 'Mature Workers' },
67
+ '49' => { api_code: '49', type: 'L49', description: 'Flatlet Seniors' },
68
+ '50' => { api_code: '50', type: 'L50', description: 'Pocket Pensions' },
69
+ '51' => { api_code: '51', type: 'L51', description: 'Retirement Communities' },
70
+ '52' => { api_code: '52', type: 'L52', description: 'Estate Veterans' },
71
+ '53' => { api_code: '53', type: 'L53', description: 'Seasoned Survivors' },
72
+ '54' => { api_code: '54', type: 'M54', description: 'Down-to-Earth Owners' },
73
+ '55' => { api_code: '55', type: 'M55', description: 'Back with the Folks' },
74
+ '56' => { api_code: '56', type: 'M56', description: 'Self Supporters' },
75
+ '57' => { api_code: '57', type: 'N57', description: 'Community Elders' },
76
+ '58' => { api_code: '58', type: 'N58', description: 'Culture & Comfort' },
77
+ '59' => { api_code: '59', type: 'N59', description: 'Large Family Living' },
78
+ '60' => { api_code: '60', type: 'N60', description: 'Ageing Access' },
79
+ '61' => { api_code: '61', type: 'O61', description: 'Career Builders' },
80
+ '62' => { api_code: '62', type: 'O62', description: 'Central Pulse' },
81
+ '63' => { api_code: '63', type: 'O63', description: 'Flexible Workforce' },
82
+ '64' => { api_code: '64', type: 'O64', description: 'Bus-Route Renters' },
83
+ '65' => { api_code: '65', type: 'O65', description: 'Learners & Earners' },
84
+ '66' => { api_code: '66', type: 'O66', description: 'Student Scene' },
85
+ '99' => { api_code: '99', type: 'U', description: 'Unclassified' }
86
+ }.freeze
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExperianConsumerView
4
+ module Transformers
5
+ # Trivial implementation of a result transformer for when the calling code just wants the raw results as returned
6
+ # by the API.
7
+ class NoOpTransformer
8
+ def transform(result_hash)
9
+ result_hash
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # For convinience, ensure all attribute transformers are included, ready to be used as defaults
4
+ Dir[File.join(File.dirname(__FILE__), 'attributes', '*.rb')].sort.each { |file| require file }
5
+
6
+ module ExperianConsumerView
7
+ module Transformers
8
+ # Default implementation of a class to transform the raw result returned by the ConsumerView API into a richer
9
+ # format. It does this by registering one or more attribute transformers, and iterating over the key/value pairs in
10
+ # the result hash, applying the attribute transformers to the appropriate values.
11
+ #
12
+ # You may provide your own custom implementations which transform the result hash in any way you wish. The only
13
+ # requirement is implementing the +transform+ method.
14
+ class ResultTransformer
15
+ def initialize
16
+ @attribute_transformers = {}
17
+ end
18
+
19
+ # Registers an attribute transformer on this +ResultTransformer+.
20
+ #
21
+ # An attribute transformer must implement:
22
+ # - +attribute_name+ - returns the name of an attribute, as returned by the ConsumerView API, which it can
23
+ # transform.
24
+ # - +transform_attribute+ - accepts a value for the given attribute as returned by the ConsumerView API, and
25
+ # transforms it in some way - usually into a richer data format.
26
+ #
27
+ # @param transformer
28
+ def register_attribute_transformer(transformer)
29
+ @attribute_transformers[transformer.attribute_name] = transformer
30
+ end
31
+
32
+ # Transforms all values in the given +result_hash+ using the registered attribute transformers. If there is no
33
+ # attribute transformer for a particular key in the +result_hash+ then the associated value will not be
34
+ # transformed.
35
+ #
36
+ # @param result_hash [Hash] the raw result hash from the ConsumerView API for a single item which was looked up -
37
+ # eg. a single individual, household, or postcode.
38
+ #
39
+ # @returns [Hash] the transformed hash of result data
40
+ def transform(result_hash)
41
+ result_hash.each do |k, v|
42
+ result_hash[k] = @attribute_transformers[k].transform_attribute(v) if @attribute_transformers[k]
43
+ end
44
+ end
45
+
46
+ ################################################
47
+ ### Helper code to get a default Transformer ###
48
+ ################################################
49
+ DEFAULT_ATTRIBUTE_TRANSFORMERS = [
50
+ ExperianConsumerView::Transformers::Attributes::Match,
51
+ ExperianConsumerView::Transformers::Attributes::PostcodeMosaicUk7Group,
52
+ ExperianConsumerView::Transformers::Attributes::PostcodeMosaicUk7Type
53
+ ].freeze
54
+
55
+ # Class instance variable
56
+ @default_transformer = nil
57
+
58
+ def self.default
59
+ unless @default_transformer
60
+ @default_transformer = ResultTransformer.new
61
+
62
+ DEFAULT_ATTRIBUTE_TRANSFORMERS.each { |t| @default_transformer.register_attribute_transformer(t) }
63
+ end
64
+
65
+ @default_transformer
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExperianConsumerView
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: experian_consumer_view
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Sibley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '12.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '12.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.91.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.91.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.25
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.25
153
+ description: "\n Experian's ConsumerView API is a commercially licensed API which
154
+ allows you\n to obtain various demographic data on UK consumers at the postcode,
155
+ household,\n and individual level. This gem provides a simple Ruby wrapper to
156
+ use the API.\n "
157
+ email:
158
+ - andrew.s@38degrees.org.uk
159
+ executables: []
160
+ extensions: []
161
+ extra_rdoc_files: []
162
+ files:
163
+ - ".gitignore"
164
+ - ".rspec"
165
+ - ".rubocop.yml"
166
+ - ".travis.yml"
167
+ - CODE_OF_CONDUCT.md
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - LICENSE.md
171
+ - README.md
172
+ - Rakefile
173
+ - bin/console
174
+ - bin/setup
175
+ - experian_consumer_view.gemspec
176
+ - lib/experian_consumer_view.rb
177
+ - lib/experian_consumer_view/api.rb
178
+ - lib/experian_consumer_view/client.rb
179
+ - lib/experian_consumer_view/constants.rb
180
+ - lib/experian_consumer_view/errors.rb
181
+ - lib/experian_consumer_view/transformers/attributes/base.rb
182
+ - lib/experian_consumer_view/transformers/attributes/match.rb
183
+ - lib/experian_consumer_view/transformers/attributes/postcode_mosaic_uk_7_group.rb
184
+ - lib/experian_consumer_view/transformers/attributes/postcode_mosaic_uk_7_type.rb
185
+ - lib/experian_consumer_view/transformers/no_op_transformer.rb
186
+ - lib/experian_consumer_view/transformers/result_transformer.rb
187
+ - lib/experian_consumer_view/version.rb
188
+ homepage: https://github.com/38degrees/experian_consumer_view
189
+ licenses:
190
+ - MIT
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: 2.3.0
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubygems_version: 3.0.6
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: Ruby wrapper for Experian's ConsumerView API.
211
+ test_files: []