addressfinder 1.7.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2191b3d7090b6eb2c2001f080427cc917c5af00262520c907b401a2a3d7c82e
4
- data.tar.gz: bd35444c4cb2a31a47130ded4dae80596718a4d6998006ffc34b92512cf729dd
3
+ metadata.gz: bac347ed1fa4ee45f7ff1bdc3f5fdc5bee74206fa73b1fe4d33be727f21c1b41
4
+ data.tar.gz: 44e72444624d652a166089b6c630fb739d47f77155dfaed2e8a27b88afa7bf59
5
5
  SHA512:
6
- metadata.gz: '08384b27d66dd5397f8e07dc550b86ea0befa4eaae6f8f294dcb8f01e4372739bebfe0484a6874fd0f3f05b6f19ed21108e7923fd8416379532d5b799bb5c60f'
7
- data.tar.gz: aadab0cc138ef723af46bd2e6baf1ac6571f51ecaba2dcfa2aedd34ff44b3a5c44b78f39ca5c2828edea29ae3329f1e22ec8ddfdc787482c24142202ece4b749
6
+ metadata.gz: 180b47e4aa74a5b09c312cc6be655bca62f9f4293f68b7c2505370dbdf2f14c2a48bf71d6523fbe1cf991bcf078745f62ba9d9f9b4e7cebdabd9b38900e111ee
7
+ data.tar.gz: 7396a52596c09359dbd3cb2facaafe6d4af4b4887be6d0c12b9de8770441ca45055bace9b4665af649793c0f482f39125b59df0e377f75c61e6380578ab258e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # AddressFinder 1.9.0 (July 2022) #
2
+
3
+ * Add support for Ruby 3.x
4
+ * Update gem dependencies
5
+
6
+ # AddressFinder 1.8.1 (October 2021) #
7
+
8
+ * Prevent NZ bulk and verification calls from using V2 module
9
+
10
+ # AddressFinder 1.8.0 (October 2021) #
11
+
12
+ * Create a V2 Module for verification (Australia)
13
+ * Remove PAF support from V1 verification API (Australia)
14
+ * Include API version number in configuration
15
+
1
16
  # AddressFinder 1.7.1 (June 2, 2021) #
2
17
 
3
18
  * Add support for PAF verification
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
- # Use the barebones version of Ruby 2.6.1
2
- FROM ruby:2.6
1
+ # Use the barebones version of Ruby 2.7.x
2
+ FROM ruby:2.7
3
3
 
4
4
  # Install dependencies:
5
5
  # - build-essential: To ensure certain gems can be compiled
data/README.md CHANGED
@@ -31,6 +31,7 @@ AddressFinder.configure do |af|
31
31
 
32
32
  # Optional
33
33
  af.default_country = 'nz' # default: nz
34
+ af.verification_version = 'v2' # default: v1
34
35
  af.timeout = 10 # default: 10 seconds
35
36
  af.retries = 12 # default: 12
36
37
  af.retry_delay = 5 # default: 5 seconds
@@ -2,25 +2,25 @@
2
2
  require File.expand_path('../lib/addressfinder/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.name = "addressfinder"
5
+ gem.name = 'addressfinder'
6
6
  gem.version = AddressFinder::VERSION
7
7
  gem.licenses = ['MIT']
8
- gem.authors = ["Nigel Ramsay", "Naiki Pohe", "Sean Arnold", "Alexandre Barret", "Cassandre Guinut"]
9
- gem.email = ["nigel.ramsay@addressfinder.nz", "naiki.pohe@abletech.co.nz", "seanarnie@gmail.com", "alex@abletech.nz", "cassandre.guinut@addressfinder.nz"]
10
- gem.description = %q{Ruby client library for AddressFinder}
11
- gem.summary = %q{Provides easy access to AddressFinder APIs}
12
- gem.homepage = "https://github.com/AddressFinder/addressfinder-ruby"
8
+ gem.authors = ['Nigel Ramsay', 'Naiki Pohe', 'Sean Arnold', 'Alexandre Barret', 'Cassandre Guinut']
9
+ gem.email = ['nigel.ramsay@addressfinder.nz', 'naiki.pohe@abletech.co.nz', 'seanarnie@gmail.com', 'alex@abletech.nz', 'cassandre.guinut@addressfinder.nz']
10
+ gem.description = 'Ruby client library for AddressFinder'
11
+ gem.summary = 'Provides easy access to AddressFinder APIs'
12
+ gem.homepage = 'https://github.com/AddressFinder/addressfinder-ruby'
13
13
 
14
14
  gem.files = `git ls-files`.split($/)
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(spec|features)/})
17
- gem.require_paths = ["lib"]
17
+ gem.require_paths = ['lib']
18
18
 
