addressfinder 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -20
- data/LICENSE.md +4 -4
- data/README.md +28 -4
- data/addressfinder.gemspec +9 -5
- data/lib/addressfinder/util.rb +6 -5
- data/lib/addressfinder/v1/email/batch_verification.rb +69 -0
- data/lib/addressfinder/v1/email/verification.rb +2 -2
- data/lib/addressfinder/version.rb +1 -1
- data/lib/addressfinder.rb +41 -30
- metadata +52 -43
- data/.github/workflows/ruby.yml +0 -31
- data/.gitignore +0 -11
- data/.travis.yml +0 -6
- data/Dockerfile +0 -28
- data/Gemfile +0 -3
- data/Guardfile +0 -5
- data/Rakefile +0 -7
- data/docker-compose.yml +0 -11
- data/spec/lib/addressfinder/address_autocomplete_spec.rb +0 -95
- data/spec/lib/addressfinder/address_info_spec.rb +0 -62
- data/spec/lib/addressfinder/address_search_spec.rb +0 -76
- data/spec/lib/addressfinder/bulk_spec.rb +0 -207
- data/spec/lib/addressfinder/location_info_spec.rb +0 -79
- data/spec/lib/addressfinder/location_search_spec.rb +0 -93
- data/spec/lib/addressfinder/util_spec.rb +0 -37
- data/spec/lib/addressfinder/v1/email/verification_spec.rb +0 -148
- data/spec/lib/addressfinder/v1/phone/verification_spec.rb +0 -144
- data/spec/lib/addressfinder/v2/au/verification_spec.rb +0 -187
- data/spec/lib/addressfinder/verification_spec.rb +0 -170
- data/spec/lib/addressfinder_spec.rb +0 -94
- data/spec/spec_helper.rb +0 -20
@@ -1,170 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::Verification do
|
4
|
-
before do
|
5
|
-
AddressFinder.configure do |af|
|
6
|
-
af.api_key = 'XXX'
|
7
|
-
af.api_secret = 'YYY'
|
8
|
-
af.default_country = 'nz'
|
9
|
-
af.timeout = 5
|
10
|
-
af.retries = 3
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:verification_module){ AddressFinder::Verification.new(**args) }
|
15
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
16
|
-
let(:net_http){ http.send(:net_http) }
|
17
|
-
|
18
|
-
describe '#execute_request' do
|
19
|
-
let(:args){ {q: "186 Willis Street", http: http} }
|
20
|
-
|
21
|
-
before do
|
22
|
-
WebMock.allow_net_connect!(net_http_connect_on_start: true)
|
23
|
-
allow(http).to receive(:sleep)
|
24
|
-
allow(verification_module).to receive(:request_uri).and_return("/test/path")
|
25
|
-
expect(http).to_not receive(:re_establish_connection)
|
26
|
-
end
|
27
|
-
|
28
|
-
after do
|
29
|
-
WebMock.disable_net_connect!
|
30
|
-
end
|
31
|
-
|
32
|
-
subject(:execute_request){ verification_module.send(:execute_request) }
|
33
|
-
|
34
|
-
it "retries an errored request another time before succeeding" do
|
35
|
-
expect(net_http).to receive(:do_start).twice.and_call_original
|
36
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout)
|
37
|
-
expect(net_http).to receive(:transport_request).once.and_return(double(:response, body: "OK", code: "200"))
|
38
|
-
expect(net_http).to receive(:do_finish).twice.and_call_original
|
39
|
-
execute_request
|
40
|
-
end
|
41
|
-
|
42
|
-
it "re-raises a Net::OpenTimeout error after 3 retries" do
|
43
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
44
|
-
expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::OpenTimeout)
|
45
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
46
|
-
expect{execute_request}.to raise_error(Net::OpenTimeout)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "re-raises a Net::ReadTimeout error after 3 retries" do
|
50
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
51
|
-
expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::ReadTimeout)
|
52
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
53
|
-
expect{execute_request}.to raise_error(Net::ReadTimeout)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "re-raises a SocketError error after 3 retries" do
|
57
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
58
|
-
expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(SocketError)
|
59
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
60
|
-
expect{execute_request}.to raise_error(SocketError)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#build_request' do
|
65
|
-
subject(:request_uri){ verification_module.send(:build_request) }
|
66
|
-
|
67
|
-
context 'with minimal arguments' do
|
68
|
-
let(:args){ {q: '186 willis st', http: http} }
|
69
|
-
|
70
|
-
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'with more arguments' do
|
74
|
-
let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', census: '2013', http: http} }
|
75
|
-
|
76
|
-
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&census=2013&key=XXX&secret=YYY&delivered=true®ion_code=A&format=json') }
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'with a country override' do
|
80
|
-
let(:args){ {q: '186 willis st', country: 'au', http: http} }
|
81
|
-
|
82
|
-
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'with a state codes as an array' do
|
86
|
-
let(:args){ {q: '186 willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
|
87
|
-
|
88
|
-
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
|
89
|
-
end
|
90
|
-
|
91
|
-
context 'with a reserved character in the query' do
|
92
|
-
let(:args){ {q: '186=willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
|
93
|
-
|
94
|
-
it { expect(request_uri).to eq('/api/au/address/verification?q=186%3Dwillis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'with a state codes as a string' do
|
98
|
-
let(:args){ {q: '186 willis st', country: 'au', state_codes: 'ACT,NSW', http: http} }
|
99
|
-
|
100
|
-
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes=ACT%2CNSW&format=json') }
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'with a key override' do
|
104
|
-
let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
|
105
|
-
|
106
|
-
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=AAA&secret=YYY&format=json') }
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'with a secret override' do
|
110
|
-
let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
|
111
|
-
|
112
|
-
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=XXX&secret=BBB&format=json') }
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'with a domain given' do
|
116
|
-
let(:args){ {q: '123', domain: 'testdomain.com', http: http} }
|
117
|
-
|
118
|
-
it { expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=testdomain.com&key=XXX&secret=YYY&format=json') }
|
119
|
-
|
120
|
-
context 'given in the AF configuration' do
|
121
|
-
|
122
|
-
let(:args){ {q: '123', http: http} }
|
123
|
-
|
124
|
-
it 'should use the config domain if set' do
|
125
|
-
AddressFinder.configuration.domain = 'anotherdomain.com'
|
126
|
-
expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=anotherdomain.com&key=XXX&secret=YYY&format=json')
|
127
|
-
AddressFinder.configuration.domain = nil # set back to nil after
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe '#build_result' do
|
134
|
-
let(:args){ {q: 'ignored', http: nil} }
|
135
|
-
|
136
|
-
before do
|
137
|
-
verification_module.send('response_body=', body)
|
138
|
-
verification_module.send('response_status=', status)
|
139
|
-
end
|
140
|
-
|
141
|
-
subject(:result){ verification_module.send(:build_result) }
|
142
|
-
|
143
|
-
context 'with a successful nz result' do
|
144
|
-
let(:body){ '{"matched": true, "postal_address": "Texas"}' }
|
145
|
-
let(:status){ '200' }
|
146
|
-
|
147
|
-
it { expect(result.class).to eq(AddressFinder::Verification::Result) }
|
148
|
-
|
149
|
-
it { expect(result.matched).to eq(true) }
|
150
|
-
|
151
|
-
it { expect(result.postal_address).to eq("Texas") }
|
152
|
-
end
|
153
|
-
|
154
|
-
context 'with a successful au result' do
|
155
|
-
let(:body){ %Q({"matched": true, "success": true, "address": {"full_address": "Texas"}}) }
|
156
|
-
let(:status){ '200' }
|
157
|
-
|
158
|
-
it { expect(result.class).to eq(AddressFinder::Verification::Result) }
|
159
|
-
|
160
|
-
it { expect(result.full_address).to eq("Texas") }
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'with an unfound result' do
|
164
|
-
let(:body){ '{"matched": false}' }
|
165
|
-
let(:status){ '200' }
|
166
|
-
|
167
|
-
it { expect(result).to eq(nil) }
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
RSpec.describe AddressFinder do
|
5
|
-
before do
|
6
|
-
AddressFinder.configure do |af|
|
7
|
-
af.api_key = 'XXX'
|
8
|
-
af.api_secret = 'YYY'
|
9
|
-
af.default_country = 'nz'
|
10
|
-
af.timeout = 5
|
11
|
-
af.retries = 5
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#verification with verification_version configured to "v2"' do
|
16
|
-
before do
|
17
|
-
AddressFinder.configuration.verification_version = "v2"
|
18
|
-
end
|
19
|
-
|
20
|
-
after do
|
21
|
-
AddressFinder.configuration.verification_version = nil # set back to nil after
|
22
|
-
end
|
23
|
-
|
24
|
-
subject(:verification){ AddressFinder.verification(args) }
|
25
|
-
|
26
|
-
context "with country set to nz" do
|
27
|
-
let(:args){ {country: "nz", q: "12 high street sydney"} }
|
28
|
-
it "calls the old class" do
|
29
|
-
expect(AddressFinder::Verification).to receive_message_chain(:new, :perform, :result)
|
30
|
-
subject
|
31
|
-
end
|
32
|
-
|
33
|
-
it "safely passes arguments through" do
|
34
|
-
stub_request(:get, Addressable::Template.new("https://api.addressfinder.io/api/nz/address/verification{?args*}")).to_return(:status => 200, :body => "{}", :headers => {})
|
35
|
-
subject
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with country set to au" do
|
40
|
-
let(:args){ {country: "au", q: "12 high street sydney"} }
|
41
|
-
it "calls the v2::Au class" do
|
42
|
-
expect(AddressFinder::V2::Au::Verification).to receive_message_chain(:new, :perform, :result)
|
43
|
-
subject
|
44
|
-
end
|
45
|
-
|
46
|
-
it "safely passes arguments through" do
|
47
|
-
stub_request(:get, Addressable::Template.new("https://api.addressfinder.io/api/au/address/v2/verification{?args*}")).to_return(:status => 200, :body => "{}", :headers => {})
|
48
|
-
subject
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#verification with verification_version not configured' do
|
54
|
-
subject(:verification){ AddressFinder.verification(args) }
|
55
|
-
|
56
|
-
context "with country set to nz" do
|
57
|
-
let(:args){ {country: "nz", q: "12 high street sydney"} }
|
58
|
-
|
59
|
-
it "calls the old class" do
|
60
|
-
expect(AddressFinder::Verification).to receive_message_chain(:new, :perform, :result)
|
61
|
-
subject
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "with country set to au" do
|
66
|
-
let(:args){ {country: "au", q: "12 high street sydney"} }
|
67
|
-
|
68
|
-
it "calls the old class" do
|
69
|
-
expect(AddressFinder::Verification).to receive_message_chain(:new, :perform, :result)
|
70
|
-
subject
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "#email_verification" do
|
76
|
-
subject(:verification) { AddressFinder.email_verification(args) }
|
77
|
-
let(:args){ {email: "john.doe@addressfinder.com"} }
|
78
|
-
|
79
|
-
it "calls the email verification class" do
|
80
|
-
expect(AddressFinder::V1::Email::Verification).to receive_message_chain(:new, :perform, :result)
|
81
|
-
subject
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "#phone_verification" do
|
86
|
-
subject(:verification) { AddressFinder.phone_verification(args) }
|
87
|
-
let(:args){ {phone_number: "1800 152 363", default_country_code: "AU"} }
|
88
|
-
|
89
|
-
it "calls the phone verification class" do
|
90
|
-
expect(AddressFinder::V1::Phone::Verification).to receive_message_chain(:new, :perform, :result)
|
91
|
-
subject
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
-
# loaded once.
|
5
|
-
#
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'bundler'
|
10
|
-
require 'webmock/rspec'
|
11
|
-
require 'addressfinder'
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.mock_with :rspec
|
15
|
-
|
16
|
-
config.filter_run :focus => true
|
17
|
-
config.run_all_when_everything_filtered = true
|
18
|
-
end
|
19
|
-
|
20
|
-
WebMock.disable_net_connect!
|