addressfinder 1.5.2 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ RSpec.describe AddressFinder::LocationSearch do
11
11
 
12
12
  describe '#build_request' do
13
13
  let(:locator){ AddressFinder::LocationSearch.new(params: args, http: http) }
14
- let(:http){ AddressFinder.send(:configure_http) }
14
+ let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
15
15
 
16
16
  subject(:request_uri){ locator.send(:build_request) }
17
17
 
@@ -0,0 +1,170 @@
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&format=json&key=XXX&secret=YYY') }
71
+ end
72
+
73
+ context 'with more arguments' do
74
+ let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', paf: '1', census: '2013', http: http} }
75
+
76
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&delivered=true&paf=1&region_code=A&census=2013&format=json&key=XXX&secret=YYY') }
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&format=json&key=XXX&secret=YYY') }
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&state_codes[]=ACT&state_codes[]=NSW&format=json&key=XXX&secret=YYY') }
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&state_codes[]=ACT&state_codes[]=NSW&format=json&key=XXX&secret=YYY') }
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&state_codes=ACT%2CNSW&format=json&key=XXX&secret=YYY') }
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&format=json&key=AAA&secret=YYY') }
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&format=json&key=XXX&secret=BBB') }
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&format=json&key=XXX&secret=YYY') }
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&format=json&key=XXX&secret=YYY')
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
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressfinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Ramsay
8
8
  - Naiki Pohe
9
9
  - Sean Arnold
10
10
  - Alexandre Barret
11
+ - Cassandre Guinut
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2015-12-21 00:00:00.000000000 Z
15
+ date: 2021-07-02 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: multi_json
@@ -61,14 +62,14 @@ dependencies:
61
62
  requirements:
62
63
  - - "~>"
63
64
  - !ruby/object:Gem::Version
64
- version: '10.4'
65
+ version: '13.0'
65
66
  type: :development
66
67
  prerelease: false
67
68
  version_requirements: !ruby/object:Gem::Requirement
68
69
  requirements:
69
70
  - - "~>"
70
71
  - !ruby/object:Gem::Version
71
- version: '10.4'
72
+ version: '13.0'
72
73
  - !ruby/object:Gem::Dependency
73
74
  name: webmock
74
75
  requirement: !ruby/object:Gem::Requirement
@@ -83,12 +84,27 @@ dependencies:
83
84
  - - "~>"
84
85
  - !ruby/object:Gem::Version
85
86
  version: '1.21'
87
+ - !ruby/object:Gem::Dependency
88
+ name: listen
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '3.2'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.2'
86
101
  description: Ruby client library for AddressFinder
87
102
  email:
88
- - nigel.ramsay@abletech.co.nz
103
+ - nigel.ramsay@addressfinder.nz
89
104
  - naiki.pohe@abletech.co.nz
90
105
  - seanarnie@gmail.com
91
106
  - alex@abletech.nz
107
+ - cassandre.guinut@addressfinder.nz
92
108
  executables: []
93
109
  extensions: []
94
110
  extra_rdoc_files: []
@@ -96,31 +112,37 @@ files:
96
112
  - ".gitignore"
97
113
  - ".travis.yml"
98
114
  - CHANGELOG.md
115
+ - Dockerfile
99
116
  - Gemfile
100
117
  - Guardfile
101
- - LICENSE
118
+ - LICENSE.md
102
119
  - README.md
103
120
  - Rakefile
104
121
  - addressfinder.gemspec
122
+ - docker-compose.yml
105
123
  - lib/addressfinder.rb
124
+ - lib/addressfinder/address_autocomplete.rb
106
125
  - lib/addressfinder/address_info.rb
107
126
  - lib/addressfinder/address_search.rb
108
127
  - lib/addressfinder/bulk.rb
109
- - lib/addressfinder/cleanse.rb
110
128
  - lib/addressfinder/configuration.rb
111
129
  - lib/addressfinder/errors.rb
130
+ - lib/addressfinder/http.rb
112
131
  - lib/addressfinder/location_info.rb
113
132
  - lib/addressfinder/location_search.rb
114
133
  - lib/addressfinder/util.rb
134
+ - lib/addressfinder/verification.rb
115
135
  - lib/addressfinder/version.rb
136
+ - spec/lib/addressfinder/address_autocomplete_spec.rb
116
137
  - spec/lib/addressfinder/address_info_spec.rb
117
138
  - spec/lib/addressfinder/address_search_spec.rb
118
- - spec/lib/addressfinder/cleanse_spec.rb
139
+ - spec/lib/addressfinder/bulk_spec.rb
119
140
  - spec/lib/addressfinder/location_info_spec.rb