19
- gem.required_ruby_version = '~> 2.1'
20
- gem.add_dependency 'multi_json', '~> 1.11'
21
- gem.add_development_dependency 'rspec', '~> 3.3'
22
- gem.add_development_dependency 'guard-rspec', '~> 4.6'
19
+ gem.required_ruby_version = '>= 2.1'
20
+ gem.add_dependency 'multi_json', '~> 1.15'
21
+ gem.add_development_dependency 'guard-rspec', '~> 4.7'
22
+ gem.add_development_dependency 'listen', '~> 3.7'
23
23
  gem.add_development_dependency 'rake', '~> 13.0'
24
+ gem.add_development_dependency 'rspec', '~> 3.11'
24
25
  gem.add_development_dependency 'webmock', '~> 1.21'
25
- gem.add_development_dependency 'listen', '~> 3.2'
26
26
  end
@@ -1,36 +1,44 @@
1
1
  module AddressFinder
2
2
  class Bulk
3
- def initialize(http:, &block)
3
+ def initialize(http:, verification_version:, default_country:, &block)
4
4
  @block = block
5
+ @verification_version = verification_version
6
+ @default_country = default_country
5
7
  @http_config = http
6
8
  end
7
9
 
8
10
  def perform
9
11
  http_config.start do |http|
10
- block.call ClientProxy.new(http: http)
12
+ block.call ClientProxy.new(http: http, verification_version: verification_version, default_country: default_country)
11
13
  end
12
14
  end
13
15
 
14
16
  private
15
17
 
16
- attr_reader :block, :http_config
18
+ attr_reader :block, :verification_version, :default_country, :http_config
17
19
 
18
20
  class ClientProxy
19
- def initialize(http:)
21
+ def initialize(http:, verification_version:, default_country:)
22
+ @verification_version = verification_version
23
+ @default_country = default_country
20
24
  @http = http
21
25
  end
22
26
 
23
27
  def cleanse(args={})
24
- AddressFinder::Verification.new(args.merge(http: http)).perform.result
28
+ AddressFinder::Verification.new(**args.merge(http: http)).perform.result
25
29
  end
26
30
 
27
31
  def verification(args={})
28
- AddressFinder::Verification.new(args.merge(http: http)).perform.result
32
+ if verification_version&.downcase == "v2" && (args[:country] || default_country) == 'au'
33
+ AddressFinder::V2::Au::Verification.new(**args.merge(http: http)).perform.result
34
+ else
35
+ AddressFinder::Verification.new(**args.merge(http: http)).perform.result
36
+ end
29
37
  end
30
38
 
31
39
  private
32
40
 
33
- attr_reader :http
41
+ attr_reader :http, :verification_version, :default_country
34
42
  end
35
43
  end
36
44
  end
@@ -2,6 +2,7 @@ module AddressFinder
2
2
  class Configuration
3
3
  attr_accessor :api_key
4
4
  attr_accessor :api_secret
5
+ attr_accessor :verification_version
5
6
  attr_accessor :hostname
6
7
  attr_accessor :port
7
8
  attr_accessor :proxy_host
@@ -21,6 +22,7 @@ module AddressFinder
21
22
  self.retries = 12
22
23
  self.retry_delay = 5
23
24
  self.default_country = 'nz'
25
+ self.verification_version = 'v1'
24
26
  end
