experian_address_validation 0.1.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.
- checksums.yaml +7 -0
- data/.env.example +3 -0
- data/.github/workflows/main.yml +19 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +150 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/experian_address_validation.gemspec +35 -0
- data/lib/errors/response_error.rb +25 -0
- data/lib/experian_address_validation.rb +15 -0
- data/lib/experian_address_validation/client.rb +16 -0
- data/lib/experian_address_validation/config.rb +7 -0
- data/lib/experian_address_validation/operation.rb +70 -0
- data/lib/experian_address_validation/operations/format.rb +33 -0
- data/lib/experian_address_validation/operations/search.rb +27 -0
- data/lib/experian_address_validation/version.rb +5 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: db9326171baa631da865cafefcbc1167026a227ccfef5b714039968f1605311a
|
4
|
+
data.tar.gz: 2b118f5588a8da48e0fd67dc012bd20edd4538fb2cee02efef61ba277dc92874
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 305fda03addd844062c54bcd7baa7a61e16482c6d4c190940f682dc22bc733f7a5ac7a62f96ef6a2fe07d6595f6d4d933614c9ad2b54cb4a2b1733cc661ff25e
|
7
|
+
data.tar.gz: d40bd0c95d6d6870ffdd25bd41b3b7072f26f705a1c79deaccf0846689dcf074e4b8540b46f2ebbb78489f568dddb6c18b0bb52a64899066b2c58ed1f926ebb9
|
data/.env.example
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: actions/setup-ruby@v1.1.2
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Build and run Rspec
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.4
|
17
|
+
bundle install
|
18
|
+
bundle exec rspec spec
|
19
|
+
bundle exec rubocop
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
Enabled: true
|
3
|
+
EnforcedStyle: double_quotes
|
4
|
+
|
5
|
+
Style/StringLiteralsInInterpolation:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Naming/VariableNumber:
|
13
|
+
CheckSymbols: false
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Enabled: false
|
17
|
+
# IgnoredMethods: ['context', 'describe', 'shared_examples_for']
|
18
|
+
|
19
|
+
Layout/LineLength:
|
20
|
+
Max: 120
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ajaz.farhad19@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
experian_address_validation (0.1.0)
|
5
|
+
faraday
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
dotenv (2.7.6)
|
17
|
+
faraday (1.3.0)
|
18
|
+
faraday-net_http (~> 1.0)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
ruby2_keywords
|
21
|
+
faraday-net_http (1.0.1)
|
22
|
+
hashdiff (1.0.1)
|
23
|
+
multipart-post (2.1.1)
|
24
|
+
parallel (1.20.1)
|
25
|
+
parser (3.0.0.0)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
public_suffix (4.0.6)
|
28
|
+
rainbow (3.0.0)
|
29
|
+
rake (13.0.3)
|
30
|
+
regexp_parser (2.1.1)
|
31
|
+
rexml (3.2.4)
|
32
|
+
rspec (3.10.0)
|
33
|
+
rspec-core (~> 3.10.0)
|
34
|
+
rspec-expectations (~> 3.10.0)
|
35
|
+
rspec-mocks (~> 3.10.0)
|
36
|
+
rspec-core (3.10.1)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-expectations (3.10.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-mocks (3.10.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-support (3.10.2)
|
45
|
+
rubocop (0.93.1)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 2.7.1.5)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 0.6.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
54
|
+
rubocop-ast (1.4.1)
|
55
|
+
parser (>= 2.7.1.5)
|
56
|
+
ruby-progressbar (1.11.0)
|
57
|
+
ruby2_keywords (0.0.4)
|
58
|
+
unicode-display_width (1.7.0)
|
59
|
+
vcr (6.0.0)
|
60
|
+
webmock (3.12.0)
|
61
|
+
addressable (>= 2.3.6)
|
62
|
+
crack (>= 0.3.2)
|
63
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
x86_64-darwin-19
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
dotenv
|
70
|
+
experian_address_validation!
|
71
|
+
rake (~> 13.0)
|
72
|
+
rspec (~> 3.0)
|
73
|
+
rubocop (~> 0.80)
|
74
|
+
vcr
|
75
|
+
webmock
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.2.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 ajazfarhad
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
# Experian Address Validation
|
2
|
+
Ruby wrapper for Experian Address Validation REST API
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'experian_address_validation'
|
9
|
+
```
|
10
|
+
And then execute:
|
11
|
+
|
12
|
+
$ bundle
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
```ruby
|
16
|
+
$ gem install experian_address_validation
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
------
|
21
|
+
## Configure client
|
22
|
+
**For using this Gem in a Rails app. Add the following code as an initializer**
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
ExperianAddressValidation::Client do |config|
|
26
|
+
config.auth_token = ENV["AUTH_TOKEN"]
|
27
|
+
config.base_url = ENV["BASE_URL"]
|
28
|
+
config.iso_code = ENV["ISO_CODE"]
|
29
|
+
end
|
30
|
+
```
|
31
|
+
**You can provide default ``iso_code`` through a config variable or you can send as a payload option to search endpoint.**
|
32
|
+
|
33
|
+
## Experian Address Validation API Reference
|
34
|
+
https://www.edq.com/documentation/apis-r/address-validate/experian-address-validation/#/AddressFormat/Get
|
35
|
+
|
36
|
+
# Endpoints
|
37
|
+
---
|
38
|
+
|
39
|
+
### Search Address
|
40
|
+
------
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
ExperianAddressValidation::Operations::Search.new(payload: {
|
44
|
+
query: 'BN1 2NW', country_iso: 'GBR'}
|
45
|
+
}).execute
|
46
|
+
```
|
47
|
+
The call to above operation will return response in the following structure.
|
48
|
+
|
49
|
+
``body`` - containing hash with the following data
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
{
|
53
|
+
result: {
|
54
|
+
more_results_available: true,
|
55
|
+
confidence: "Verified match",
|
56
|
+
suggestions: [
|
57
|
+
{
|
58
|
+
global_address_key: "aWQ9ZWUwMzhjYzAtY2IxZi00MDRiLTTlfVTQwXzI0XzBfMF8",
|
59
|
+
text: "Mail Boxes Etc, 91 Western Road, Brighton, BN1 2NW",
|
60
|
+
format: "https://localhost/capture/address/v3/format/aWQ9ZWUwMzhjYzAtY2IxZi00MDRiLTTlfVTQwXzI0XzBfMF8"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}
|
64
|
+
}
|
65
|
+
```
|
66
|
+
``code`` - Status code e.g ``200``
|
67
|
+
|
68
|
+
Address Search endpoint:
|
69
|
+
https://api.experianaperture.io/address/search/v1
|
70
|
+
|
71
|
+
### Format Address
|
72
|
+
------
|
73
|
+
|
74
|
+
``` ruby
|
75
|
+
ExperianAddressValidation::Operations::Format.new({
|
76
|
+
global_address_key: 'aWQ9ZWUwMzhjYzAtY2IxZi00MDRiL...'
|
77
|
+
}).execute
|
78
|
+
```
|
79
|
+
``Add-Metadata`` and ``Add-Components`` headers are default set to ``true`` in ``Format`` call.
|
80
|
+
However you can override them by passing ``headers`` hash as an option to the ``Format`` endpoint.
|
81
|
+
|
82
|
+
``` ruby
|
83
|
+
headers: { Add-Metadata: false, Add-Components: false }
|
84
|
+
```
|
85
|
+
|
86
|
+
``code`` - Status code e.g ``200``
|
87
|
+
|
88
|
+
The call to above operation will return response in the following structure.
|
89
|
+
|
90
|
+
``` ruby
|
91
|
+
{
|
92
|
+
result: {
|
93
|
+
global_address_key: "aWQ9ZWUwMzhjYzAtY2IxZi00MDRiL...",
|
94
|
+
confidence: "Verified match",
|
95
|
+
address: {
|
96
|
+
address_line_1: "Mail Boxes Etc",
|
97
|
+
address_line_2: "91 Western Road",
|
98
|
+
address_line_3: "",
|
99
|
+
locality: "BRIGHTON",
|
100
|
+
region: "",
|
101
|
+
postal_code: "BN1 2NW",
|
102
|
+
country: "UNITED KINGDOM"
|
103
|
+
},
|
104
|
+
components: {
|
105
|
+
language: "en-GB",
|
106
|
+
country_name: "United Kingdom",
|
107
|
+
country_iso_3: "GBR",
|
108
|
+
postal_code: {
|
109
|
+
full_name: "BN1 2NW",
|
110
|
+
primary: "BN1 2NW"
|
111
|
+
},
|
112
|
+
building: {
|
113
|
+
building_number: "91"
|
114
|
+
},
|
115
|
+
organization: {
|
116
|
+
company_name: "Mail Boxes Etc"
|
117
|
+
},
|
118
|
+
street: {
|
119
|
+
full_name: "Western Road",
|
120
|
+
name: "Western",
|
121
|
+
type: "Road"
|
122
|
+
},
|
123
|
+
locality: {
|
124
|
+
town: {
|
125
|
+
name: "Brighton"
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
},
|
130
|
+
"metadata": {
|
131
|
+
"address_info": {
|
132
|
+
"identifier": {
|
133
|
+
"udprn": "123123"
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
Address Format endpoint:
|
141
|
+
https://api.experianaperture.io/address/format/v1/#{global_address_key}
|
142
|
+
|
143
|
+
## Running specs
|
144
|
+
|
145
|
+
To run the specs, add your development credentials to your dev env.test file:
|
146
|
+
```
|
147
|
+
BASE_URL=https://api.experianaperture.io
|
148
|
+
AUTH_TOKEN=<api_token>
|
149
|
+
ISO_CODE=GBR
|
150
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "experian_address_validation"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/experian_address_validation/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "experian_address_validation"
|
7
|
+
spec.version = ExperianAddressValidation::VERSION
|
8
|
+
spec.authors = ["ajazfarhad"]
|
9
|
+
spec.email = ["ajaz.farhad19@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby wrapper for Experian Address Validation API"
|
12
|
+
spec.homepage = "https://github.com/ajazfarhad/experian_address_validation"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency "faraday"
|
28
|
+
|
29
|
+
spec.add_development_dependency "dotenv"
|
30
|
+
spec.add_development_dependency "vcr"
|
31
|
+
spec.add_development_dependency "webmock"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExperianAddressValidation
|
4
|
+
module Errors
|
5
|
+
class ResponseError < StandardError
|
6
|
+
attr_reader :status, :body
|
7
|
+
|
8
|
+
def initialize(status:, body:)
|
9
|
+
@status = status
|
10
|
+
@body = body
|
11
|
+
|
12
|
+
super(build_message)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_message
|
18
|
+
return status unless body.is_a?(String)
|
19
|
+
|
20
|
+
parsed_body = JSON.parse(body)
|
21
|
+
parsed_body["error"] || body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "faraday"
|
5
|
+
|
6
|
+
require_relative "experian_address_validation/version"
|
7
|
+
require_relative "experian_address_validation/config"
|
8
|
+
require_relative "experian_address_validation/client"
|
9
|
+
require_relative "experian_address_validation/operation"
|
10
|
+
require_relative "experian_address_validation/operations/search"
|
11
|
+
require_relative "experian_address_validation/operations/format"
|
12
|
+
require_relative "errors/response_error"
|
13
|
+
|
14
|
+
module ExperianAddressValidation
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExperianAddressValidation
|
4
|
+
class Client
|
5
|
+
class << self
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def configure
|
9
|
+
raise ArgumentError, "block not given" unless block_given?
|
10
|
+
|
11
|
+
@config = Config.new
|
12
|
+
yield config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExperianAddressValidation
|
4
|
+
# Base class for API operations
|
5
|
+
class Operation
|
6
|
+
DEFAULT_HEADERS = {
|
7
|
+
content_type: "application/json"
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
http_client.headers["Auth-Token"] = auth_token
|
16
|
+
|
17
|
+
response = http_client.run_request(http_method, endpoint, json_payload, headers)
|
18
|
+
|
19
|
+
return json_response(response) if response.success?
|
20
|
+
|
21
|
+
raise ExperianAddressValidation::Errors::ResponseError.new(body: response.body, status: response.status)
|
22
|
+
end
|
23
|
+
|
24
|
+
def http_method
|
25
|
+
:post
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :options
|
31
|
+
|
32
|
+
def http_client
|
33
|
+
@http_client ||= Faraday.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def json_response(response)
|
37
|
+
JSON.parse(response.body, symbolize_names: true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def json_payload
|
41
|
+
@json_payload ||= JSON.generate(payload)
|
42
|
+
end
|
43
|
+
|
44
|
+
def payload
|
45
|
+
options[:payload]
|
46
|
+
end
|
47
|
+
|
48
|
+
def base_url
|
49
|
+
config.base_url
|
50
|
+
end
|
51
|
+
|
52
|
+
def headers
|
53
|
+
DEFAULT_HEADERS.merge(options.fetch(:headers, {}))
|
54
|
+
end
|
55
|
+
|
56
|
+
def auth_token
|
57
|
+
config.auth_token
|
58
|
+
end
|
59
|
+
|
60
|
+
def config
|
61
|
+
Client.config
|
62
|
+
end
|
63
|
+
|
64
|
+
def default_iso_code
|
65
|
+
config.iso_code
|
66
|
+
end
|
67
|
+
|
68
|
+
def endpoint; end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# GET {{ base_url }}/address/format/v1/{global_address_key}
|
4
|
+
module ExperianAddressValidation
|
5
|
+
module Operations
|
6
|
+
# Handles address formatting
|
7
|
+
class Format < Operation
|
8
|
+
FORMAT_HEADERS = {
|
9
|
+
"Add-Metadata": "true",
|
10
|
+
"Add-Components": "true"
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def endpoint
|
16
|
+
"#{base_url}/address/format/v1/#{global_address_key}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def global_address_key
|
20
|
+
options[:global_address_key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_method
|
24
|
+
:get
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
option_headers = options.fetch(:headers, {})
|
29
|
+
DEFAULT_HEADERS.merge(**FORMAT_HEADERS, **option_headers)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# POST {{ base_url }}/address/search/v1
|
4
|
+
module ExperianAddressValidation
|
5
|
+
module Operations
|
6
|
+
# Handles address search operataion
|
7
|
+
class Search < Operation
|
8
|
+
private
|
9
|
+
|
10
|
+
def endpoint
|
11
|
+
"#{base_url}/address/search/v1"
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload
|
15
|
+
data = options[:payload]
|
16
|
+
{
|
17
|
+
country_iso: default_iso_code || data[:iso_code],
|
18
|
+
components: {
|
19
|
+
unspecified: [data[:query]]
|
20
|
+
},
|
21
|
+
location: data[:location],
|
22
|
+
dataset: data[:dataset]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: experian_address_validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ajazfarhad
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- ajaz.farhad19@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".env.example"
|
77
|
+
- ".github/workflows/main.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- experian_address_validation.gemspec
|
90
|
+
- lib/errors/response_error.rb
|
91
|
+
- lib/experian_address_validation.rb
|
92
|
+
- lib/experian_address_validation/client.rb
|
93
|
+
- lib/experian_address_validation/config.rb
|
94
|
+
- lib/experian_address_validation/operation.rb
|
95
|
+
- lib/experian_address_validation/operations/format.rb
|
96
|
+
- lib/experian_address_validation/operations/search.rb
|
97
|
+
- lib/experian_address_validation/version.rb
|
98
|
+
homepage: https://github.com/ajazfarhad/experian_address_validation
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata:
|
102
|
+
homepage_uri: https://github.com/ajazfarhad/experian_address_validation
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.4'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubygems_version: 3.2.3
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Ruby wrapper for Experian Address Validation API
|
122
|
+
test_files: []
|