120
141
  - spec/lib/addressfinder/location_search_spec.rb
121
142
  - spec/lib/addressfinder/util_spec.rb
143
+ - spec/lib/addressfinder/verification_spec.rb
122
144
  - spec/spec_helper.rb
123
- homepage: https://github.com/AbleTech/addressfinder-ruby
145
+ homepage: https://github.com/AddressFinder/addressfinder-ruby
124
146
  licenses:
125
147
  - MIT
126
148
  metadata: {}
@@ -139,16 +161,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
161
  - !ruby/object:Gem::Version
140
162
  version: '0'
141
163
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.4.7
164
+ rubygems_version: 3.0.3
144
165
  signing_key:
145
166
  specification_version: 4
146
167
  summary: Provides easy access to AddressFinder APIs
147
168
  test_files:
169
+ - spec/lib/addressfinder/address_autocomplete_spec.rb
148
170
  - spec/lib/addressfinder/address_info_spec.rb
149
171
  - spec/lib/addressfinder/address_search_spec.rb
150
- - spec/lib/addressfinder/cleanse_spec.rb
172
+ - spec/lib/addressfinder/bulk_spec.rb
151
173
  - spec/lib/addressfinder/location_info_spec.rb
152
174
  - spec/lib/addressfinder/location_search_spec.rb
153
175
  - spec/lib/addressfinder/util_spec.rb
176
+ - spec/lib/addressfinder/verification_spec.rb
154
177
  - spec/spec_helper.rb
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Abletech
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.
22
-
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::Cleanse 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(:cleanser){ AddressFinder::Cleanse.new(args) }
14
- let(:http){ AddressFinder.send(:configure_http) }
15
-
16
- subject(:request_uri){ cleanser.send(:build_request) }
17
-
18
- context 'with minimal arguments' do
19
- let(:args){ {q: '186 willis st', http: http} }
20
-
21
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=YYY') }
22
- end
23
-
24
- context 'with more arguments' do
25
- let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', http: http} }
26
-
27
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&delivered=true&region_code=A&format=json&key=XXX&secret=YYY') }
28
- end
29
-
30
- context 'with a country override' do
31
- let(:args){ {q: '186 willis st', country: 'au', http: http} }
32
-
33
- it { expect(request_uri).to eq('/api/au/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=YYY') }
34
- end
35
-
36
- context 'with a key override' do
37
- let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
38
-
39
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=AAA&secret=YYY') }
40
- end
41
-
42
- context 'with a secret override' do
43
- let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
44
-
45
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=BBB') }
46
- end
47
-
48
- context 'with a domain given' do
49
- let(:args){ {q: '123', domain: 'testdomain.com', http: http} }
50
-
51
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=123&domain=testdomain.com&format=json&key=XXX&secret=YYY') }
52
-
53
- context 'given in the AF configuration' do
54
-
55
- let(:args){ {q: '123', http: http} }
56
-
57
- it 'should use the config domain if set' do
58
- AddressFinder.configuration.domain = 'anotherdomain.com'
59
- expect(request_uri).to eq('/api/nz/address/cleanse?q=123&domain=anotherdomain.com&format=json&key=XXX&secret=YYY')
60
- AddressFinder.configuration.domain = nil # set back to nil after
61
- end
62
- end
63
- end
64
- end
65
-
66
- describe '#build_result' do
67
- let(:cleanser){ AddressFinder::Cleanse.new(q: 'ignored', http: nil) }
68
-
69
- before do
70
- cleanser.send('response_body=', body)
71
- cleanser.send('response_status=', status)
72
- end
73
-
74
- subject(:result){ cleanser.send(:build_result) }
75
-
76
- context 'with a successful nz result' do
77
- let(:body){ '{"matched": true, "postal_address": "Texas"}' }
78
- let(:status){ '200' }
79
-
80
- it { expect(result.class).to eq(AddressFinder::Cleanse::Result) }
81
-
82
- it { expect(result.matched).to eq(true) }
83
-
84
- it { expect(result.postal_address).to eq("Texas") }
85
- end
86
-
87
- context 'with a successful au result' do
88
- let(:body){ %Q({"matched": true, "success": true, "address": {"full_address": "Texas"}}) }
89
- let(:status){ '200' }
90
-
91
- it { expect(result.class).to eq(AddressFinder::Cleanse::Result) }
92
-
93
- it { expect(result.full_address).to eq("Texas") }
94
- end
95
-
96
- context 'with an unfound result' do
97
- let(:body){ '{"matched": false}' }
98
- let(:status){ '200' }
99
-
100
- it { expect(result).to eq(nil) }
101
- end
102
- end
103
- end