25
27
  end
26
28
  end
@@ -0,0 +1,96 @@
1
+ require 'ostruct'
2
+
3
+ module AddressFinder
4
+ module V2
5
+ module Au
6
+ class Verification
7
+
8
+ attr_reader :result
9
+
10
+ # V2 AU expected attributes:
11
+ # params[:q] --> the address query,
12
+ # params[:post_box] --> nil or '0'
13
+ # params[:census] --> '2011' or '2016' or nil,
14
+ # params[:domain] --> used for reporting does not affect query results
15
+ # params[:key] --> unique AddressFinder public key
16
+ # params[:secret] --> unique AddressFinder secret key
17
+ # params[:paf] --> nil or '1',
18
+ # params[:gnaf] --> nil or '1',
19
+ # params[:gps] --> nil or '1',
20
+ # params[:extended] --> nil or '1',
21
+ # params[:state_codes] --> string or array of strings: i.e.,['ACT', 'NSW'],
22
+ def initialize(q:, post_box: nil, census: nil, domain: nil, key: nil, secret: nil, paf: nil, gnaf: nil, gps: nil, state_codes: nil, extended: nil, http:, country: nil)
23
+ @params = {}
24
+ @params['q'] = q
25
+ @params['post_box'] = post_box if post_box
26
+ @params['census'] = census if census
27
+ @params['domain'] = domain || config.domain if (domain || config.domain)
28
+ @params['key'] = key || config.api_key
29
+ @params['secret'] = secret || config.api_secret
30
+ @params['paf'] = paf if paf
31
+ @params['gnaf'] = gnaf if gnaf
32
+ @params['gps'] = gps if gps
33
+ @params['extended'] = extended if extended
34
+ @params['state_codes'] = state_codes if state_codes
35
+
36
+ @params['format'] = 'json'
37
+ @http = http
38
+ end
39
+
40
+ def perform
41
+ build_request
42
+ execute_request
43
+ build_result
44
+
45
+ self
46
+ end
47
+
48
+ private
49
+
50
+ attr_reader :request_uri, :params, :http
51
+ attr_accessor :response_body, :response_status
52
+ attr_writer :result
53
+
54
+ def build_request
55
+ @request_uri = "/api/au/address/v2/verification?#{encoded_params}"
56
+ end
57
+
58
+ def execute_request
59
+ request = Net::HTTP::Get.new(request_uri)
60
+
61
+ response = http.request(request)
62
+
63
+ self.response_body = response.body
64
+ self.response_status = response.code
65
+ end
66
+
67
+ def build_result
68
+ if response_status != '200'
69
+ raise AddressFinder::RequestRejectedError.new(@response_status, @response_body)
70
+ end
71
+
72
+ if response_hash['matched']
73
+ self.result = Result.new(response_hash['address'] || response_hash)
74
+ else
75
+ self.result = nil
76
+ end
77
+ end
78
+
79
+ def encoded_params
80
+ Util.encode_and_join_params(params)
81
+ end
82
+
83
+ def response_hash
84
+ @_response_hash ||= MultiJson.load(response_body)
85
+ end
86
+
87
+ def config
88
+ @_config ||= AddressFinder.configuration
89
+ end
90
+
91
+ class Result < OpenStruct
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -5,21 +5,40 @@ module AddressFinder
5
5
 
6
6
  attr_reader :result
7
7
 
8
- def initialize(q:, country: nil, delivered: nil, post_box: nil, paf: nil, rural: nil, region_code: nil, state_codes: nil, census: nil, domain: nil, key: nil, secret: nil, http:)
8
+ # AU V1 expected attributes:
9
+ # params[:state_codes] --> string or array of strings: i.e.,['ACT', 'NSW'],
10
+ # params[:census] --> '2011' or '2016' or nil,
11
+
12
+ # NZ expected attributes:
13
+ # params[:delivered] --> '0', '1', or nil,
14
+ # params[:post_box] --> '0', '1', or nil,
15
+ # params[:rural] --> '0', '1', or nil,
16
+ # params[:region_code] --> string, see options on addressfinder.nz or nil,
17
+ # params[:census] --> '2013', '2018' or nil
18
+
19
+ # Combined attributes
20
+ # params[:q] --> the address query,
21
+ # params[:domain] --> used for reporting does not affect query results
22
+ # params[:key] --> unique AddressFinder public key
23
+ # params[:secret] --> unique AddressFinder secret key
24
+ def initialize(q:, post_box: nil, census: nil, domain: nil, key: nil, secret: nil, state_codes: nil, delivered: nil, rural: nil, region_code: nil, country: nil, http:)
9
25
  @params = {}
