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
data/.github/workflows/ruby.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
name: Ruby
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ "master" ]
|
6
|
-
pull_request:
|
7
|
-
branches: [ "master" ]
|
8
|
-
|
9
|
-
permissions:
|
10
|
-
contents: read
|
11
|
-
|
12
|
-
jobs:
|
13
|
-
test:
|
14
|
-
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
strategy:
|
17
|
-
matrix:
|
18
|
-
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
19
|
-
|
20
|
-
steps:
|
21
|
-
- uses: actions/checkout@v3
|
22
|
-
- name: Set up Ruby
|
23
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
24
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
25
|
-
# uses: ruby/setup-ruby@v1
|
26
|
-
uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
|
27
|
-
with:
|
28
|
-
ruby-version: ${{ matrix.ruby-version }}
|
29
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
30
|
-
- name: Run tests
|
31
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Dockerfile
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# Use the barebones version of Ruby 2.7.x
|
2
|
-
FROM ruby:2.7
|
3
|
-
|
4
|
-
# Install dependencies:
|
5
|
-
# - build-essential: To ensure certain gems can be compiled
|
6
|
-
# - nodejs: Compile assets
|
7
|
-
# - bundler: ensure most recent version is installed
|
8
|
-
RUN apt-get update && apt-get install -qq -y build-essential --fix-missing --no-install-recommends
|
9
|
-
RUN gem install bundler
|
10
|
-
|
11
|
-
# Set an environment variable to store where the app is installed to inside
|
12
|
-
# of the Docker image.
|
13
|
-
ENV LANG C.UTF-8
|
14
|
-
ENV BUNDLE_PATH /bundle
|
15
|
-
ENV INSTALL_PATH /addressfinder-ruby
|
16
|
-
RUN mkdir -p $INSTALL_PATH
|
17
|
-
|
18
|
-
# Create address verification directories
|
19
|
-
RUN mkdir -p $INSTALL_PATH/verification/originals
|
20
|
-
RUN mkdir -p $INSTALL_PATH/verification/verified
|
21
|
-
|
22
|
-
# This sets the context of where commands will be ran in and is documented
|
23
|
-
# on Docker's website extensively.
|
24
|
-
WORKDIR $INSTALL_PATH
|
25
|
-
|
26
|
-
ADD . $INSTALL_PATH
|
27
|
-
|
28
|
-
RUN bundle install
|
data/Gemfile
DELETED
data/Guardfile
DELETED
data/Rakefile
DELETED
data/docker-compose.yml
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::AddressAutocomplete do
|
4
|
-
before do
|
5
|
-
AddressFinder.configure do |af|
|
6
|
-
af.api_key = 'XXX'
|
7
|
-
af.api_secret = 'YYY'
|
8
|
-
af.default_country = 'au'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#build_request' do
|
13
|
-
let(:locator){ AddressFinder::AddressAutocomplete.new(params: args, http: http) }
|
14
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
15
|
-
|
16
|
-
subject(:request_uri){ locator.send(:build_request) }
|
17
|
-
|
18
|
-
context 'with minimal arguments' do
|
19
|
-
let(:args){ {q: '186 willis'} }
|
20
|
-
|
21
|
-
it { expect(request_uri).to eq('/api/au/address/autocomplete.json?q=186+willis&key=XXX&secret=YYY') }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with more arguments' do
|
25
|
-
let(:args){ {q: '186 willis st', au_paf: 1, max: 10} }
|
26
|
-
|
27
|
-
it { expect(request_uri).to eq('/api/au/address/autocomplete.json?q=186+willis+st&au_paf=1&max=10&key=XXX&secret=YYY') }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with a country override' do
|
31
|
-
let(:args){ {q: '186 willis st', country: 'au'} }
|
32
|
-
|
33
|
-
it { expect(request_uri).to eq('/api/au/address/autocomplete.json?q=186+willis+st&key=XXX&secret=YYY') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with a key override' do
|
37
|
-
let(:args){ {q: '186 willis st', key: 'AAA'} }
|
38
|
-
|
39
|
-
it { expect(request_uri).to eq('/api/au/address/autocomplete.json?q=186+willis+st&key=AAA&secret=YYY') }
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with a secret override' do
|
43
|
-
let(:args){ {q: '186 willis st', secret: 'BBB'} }
|
44
|
-
|
45
|
-
it { expect(request_uri).to eq('/api/au/address/autocomplete.json?q=186+willis+st&secret=BBB&key=XXX') }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#validate_params' do
|
50
|
-
let(:locator){ AddressFinder::AddressAutocomplete.new(params: args, http: http) }
|
51
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
52
|
-
|
53
|
-
subject(:validate_params){ locator.send(:validate_params) }
|
54
|
-
|
55
|
-
context 'with wrong country' do
|
56
|
-
let(:args){ {q: '186 willis st', country: 'nz'} }
|
57
|
-
|
58
|
-
it { expect{validate_params}.to raise_error(AddressFinder::RequestRejectedError) }
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with correct country' do
|
62
|
-
let(:args){ {q: '186 willis st', country: 'au'} }
|
63
|
-
|
64
|
-
it { expect{validate_params}.not_to raise_error }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#build_result' do
|
69
|
-
let(:locator){ AddressFinder::AddressSearch.new(params: {q: 'ignored'}, http: nil) }
|
70
|
-
|
71
|
-
before do
|
72
|
-
locator.send('response_body=', body)
|
73
|
-
locator.send('response_status=', status)
|
74
|
-
locator.send(:build_result)
|
75
|
-
end
|
76
|
-
|
77
|
-
subject(:results){ locator.results }
|
78
|
-
|
79
|
-
context 'with completions' do
|
80
|
-
let(:body){ '{"completions":[{"a":"184 William Jones Drive, Otangarei, Whangarei 0112","pxid":"2-.9.2U.F.F.2I","v":1},{"a":"184 Williams Street, Kaiapoi 7630","pxid":"2-.3.1q.2.4G.4c","v":0},{"a":"184 Willis Street, Te Aro, Wellington 6011","pxid":"2-.F.1W.p.1D.1W","v":0}],"paid":true}' }
|
81
|
-
let(:status){ '200' }
|
82
|
-
|
83
|
-
it { expect(results.size).to eq(3) }
|
84
|
-
it { expect(results.first.class).to eq(AddressFinder::AddressSearch::Result) }
|
85
|
-
it { expect(results.first.a).to eq("184 William Jones Drive, Otangarei, Whangarei 0112") }
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'with no completions' do
|
89
|
-
let(:body){ '{"completions":[],"paid":true}' }
|
90
|
-
let(:status){ '200' }
|
91
|
-
|
92
|
-
it { expect(results).to eq([]) }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::AddressInfo do
|
4
|
-
before do
|
5
|
-
AddressFinder.configure do |af|
|
6
|
-
af.api_key = 'XXX'
|
7
|
-
af.api_secret = 'YYY'
|
8
|
-
af.default_country = 'au'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#build_request' do
|
13
|
-
let(:locator){ AddressFinder::AddressInfo.new(params: args, http: http) }
|
14
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
15
|
-
|
16
|
-
subject(:request_uri){ locator.send(:build_request) }
|
17
|
-
|
18
|
-
context 'with a simple PXID' do
|
19
|
-
let(:args){ {pxid: '123'} }
|
20
|
-
|
21
|
-
it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&key=XXX&secret=YYY') }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a country override' do
|
25
|
-
let(:args){ {pxid: '123', country: 'nz'} }
|
26
|
-
|
27
|
-
it { expect(request_uri).to eq('/api/nz/address/info.json?pxid=123&key=XXX&secret=YYY') }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with a key override' do
|
31
|
-
let(:args){ {pxid: '123', key:'AAA'} }
|
32
|
-
|
33
|
-
it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&key=AAA&secret=YYY') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with a secret override' do
|
37
|
-
let(:args){ {pxid: '123', secret: 'BBB'} }
|
38
|
-
|
39
|
-
it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&secret=BBB&key=XXX') }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#build_result' do
|
44
|
-
let(:locator){ AddressFinder::AddressInfo.new(params: {q: 'ignored'}, http: nil) }
|
45
|
-
|
46
|
-
before do
|
47
|
-
locator.send('response_body=', body)
|
48
|
-
locator.send('response_status=', status)
|
49
|
-
end
|
50
|
-
|
51
|
-
subject(:result){ locator.send(:build_result) }
|
52
|
-
|
53
|
-
context 'with a successful result' do
|
54
|
-
let(:body){ '{"pxid":"2-.9.2U.F.F.2I","number":"184","container_only":"false","x":"174.314855382547","y":"-35.6946659390092","postcode":"0112","a":"184 William Jones Drive, Otangarei, Whangarei 0112","postal":"184 William Jones Drive, Otangarei, Whangarei 0112","mailtown":"Whangarei","post_suburb":"Otangarei","ta":"Whangarei District","sufi":932755,"street_type":"drive","city":"Whangarei","suburb":"Otangarei","region":"Northland Region","street":"William Jones Drive","postal_line_1":"184 William Jones Drive","postal_line_2":"Otangarei","postal_line_3":"Whangarei 0112","meshblock":"93700","dpid":"681856"}' }
|
55
|
-
let(:status){ '200' }
|
56
|
-
|
57
|
-
it { expect(result.class).to eq(AddressFinder::AddressInfo::Result) }
|
58
|
-
it { expect(result.a).to eq("184 William Jones Drive, Otangarei, Whangarei 0112") }
|
59
|
-
it { expect(result.pxid).to eq("2-.9.2U.F.F.2I") }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::AddressSearch 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
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#build_request' do
|
13
|
-
let(:locator){ AddressFinder::AddressSearch.new(params: args, http: http) }
|
14
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
15
|
-
|
16
|
-
subject(:request_uri){ locator.send(:build_request) }
|
17
|
-
|
18
|
-
context 'with minimal arguments' do
|
19
|
-
let(:args){ {q: '186 willis'} }
|
20
|
-
|
21
|
-
it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis&key=XXX&secret=YYY') }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with more arguments' do
|
25
|
-
let(:args){ {q: '186 willis st', delivered: 1, max: 10} }
|
26
|
-
|
27
|
-
it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&delivered=1&max=10&key=XXX&secret=YYY') }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with a country override' do
|
31
|
-
let(:args){ {q: '186 willis st', country: 'au'} }
|
32
|
-
|
33
|
-
it { expect(request_uri).to eq('/api/au/address.json?q=186+willis+st&key=XXX&secret=YYY') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with a key override' do
|
37
|
-
let(:args){ {q: '186 willis st', key: 'AAA'} }
|
38
|
-
|
39
|
-
it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&key=AAA&secret=YYY') }
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with a secret override' do
|
43
|
-
let(:args){ {q: '186 willis st', secret: 'BBB'} }
|
44
|
-
|
45
|
-
it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&secret=BBB&key=XXX') }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#build_result' do
|
50
|
-
let(:locator){ AddressFinder::AddressSearch.new(params: {q: 'ignored'}, http: nil) }
|
51
|
-
|
52
|
-
before do
|
53
|
-
locator.send('response_body=', body)
|
54
|
-
locator.send('response_status=', status)
|
55
|
-
locator.send(:build_result)
|
56
|
-
end
|
57
|
-
|
58
|
-
subject(:results){ locator.results }
|
59
|
-
|
60
|
-
context 'with completions' do
|
61
|
-
let(:body){ '{"completions":[{"a":"184 William Jones Drive, Otangarei, Whangarei 0112","pxid":"2-.9.2U.F.F.2I","v":1},{"a":"184 Williams Street, Kaiapoi 7630","pxid":"2-.3.1q.2.4G.4c","v":0},{"a":"184 Willis Street, Te Aro, Wellington 6011","pxid":"2-.F.1W.p.1D.1W","v":0}],"paid":true}' }
|
62
|
-
let(:status){ '200' }
|
63
|
-
|
64
|
-
it { expect(results.size).to eq(3) }
|
65
|
-
it { expect(results.first.class).to eq(AddressFinder::AddressSearch::Result) }
|
66
|
-
it { expect(results.first.a).to eq("184 William Jones Drive, Otangarei, Whangarei 0112") }
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with no completions' do
|
70
|
-
let(:body){ '{"completions":[],"paid":true}' }
|
71
|
-
let(:status){ '200' }
|
72
|
-
|
73
|
-
it { expect(results).to eq([]) }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::Bulk 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 = 5
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#perform' do
|
15
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
16
|
-
let(:net_http){ http.send(:net_http) }
|
17
|
-
|
18
|
-
before do
|
19
|
-
WebMock.allow_net_connect!(net_http_connect_on_start: true)
|
20
|
-
allow(http).to receive(:sleep)
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
WebMock.disable_net_connect!
|
25
|
-
end
|
26
|
-
|
27
|
-
context "with 3 requests in the provided block" do
|
28
|
-
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
29
|
-
let(:block){
|
30
|
-
Proc.new do |proxy|
|
31
|
-
proxy.verification(q: "1 Willis")
|
32
|
-
proxy.verification(q: "2 Willis")
|
33
|
-
proxy.verification(q: "3 Willis")
|
34
|
-
end
|
35
|
-
}
|
36
|
-
|
37
|
-
it "uses 1 http connection" do
|
38
|
-
expect(net_http).to receive(:do_start).once.and_call_original
|
39
|
-
expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
40
|
-
expect(net_http).to receive(:do_finish).once.and_call_original
|
41
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
|
42
|
-
end
|
43
|
-
|
44
|
-
it "calls the correct class with v2 verification and au default" do
|
45
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
46
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
47
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
48
|
-
expect(AddressFinder::V2::Au::Verification).to receive(:new).exactly(3).times.and_call_original
|
49
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
|
50
|
-
end
|
51
|
-
|
52
|
-
it "calls the correct class with v2 verification and nz default" do
|
53
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
54
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
55
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
56
|
-
expect(AddressFinder::Verification).to receive(:new).exactly(3).times.and_call_original
|
57
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'nz', &block).perform
|
58
|
-
end
|
59
|
-
|
60
|
-
it "calls the correct class without a verification version" do
|
61
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
62
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
63
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
64
|
-
expect(AddressFinder::Verification).to receive(:new).exactly(3).times.and_call_original
|
65
|
-
AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: 'au', &block).perform
|
66
|
-
end
|
67
|
-
|
68
|
-
it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
|
69
|
-
expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
|
70
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
71
|
-
expect(net_http).to receive(:transport_request).once.and_return(response) # 1 Willis (success)
|
72
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # 2 Willis (error)
|
73
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry 2 Willis (error)
|
74
|
-
expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 2 Willis (error)
|
75
|
-
expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 2 Willis (success) & 3 Willis (success)
|
76
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
77
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "with the deprecated cleanse method" do
|
82
|
-
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
83
|
-
let(:block){
|
84
|
-
Proc.new do |proxy|
|
85
|
-
proxy.cleanse(q: "1 Willis")
|
86
|
-
end
|
87
|
-
}
|
88
|
-
|
89
|
-
it "has the same behaviour as the verification method" do
|
90
|
-
expect(net_http).to receive(:do_start).once.and_call_original
|
91
|
-
expect(net_http).to receive(:transport_request).once.and_return(response)
|
92
|
-
expect(net_http).to receive(:do_finish).once.and_call_original
|
93
|
-
expect(AddressFinder::Verification).to receive(:new).exactly(1).times.and_call_original
|
94
|
-
AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: 'au', &block).perform
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "with a country override and v2 in the config" do
|
99
|
-
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
100
|
-
let(:block){
|
101
|
-
Proc.new do |proxy|
|
102
|
-
proxy.verification(q: "1 Willis", country: "au")
|
103
|
-
end
|
104
|
-
}
|
105
|
-
|
106
|
-
it "has the same behaviour as the verification method" do
|
107
|
-
expect(net_http).to receive(:do_start).once.and_call_original
|
108
|
-
expect(net_http).to receive(:transport_request).once.and_return(response)
|
109
|
-
expect(net_http).to receive(:do_finish).once.and_call_original
|
110
|
-
expect(AddressFinder::V2::Au::Verification).to receive(:new).exactly(1).times.and_call_original
|
111
|
-
AddressFinder::Bulk.new(http: http, verification_version: "v2", default_country: 'nz', &block).perform
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "email verification with 3 requests in the provided block" do
|
116
|
-
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
117
|
-
let(:block){
|
118
|
-
Proc.new do |proxy|
|
119
|
-
proxy.email_verification(email: "john.doe@addressfinder.com")
|
120
|
-
proxy.email_verification(email: "jane.doe@addressfinder.com")
|
121
|
-
proxy.email_verification(email: "tom.doe@addressfinder.com")
|
122
|
-
end
|
123
|
-
}
|
124
|
-
|
125
|
-
it "uses 1 http connection" do
|
126
|
-
expect(net_http).to receive(:do_start).once.and_call_original
|
127
|
-
expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
128
|
-
expect(net_http).to receive(:do_finish).once.and_call_original
|
129
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
130
|
-
end
|
131
|
-
|
132
|
-
it "calls the correct class with v1 verification and nz default" do
|
133
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
134
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
135
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
136
|
-
expect(AddressFinder::V1::Email::Verification).to receive(:new).exactly(3).times.and_call_original
|
137
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
138
|
-
end
|
139
|
-
|
140
|
-
it "calls the correct class without a verification version or default country" do
|
141
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
142
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
143
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
144
|
-
expect(AddressFinder::V1::Email::Verification).to receive(:new).exactly(3).times.and_call_original
|
145
|
-
AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: nil, &block).perform
|
146
|
-
end
|
147
|
-
|
148
|
-
it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
|
149
|
-
expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
|
150
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
151
|
-
expect(net_http).to receive(:transport_request).once.and_return(response) # john.doe@addressfinder.com (success)
|
152
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # jane.doe@addressfinder.com (error)
|
153
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry jane.doe@addressfinder.com (error)
|
154
|
-
expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry jane.doe@addressfinder.com (error)
|
155
|
-
expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry jane.doe@addressfinder.com (success) & tom.doe@addressfinder.com (success)
|
156
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
157
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "phone verification with 3 requests in the provided block" do
|
162
|
-
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
163
|
-
let(:block){
|
164
|
-
Proc.new do |proxy|
|
165
|
-
proxy.phone_verification(phone_number: "+64274673830", default_country_code: "AU")
|
166
|
-
proxy.phone_verification(phone_number: "1800 152 363", default_country_code: "AU")
|
167
|
-
proxy.phone_verification(phone_number: "0274673830", default_country_code: "NZ")
|
168
|
-
end
|
169
|
-
}
|
170
|
-
|
171
|
-
it "uses 1 http connection" do
|
172
|
-
expect(net_http).to receive(:do_start).once.and_call_original
|
173
|
-
expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
174
|
-
expect(net_http).to receive(:do_finish).once.and_call_original
|
175
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
176
|
-
end
|
177
|
-
|
178
|
-
it "calls the correct class with v1 verification and nz default" do
|
179
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
180
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
181
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
182
|
-
expect(AddressFinder::V1::Phone::Verification).to receive(:new).exactly(3).times.and_call_original
|
183
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
184
|
-
end
|
185
|
-
|
186
|
-
it "calls the correct class without a verification version or default country" do
|
187
|
-
allow(net_http).to receive(:do_start).once.and_call_original
|
188
|
-
allow(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
|
189
|
-
allow(net_http).to receive(:do_finish).once.and_call_original
|
190
|
-
expect(AddressFinder::V1::Phone::Verification).to receive(:new).exactly(3).times.and_call_original
|
191
|
-
AddressFinder::Bulk.new(http: http, verification_version: nil, default_country: nil, &block).perform
|
192
|
-
end
|
193
|
-
|
194
|
-
it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
|
195
|
-
expect(http).to receive(:re_establish_connection).exactly(3).times.and_call_original
|
196
|
-
expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
|
197
|
-
expect(net_http).to receive(:transport_request).once.and_return(response) # +64274673830 (success)
|
198
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout) # 1800 152 363 (error)
|
199
|
-
expect(net_http).to receive(:transport_request).once.and_raise(Net::ReadTimeout) # Retry 1800 152 363 (error)
|
200
|
-
expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 1800 152 363 (error)
|
201
|
-
expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 1800 152 363 (success) & 0274673830 (success)
|
202
|
-
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
203
|
-
AddressFinder::Bulk.new(http: http, verification_version: 'v1', default_country: 'nz', &block).perform
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe AddressFinder::LocationInfo do
|
4
|
-
before do
|
5
|
-
AddressFinder.configure do |af|
|
6
|
-
af.api_key = 'XXX'
|
7
|
-
af.api_secret = 'YYY'
|
8
|
-
af.default_country = 'au'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#build_request' do
|
13
|
-
let(:locator){ AddressFinder::LocationInfo.new(params: args, http: http) }
|
14
|
-
let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
|
15
|
-
|
16
|
-
subject(:request_uri){ locator.send(:build_request) }
|
17
|
-
|
18
|
-
context 'with a simple PXID' do
|
19
|
-
let(:args){ {pxid: '123'} }
|
20
|
-
|
21
|
-
it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&key=XXX&secret=YYY') }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a country override' do
|
25
|
-
let(:args){ {pxid: '123', country: 'nz'} }
|
26
|
-
|
27
|
-
it { expect(request_uri).to eq('/api/nz/location/info.json?pxid=123&key=XXX&secret=YYY') }
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with a key override' do
|
31
|
-
let(:args){ {pxid: '123', key: 'AAA'} }
|
32
|
-
|
33
|
-
it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&key=AAA&secret=YYY') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with a secret override' do
|
37
|
-
let(:args){ {pxid: '123', secret: 'BBB'} }
|
38
|
-
|
39
|
-
it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&secret=BBB&key=XXX') }
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'with a domain given' do
|
43
|
-
let(:args){ {pxid: '123', domain: 'testdomain.com'} }
|
44
|
-
|
45
|
-
it { expect(request_uri).to eq('/api/au/location/info.json?pxid=123&domain=testdomain.com&key=XXX&secret=YYY') }
|
46
|
-
|
47
|
-
context 'given in the AF configuration' do
|
48
|
-
|
49
|
-
let(:args){ {pxid: '123'} }
|
50
|
-
|
51
|
-
it 'should use the config domain if set' do
|
52
|
-
AddressFinder.configuration.domain = 'anotherdomain.com'
|
53
|
-
expect(request_uri).to eq('/api/au/location/info.json?pxid=123&domain=anotherdomain.com&key=XXX&secret=YYY')
|
54
|
-
AddressFinder.configuration.domain = nil # set back to nil after
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#build_result' do
|
61
|
-
let(:locator){ AddressFinder::LocationInfo.new(params: {q: 'ignored'}, http: nil) }
|
62
|
-
|
63
|
-
before do
|
64
|
-
locator.send('response_body=', body)
|
65
|
-
locator.send('response_status=', status)
|
66
|
-
end
|
67
|
-
|
68
|
-
subject(:result){ locator.send(:build_result) }
|
69
|
-
|
70
|
-
context 'with a successful result' do
|
71
|
-
let(:body){ '{"a":"Seaview Road, Glenfield, Auckland","city":"Auckland","suburb":"Glenfield","region":"Auckland Region","x":174.713938691835,"y":-36.7894885545157,"pxid":"1-.1.6.j.1F","street":"Seaview Road"}' }
|
72
|
-
let(:status){ '200' }
|
73
|
-
|
74
|
-
it { expect(result.class).to eq(AddressFinder::LocationInfo::Result) }
|
75
|
-
it { expect(result.a).to eq("Seaview Road, Glenfield, Auckland") }
|
76
|
-
it { expect(result.pxid).to eq("1-.1.6.j.1F") }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|