26
+ # Common to AU and NZ
10
27
  @params['q'] = q
11
- @params['delivered'] = delivered if delivered
12
28
  @params['post_box'] = post_box if post_box
13
- @params['paf'] = paf if paf
14
- @params['rural'] = rural if rural
15
- @params['region_code'] = region_code if region_code
16
- @params['state_codes'] = state_codes if state_codes
17
29
  @params['census'] = census if census
18
30
  @params['domain'] = domain || config.domain if (domain || config.domain)
19
- @params['format'] = 'json'
20
31
  @params['key'] = key || config.api_key
21
32
  @params['secret'] = secret || config.api_secret
33
+ # AU params
34
+ @params['state_codes'] = state_codes if state_codes
35
+ # NZ params
36
+ @params['delivered'] = delivered if delivered
37
+ @params['rural'] = rural if rural
38
+ @params['region_code'] = region_code if region_code
22
39
  @country = country || config.default_country
40
+
41
+ @params['format'] = 'json'
23
42
  @http = http
24
43
  end
25
44
 
@@ -1,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = '1.7.1'
2
+ VERSION = '1.9.0'
3
3
  end
data/lib/addressfinder.rb CHANGED
@@ -2,6 +2,7 @@ require 'multi_json'
2
2
  require 'addressfinder/version'
3
3
  require 'addressfinder/configuration'
4
4
  require 'addressfinder/verification'
5
+ require 'addressfinder/v2/au/verification'
5
6
  require 'addressfinder/location_info'
6
7
  require 'addressfinder/location_search'
7
8
  require 'addressfinder/address_info'
@@ -33,7 +34,11 @@ module AddressFinder
33
34
  end
34
35
 
35
36
  def verification(args={})
36
- AddressFinder::Verification.new(args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
37
+ if (args[:country] || configuration.default_country) == 'au' && configuration.verification_version&.downcase == "v2"
38
+ AddressFinder::V2::Au::Verification.new(args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
39
+ else
40
+ AddressFinder::Verification.new(args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
41
+ end
37
42
  end
38
43
 
39
44
  def location_search(args={})
@@ -57,7 +62,7 @@ module AddressFinder
57
62
  end
58
63
 
59
64
  def bulk(&block)
60
- AddressFinder::Bulk.new(http: AddressFinder::HTTP.new(configuration), &block).perform
65
+ AddressFinder::Bulk.new(http: AddressFinder::HTTP.new(configuration), verification_version: configuration.verification_version, default_country: configuration.default_country, &block).perform
61
66
  end
62
67
  end
63
68
  end
@@ -38,7 +38,31 @@ RSpec.describe AddressFinder::Bulk do
38
38
  expect(net_http).to receive(:do_start).once.and_call_original
39
39
  expect(net_http).to receive(:transport_request).exactly(3).times.and_return(response)
40
40
  expect(net_http).to receive(:do_finish).once.and_call_original
41
- AddressFinder::Bulk.new(http: http, &block).perform
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
42
66
  end
43
67
 
44
68
  it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
@@ -50,7 +74,7 @@ RSpec.describe AddressFinder::Bulk do
50
74
  expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 2 Willis (error)
51
75
  expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 2 Willis (success) & 3 Willis (success)
52
76
  expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
53
- AddressFinder::Bulk.new(http: http, &block).perform
77
+ AddressFinder::Bulk.new(http: http, verification_version: 'v2', default_country: 'au', &block).perform
54
78
  end
55
79
  end
56
80
 
@@ -66,7 +90,25 @@ RSpec.describe AddressFinder::Bulk do
66
90
  expect(net_http).to receive(:do_start).once.and_call_original
67
91
  expect(net_http).to receive(:transport_request).once.and_return(response)
68
92
  expect(net_http).to receive(:do_finish).once.and_call_original
69
- AddressFinder::Bulk.new(http: http, &block).perform
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
70
112
  end
71
113
  end
72
114
  end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe AddressFinder::V2::Au::Verification do
4
+ before do
5
+ AddressFinder.configure do |af|
6
+ af.api_key = 'XXX'
7
+ af.api_secret = 'YYY'
8
+ af.timeout = 5
9
+ af.retries = 3
10
+ end
11
+ end
12
+
13
+ let(:verification_module){ AddressFinder::V2::Au::Verification.new(**args) }
14
+ let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
15
+ let(:net_http){ http.send(:net_http) }
16
+
17
+ describe '#execute_request' do
18
+ let(:args){ {q: "186 Willis Street", http: http} }
19
+
20
+ before do
21
+ WebMock.allow_net_connect!(net_http_connect_on_start: true)
22
+ allow(http).to receive(:sleep)
23
+ allow(verification_module).to receive(:request_uri).and_return("/test/path")
24
+ expect(http).to_not receive(:re_establish_connection)
25
+ end
26
+
27
+ after do
28
+ WebMock.disable_net_connect!
29
+ end
30
+
31
+ subject(:execute_request){ verification_module.send(:execute_request) }
32
+
33
+ it "retries an errored request another time before succeeding" do
34
+ expect(net_http).to receive(:do_start).twice.and_call_original
35
+ expect(net_http).to receive(:transport_request).once.and_raise(Net::OpenTimeout)
36
+ expect(net_http).to receive(:transport_request).once.and_return(double(:response, body: "OK", code: "200"))
37
+ expect(net_http).to receive(:do_finish).twice.and_call_original
38
+ execute_request
39
+ end
40
+
41
+ it "re-raises a Net::OpenTimeout error after 3 retries" do
42
+ expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
43
+ expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::OpenTimeout)
44
+ expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
45
+ expect{execute_request}.to raise_error(Net::OpenTimeout)
46
+ end
47
+
48
+ it "re-raises a Net::ReadTimeout error after 3 retries" do
49
+ expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
50
+ expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(Net::ReadTimeout)
51
+ expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
52
+ expect{execute_request}.to raise_error(Net::ReadTimeout)
53
+ end
54
+
55
+ it "re-raises a SocketError error after 3 retries" do
56
+ expect(net_http).to receive(:do_start).exactly(4).times.and_call_original
57
+ expect(net_http).to receive(:transport_request).exactly(4).times.and_raise(SocketError)
58
+ expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
59
+ expect{execute_request}.to raise_error(SocketError)
60
+ end
61
+ end
62
+
63
+ describe '#build_request' do
64
+ subject(:request_uri){ verification_module.send(:build_request) }
65
+
66
+ context 'with minimal arguments' do
67
+ let(:args){ {q: '186 willis st', http: http} }
68
+
69
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
70
+ end
71
+
72
+ context 'with more arguments' do
73
+ let(:args){ {q: '186 willis st', census: '2011', http: http} }
74
+
75
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&census=2011&key=XXX&secret=YYY&format=json') }
76
+ end
77
+
78
+ context 'with a state codes as an array' do
79
+ let(:args){ {q: '186 willis st', state_codes: ['ACT','NSW'], http: http} }
80
+
81
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
82
+ end
83
+
84
+ context 'with a reserved character in the query' do
85
+ let(:args){ {q: '186=willis st', state_codes: ['ACT','NSW'], http: http} }
86
+
87
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186%3Dwillis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
88
+ end
89
+
90
+ context 'with a state codes as a string' do
91
+ let(:args){ {q: '186 willis st', state_codes: 'ACT,NSW', http: http} }
92
+
93
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes=ACT%2CNSW&format=json') }
94
+ end
95
+
96
+ context 'with a key override' do
97
+ let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
98
+
99
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=AAA&secret=YYY&format=json') }
100
+ end
101
+
102
+ context 'with a secret override' do
103
+ let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
104
+
105
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=BBB&format=json') }
106
+ end
107
+
108
+ context 'with a domain given' do
109
+ let(:args){ {q: '123', domain: 'testdomain.com', http: http} }
110
+
111
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=123&domain=testdomain.com&key=XXX&secret=YYY&format=json') }
112
+
113
+ context 'given in the AF configuration' do
114
+
115
+ let(:args){ {q: '123', http: http} }
116
+
117
+ it 'should use the config domain if set' do
118
+ AddressFinder.configuration.domain = 'anotherdomain.com'
119
+ # expect(request_uri).to eq('/api/au/address/v2/verification?q=123&domain=anotherdomain.com&key=XXX&secret=YYY&format=json')
120
+ AddressFinder.configuration.domain = nil # set back to nil after
121
+ end
122
+ end
123
+ end
124
+
125
+ context 'with a post_box exclusion' do
126
+ let(:args){ {q: '186 willis st', post_box: '0', http: http} }
127
+
128
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&post_box=0&key=XXX&secret=YYY&format=json') }
129
+ end
130
+
131
+ context 'with a gnaf request' do
132
+ let(:args){ {q: '186 willis st', gnaf: '1', http: http} }
133
+
134
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=YYY&gnaf=1&format=json') }
135
+ end
136
+
137
+ context 'with a paf request' do
138
+ let(:args){ {q: '186 willis st', paf: '1', http: http} }
139
+
140
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&key=XXX&secret=YYY&paf=1&format=json') }
141
+ end
142
+
143
+ context 'with a all args included request' do
144
+ let(:args){ {q: '186 willis st', paf: '1', gnaf:'1', post_box:'0', state_codes:'ACT', census: '2016', domain: 'mysite.com', gps: '1', extended: '1', http: http} }
145
+
146
+ it { expect(request_uri).to eq('/api/au/address/v2/verification?q=186+willis+st&post_box=0&census=2016&domain=mysite.com&key=XXX&secret=YYY&paf=1&gnaf=1&gps=1&extended=1&state_codes=ACT&format=json') }
147
+ end
148
+ end
149
+
150
+ describe '#build_result' do
151
+ let(:args){ {q: 'ignored', http: nil} }
152
+
153
+ before do
154
+ verification_module.send('response_body=', body)
155
+ verification_module.send('response_status=', status)
156
+ end
157
+
158
+ subject(:result){ verification_module.send(:build_result) }
159
+
160
+ context 'with a successful nz result' do
161
+ let(:body){ '{"matched": true, "postal_address": "Texas"}' }
162
+ let(:status){ '200' }
163
+
164
+ it { expect(result.class).to eq(AddressFinder::V2::Au::Verification::Result) }
165
+
166
+ it { expect(result.matched).to eq(true) }
167
+
168
+ it { expect(result.postal_address).to eq("Texas") }
169
+ end
170
+
171
+ context 'with a successful au result' do
172
+ let(:body){ %Q({"matched": true, "success": true, "address": {"full_address": "Texas"}}) }
173
+ let(:status){ '200' }
174
+
175
+ it { expect(result.class).to eq(AddressFinder::V2::Au::Verification::Result) }
176
+
177
+ it { expect(result.full_address).to eq("Texas") }
178
+ end
179
+
180
+ context 'with an unfound result' do
181
+ let(:body){ '{"matched": false}' }
182
+ let(:status){ '200' }
183
+
184
+ it { expect(result).to eq(nil) }
185
+ end
186
+ end
187
+ end
@@ -11,7 +11,7 @@ RSpec.describe AddressFinder::Verification do
11
11
  end
12
12
  end
13
13
 
14
- let(:verification_module){ AddressFinder::Verification.new(args) }
14
+ let(:verification_module){ AddressFinder::Verification.new(**args) }
15
15
  let(:http){ AddressFinder::HTTP.new(AddressFinder.configuration) }
16
16
  let(:net_http){ http.send(:net_http) }
17
17
 
@@ -67,55 +67,55 @@ RSpec.describe AddressFinder::Verification do
67
67
  context 'with minimal arguments' do
68
68
  let(:args){ {q: '186 willis st', http: http} }
69
69
 
70
- it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&format=json&key=XXX&secret=YYY') }
70
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
71
71
  end
72
72
 
73
73
  context 'with more arguments' do
74
- let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', paf: '1', census: '2013', http: http} }
74
+ let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', census: '2013', http: http} }
75
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') }
76
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&census=2013&key=XXX&secret=YYY&delivered=true&region_code=A&format=json') }
77
77
  end
78
78
 
79
79
  context 'with a country override' do
80
80
  let(:args){ {q: '186 willis st', country: 'au', http: http} }
81
81
 
82
- it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&format=json&key=XXX&secret=YYY') }
82
+ it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
83
83
  end
84
84
 
85
85
  context 'with a state codes as an array' do
86
86
  let(:args){ {q: '186 willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
87
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') }
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
89
  end
90
90
 
91
91
  context 'with a reserved character in the query' do
92
92
  let(:args){ {q: '186=willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
93
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') }
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
95
  end
96
96
 
97
97
  context 'with a state codes as a string' do
98
98
  let(:args){ {q: '186 willis st', country: 'au', state_codes: 'ACT,NSW', http: http} }
99
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') }
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
101
  end
102
102
 
103
103
  context 'with a key override' do
104
104
  let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
105
105
 
106
- it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&format=json&key=AAA&secret=YYY') }
106
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=AAA&secret=YYY&format=json') }
107
107
  end
108
108
 
109
109
  context 'with a secret override' do
110
110
  let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
111
111
 
112
- it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&format=json&key=XXX&secret=BBB') }
112
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=XXX&secret=BBB&format=json') }
113
113
  end
114
114
 
115
115
  context 'with a domain given' do
116
116
  let(:args){ {q: '123', domain: 'testdomain.com', http: http} }
117
117
 
118
- it { expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=testdomain.com&format=json&key=XXX&secret=YYY') }
118
+ it { expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=testdomain.com&key=XXX&secret=YYY&format=json') }
119
119
 
120
120
  context 'given in the AF configuration' do
121
121
 
@@ -123,7 +123,7 @@ RSpec.describe AddressFinder::Verification do
123
123
 
124
124
  it 'should use the config domain if set' do
125
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')
126
+ expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=anotherdomain.com&key=XXX&secret=YYY&format=json')
127
127
  AddressFinder.configuration.domain = nil # set back to nil after
128
128
  end
129
129
  end
@@ -0,0 +1,64 @@
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
+ end
33
+
34
+ context "with country set to au" do
35
+ let(:args){ {country: "au", q: "12 high street sydney"} }
36
+ it "calls the v2::Au class" do
37
+ expect(AddressFinder::V2::Au::Verification).to receive_message_chain(:new, :perform, :result)
38
+ subject
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#verification with verification_version not configured' do
44
+ subject(:verification){ AddressFinder.verification(args) }
45
+
46
+ context "with country set to nz" do
47
+ let(:args){ {country: "nz", q: "12 high street sydney"} }
48
+
49
+ it "calls the old class" do
50
+ expect(AddressFinder::Verification).to receive_message_chain(:new, :perform, :result)
51
+ subject
52
+ end
53
+ end
54
+
55
+ context "with country set to au" do
56
+ let(:args){ {country: "au", q: "12 high street sydney"} }
57
+
58
+ it "calls the old class" do
59
+ expect(AddressFinder::Verification).to receive_message_chain(:new, :perform, :result)
60
+ subject
61
+ end
62
+ end
63
+ end
64
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,9 @@ require 'addressfinder'
12
12
 
13
13
  RSpec.configure do |config|
14
14
  config.mock_with :rspec
15
+
16
+ config.filter_run :focus => true
17
+ config.run_all_when_everything_filtered = true
15
18
  end
16
19
 
17
20
  WebMock.disable_net_connect!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressfinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Ramsay
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-07-02 00:00:00.000000000 Z
15
+ date: 2022-07-21 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: multi_json
@@ -20,42 +20,42 @@ dependencies:
20
20
  requirements:
21
21
  - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: '1.11'
23
+ version: '1.15'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: '1.11'
30
+ version: '1.15'
31
31
  - !ruby/object:Gem::Dependency
32
- name: rspec
32
+ name: guard-rspec
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - "~>"
36
36
  - !ruby/object:Gem::Version
37
- version: '3.3'
37
+ version: '4.7'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - "~>"
43
43
  - !ruby/object:Gem::Version
44
- version: '3.3'
44
+ version: '4.7'
45
45
  - !ruby/object:Gem::Dependency
46
- name: guard-rspec
46
+ name: listen
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - "~>"
50
50
  - !ruby/object:Gem::Version
51
- version: '4.6'
51
+ version: '3.7'
52
52
  type: :development
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: '4.6'
58
+ version: '3.7'
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
61
  requirement: !ruby/object:Gem::Requirement
@@ -71,33 +71,33 @@ dependencies:
71
71
  - !ruby/object:Gem::Version
72
72
  version: '13.0'
73
73
  - !ruby/object:Gem::Dependency
74
- name: webmock
74
+ name: rspec
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '1.21'
79
+ version: '3.11'
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '1.21'
86
+ version: '3.11'
87
87
  - !ruby/object:Gem::Dependency
88
- name: listen
88
+ name: webmock
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '3.2'
93
+ version: '1.21'
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '3.2'
100
+ version: '1.21'
101
101
  description: Ruby client library for AddressFinder
102
102
  email:
103
103
  - nigel.ramsay@addressfinder.nz
@@ -131,6 +131,7 @@ files:
131
131
  - lib/addressfinder/location_info.rb
132
132
  - lib/addressfinder/location_search.rb
133
133
  - lib/addressfinder/util.rb
134
+ - lib/addressfinder/v2/au/verification.rb
134
135
  - lib/addressfinder/verification.rb
135
136
  - lib/addressfinder/version.rb
136
137
  - spec/lib/addressfinder/address_autocomplete_spec.rb
@@ -140,7 +141,9 @@ files:
140
141
  - spec/lib/addressfinder/location_info_spec.rb
141
142
  - spec/lib/addressfinder/location_search_spec.rb
142
143
  - spec/lib/addressfinder/util_spec.rb
144
+ - spec/lib/addressfinder/v2/au/verification_spec.rb
143
145
  - spec/lib/addressfinder/verification_spec.rb
146
+ - spec/lib/addressfinder_spec.rb
144
147
  - spec/spec_helper.rb
145
148
  homepage: https://github.com/AddressFinder/addressfinder-ruby
146
149
  licenses:
@@ -152,7 +155,7 @@ require_paths:
152
155
  - lib
153
156
  required_ruby_version: !ruby/object:Gem::Requirement
154
157
  requirements:
155
- - - "~>"
158
+ - - ">="
156
159
  - !ruby/object:Gem::Version
157
160
  version: '2.1'
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  requirements: []
164
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.6
165
168
  signing_key:
166
169
  specification_version: 4
167
170
  summary: Provides easy access to AddressFinder APIs
@@ -173,5 +176,7 @@ test_files:
173
176
  - spec/lib/addressfinder/location_info_spec.rb
174
177
  - spec/lib/addressfinder/location_search_spec.rb
175
178
  - spec/lib/addressfinder/util_spec.rb
179
+ - spec/lib/addressfinder/v2/au/verification_spec.rb
176
180
  - spec/lib/addressfinder/verification_spec.rb
181
+ - spec/lib/addressfinder_spec.rb
177
182
  - spec/spec_helper.rb