addressfinder 1.6.2 → 1.8.1

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: de05727d08ca624896115f6fe76ae68bb3dd36ed99195468153cf982c9af07a0
4
- data.tar.gz: 30ba24d9f052a8884ec5772b8d0d492f1334636674ae29e265ddd3fb105d51dd
3
+ metadata.gz: 939c60d3f251b84c6fc378148d6d8d3480e2dcf2f171c27b7edef470d9b5a5b8
4
+ data.tar.gz: '07988c8cbbe65632d5551a11d9a02618360589c43ef2b3f3112159141b0a290d'
5
5
  SHA512:
6
- metadata.gz: 160bee2722353ec131681b401a1ddb92748cb606b4e0bf5d1572a924becf1475a61431ef8382f39df9e361a4133d300714ec029033a631285f62f646c3428e17
7
- data.tar.gz: e1d026848279132f2cd4b2e1ba35061adee84fcac56e89b54fc336b7caff2386e4123a9f5686ea0792dc371fd6a2ba6fa35195d8dfd28a858de43e376cc423f5
6
+ metadata.gz: 14d93058d16682693bf237678aed85bb496d71447ff16457c30a32785e2fde1ad263c0063eb3da5a54ce96df3d88733afcef9452eb97e9a0a3483a56cfc86083
7
+ data.tar.gz: 19825d8fefac06180ee9c8d7a62eb81ec1ee8a06b753272f2dace02620a6e07c231e062d2af4f39285baafae1b00c232fd5c8034332d5f522452dae10e842145
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
3
+ - 2.2.7
4
4
  - 2.3.1
5
5
  - 2.4.1
6
6
  - 2.6.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # AddressFinder 1.8.1 (October 2021) #
2
+
3
+ * Prevent NZ bulk and verification calls from using V2 module
4
+
5
+ # AddressFinder 1.8.0 (October 2021) #
6
+
7
+ * Create a V2 Module for verification (Australia)
8
+ * Remove PAF support from V1 verification API (Australia)
9
+ * Include API version number in configuration
10
+
11
+ # AddressFinder 1.7.1 (June 2, 2021) #
12
+
13
+ * Add support for PAF verification
14
+ * Rename cleanse to verification
15
+
16
+ # AddressFinder 1.7.0 (May 4, 2020) #
17
+
18
+ * Add support for Address Autocomplete API (Australia only)
19
+
1
20
  # AddressFinder 1.6.2 (September 23, 2019) #
2
21
 
3
22
  * Add support for an optional state_codes parameter in the Cleanse class
data/Dockerfile ADDED
@@ -0,0 +1,28 @@
1
+ # Use the barebones version of Ruby 2.6.1
2
+ FROM ruby:2.6
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/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec, cmd: 'rspec' do
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { "spec" }
data/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (c) 2015-present AddressFinder
2
+
3
+ The intellectual property rights in this plugin are owned by AddressFinder Limited of Wellington New Zealand (referred to below as “we”, “us” or “our”) or its third party licensors. The plugin may be accessed and used by AddressFinder customers only, subject to the following terms. If you are not, or are no longer, an AddressFinder customer you are not permitted to access or use the plugin in any way.
4
+
5
+ If you are an AddressFinder customer (referred to below as “you” or “your”), the following terms apply in relation to your access and use of the plugin (and your access or use of the plugin confirms your acceptance of the following terms). If you do not accept the following terms you are not permitted to access or use the plugin in any way.
6
+ * In these terms, “Terms and Conditions” means the applicable Terms and Conditions that you entered into, being either https://addressfinder.nz/legal/terms/ or https://addressfinder.com.au/legal/terms/, and “Services” and “Subscription Term” have the meaning given in the Terms and Conditions.
7
+ * All rights, title and interest (including, without limitation, all intellectual property rights) in and to the plugin are owned by us or our third party licensors. Provided that you comply with these terms, and the Terms and Conditions, we grant you the right during your Subscription Term to: (a) access and use the plugin solely in connection with the Services and then only in combination with websites that you own or control; and (b) view the source code and configurations of the plugin solely for the purpose of evaluating the plugin in relation to its use in connection with the Services, and for no other purpose. This right is non-exclusive, non-transferable and may be revoked by us at any time. You are not granted any other rights or licences in relation to the plugin.
8
+ * You must never copy, modify, publish, merge, distribute, resell, lease, transfer or sub-license, or create derivative works from, all or any part of the plugin. You must never access or use the plugin for any purpose related to building a product or service which competes with the Services or the plugin or has similar features or functionality. You must comply with all instructions or restrictions that we provide to you in relation to the plugin (including, without limitation, that we may post on this page from time to time).
9
+ * The plugin is provided to you on an "as is" and "as available" basis and your use of it is at your sole risk. To the maximum extent permitted by law, we do not represent or warrant that the plugin will be secure, reliable, uninterrupted, always available, free of errors, omissions, inaccuracies, viruses or other destructive code, or that it will be fit for your purposes or for use in any specific technical environment or that any problems can or will be corrected. To the maximum extent permitted by law, we give no warranties in relation to the plugin. To avoid doubt, to the maximum extent permitted by law, we disclaim and exclude all implied representations, warranties and conditions (including any warranties of fitness for purpose, merchantability, title and non-infringement). Certain legislation may imply warranties or conditions, impose obligations or give statutory guarantees (together, Statutory Provisions) which cannot be excluded, restricted or modified except to a limited extent. These terms must be read subject to applicable Statutory Provisions. If the Statutory Provisions apply, notwithstanding any other provision of these terms, to the extent to which we are entitled to do so, we limit our liability in respect of any claim to: (a) in the case of goods, at our option: the replacement of the goods or the supply of equivalent goods; the repair of the goods; the payment of the cost of replacing the goods or acquiring equivalent goods; or the payment of having the goods repaired; and (b) in the case of services, at our option: the supply of the services again; or the payment of the cost of having the services supplied again. If you entered into our New Zealand Terms and Conditions, you represent to us that you are acquiring the right to use the plugin for the purposes of a business and so you agree that the provisions of the Consumer Guarantees Act 1993 do not apply to the plugin.
10
+ * To the maximum extent permitted by law, we and Our Related Parties will not be liable to you or any third party for any loss or damage to data, breach of security, loss of profit, revenue, opportunity or saving, or any incidental, indirect, special or consequential loss or damage. To the maximum extent permitted by law, the total aggregate liability of us and Our Related Parties (together) to you under or in connection with these terms or its subject matter is limited to NZ$10. These limitations and exclusions of liability apply however liability arises, whether in contract, in tort (including negligence), for breach of statutory duty or otherwise. You fully indemnify us from and against any claim, proceeding, damage, loss, liability, cost or expense (including legal costs on a solicitor and own client basis) arising from or connected to your use of plugin or breach of these terms. In these terms “Our Related Parties” means AddressFinder Pty Limited, ACN 606 672 333, any related company of us or AddressFinder Pty Limited (where “related company” has the meaning given in section 2(3) of the Companies Act 1993, and includes any company or similar entity which would be a related company within that definition if incorporated as a company in New Zealand) and our suppliers, contractors, directors, employees and agents.
11
+ * We may change these terms at any time by emailing you, by updating the Terms and Conditions and/or by displaying or referring to the replacement terms on this page. Your continued use of the plugin after you receive notice of any such changes will amount to your acceptance of those changes. If you don’t accept those changes you must immediately stop using the plugin.
12
+ * Any waiver of any part of these terms must be in writing and signed by one of our authorised representatives. Any delay or failure by us to exercise any right does not prevent us from exercising that right, or any other right, on that or any other occasion.
13
+ * Any unlawful or unenforceable provision of these terms will be deemed to be amended to the minimum extent necessary to ensure that it is not unlawful or unenforceable and, as far as is possible, to ensure that it is consistent with the intent and effect of the provision. The remaining provisions will be enforceable as if such unlawful or unenforceable provision had not been included in these terms. If the provision is unable to be amended without materially altering the intent and effect of the provision, it will be severed, and the remaining provisions will be enforceable.
14
+ * The terms are governed by the laws of New Zealand and you and we submit to the non-exclusive jurisdiction of the New Zealand courts.
15
+
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # AddressFinder Ruby Gem
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/addressfinder.svg)](http://badge.fury.io/rb/addressfinder)
4
- [![Build Status](https://travis-ci.org/AbleTech/addressfinder-ruby.svg)](https://travis-ci.org/AbleTech/addressfinder-ruby)
4
+ [![Build Status](https://travis-ci.com/github/AddressFinder/addressfinder-ruby.svg)](https://travis-ci.com/github/AddressFinder/addressfinder-ruby)
5
5
 
6
6
  A client library for accessing the [AddressFinder](https://addressfinder.nz/?utm_source=github&utm_medium=readme&utm_campaign=addressfinder_rubygem&utm_term=AddressFinder) APIs.
7
7
 
@@ -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
@@ -56,7 +57,7 @@ For available parameters and example responses, see the API documentation pages
56
57
  #### Address Verification
57
58
 
58
59
  ```ruby
59
- result = AddressFinder.cleanse(q: '186 Willis St, Wellington', country: 'nz')
60
+ result = AddressFinder.verification(q: '186 Willis St, Wellington', country: 'nz')
60
61
 
61
62
  if result
62
63
  $stdout.puts "Success: #{result.postal}"
@@ -65,7 +66,14 @@ else
65
66
  end
66
67
  ```
67
68
 
68
- #### Address Autocomplete
69
+ **Note:** The deprecated method `cleanse` is still available now but will be dropped in the future.
70
+
71
+ #### Address Search
72
+
73
+ The Address Search API supports the following address sets:
74
+
75
+ * New Zealand addresses
76
+ * Australian addresses from the GNAF dataset only
69
77
 
70
78
  ```ruby
71
79
  begin
@@ -81,6 +89,26 @@ rescue AddressFinder::RequestRejectedError => e
81
89
  end
82
90
  ```
83
91
 
92
+ #### Address Autocomplete
93
+
94
+ The Address Autocomplete API supports the following address sets:
95
+
96
+ * Australian addresses from the GNAF and PAF datasets only
97
+
98
+ ```ruby
99
+ begin
100
+ results = AddressFinder.address_autocomplete(q: '275 high st, bel', au_paf: '1')
101
+ if results.any?
102
+ $stdout.puts "Success: #{results}"
103
+ else
104
+ $stdout.puts "Sorry, there were no address matches"
105
+ end
106
+ rescue AddressFinder::RequestRejectedError => e
107
+ response = JSON.parse(e.body)
108
+ $stdout.puts response['message']
109
+ end
110
+ ```
111
+
84
112
  #### Address Metadata
85
113
 
86
114
  ```ruby
@@ -136,12 +164,12 @@ end
136
164
  If you have a series of API requests, you can use the
137
165
  bulk method to re-use the HTTP connection.
138
166
 
139
- **Note:** The bulk method is currently only available for Address Verification (`#cleanse`).
167
+ **Note:** The bulk method is currently only available for Address Verification (`#verification`).
140
168
 
141
169
  ```ruby
142
170
  AddressFinder.bulk do |af|
143
171
  CSV.foreach('auckland_addresses.csv') do |row|
144
- result = af.cleanse(q: row[0], region_code: '1')
172
+ result = af.verification(q: row[0], region_code: '1')
145
173
 
146
174
  if result
147
175
  $stdout.puts "Success: #{result.postal}"
@@ -171,3 +199,12 @@ rescue AddressFinder::RequestRejectedError => e
171
199
  end
172
200
  ```
173
201
 
202
+ ### Testing
203
+
204
+ You can run all the specs with the following command:
205
+
206
+ `docker-compose up`
207
+
208
+ You can `guard` for repeating test runs (while editing new code):
209
+
210
+ `docker-compose run ruby bundle exec guard`
@@ -5,11 +5,11 @@ Gem::Specification.new do |gem|
5
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"]
9
- gem.email = ["nigel.ramsay@abletech.co.nz", "naiki.pohe@abletech.co.nz", "seanarnie@gmail.com", "alex@abletech.nz"]
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
10
  gem.description = %q{Ruby client library for AddressFinder}
11
11
  gem.summary = %q{Provides easy access to AddressFinder APIs}
12
- gem.homepage = "https://github.com/AbleTech/addressfinder-ruby"
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) }
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency 'multi_json', '~> 1.11'
21
21
  gem.add_development_dependency 'rspec', '~> 3.3'
22
22
  gem.add_development_dependency 'guard-rspec', '~> 4.6'
23
- gem.add_development_dependency 'rake', '~> 10.4'
23
+ gem.add_development_dependency 'rake', '~> 13.0'
24
24
  gem.add_development_dependency 'webmock', '~> 1.21'
25
- gem.add_development_dependency 'listen', '~> 3.0.0'
25
+ gem.add_development_dependency 'listen', '~> 3.2'
26
26
  end
@@ -0,0 +1,11 @@
1
+ version: '3'
2
+ services:
3
+ ruby:
4
+ build: .
5
+ volumes:
6
+ - .:/addressfinder-ruby
7
+ - bundle-cache:/bundle
8
+ command: bundle exec rspec
9
+
10
+ volumes:
11
+ bundle-cache: {}
@@ -0,0 +1,77 @@
1
+ require 'ostruct'
2
+
3
+ module AddressFinder
4
+ class AddressAutocomplete
5
+
6
+ attr_reader :results
7
+
8
+ def initialize(params:, http:)
9
+ @http = http
10
+ @country = params.delete(:country) || 'au'
11
+
12
+ @params = params
13
+ @params[:key] ||= config.api_key
14
+ @params[:secret] ||= config.api_secret
15
+ end
16
+
17
+ def perform
18
+ validate_params
19
+ build_request
20
+ execute_request
21
+ build_result
22
+
23
+ self
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :request_uri, :params, :country, :http
29
+ attr_accessor :response_body, :response_status
30
+ attr_writer :results
31
+
32
+ def validate_params
33
+ if country != 'au'
34
+ raise AddressFinder::RequestRejectedError.new("400", "#address_autocomplete only available for Australian addresses")
35
+ end
36
+ end
37
+
38
+ def build_request
39
+ @request_uri = "/api/au/address/autocomplete.json?#{encoded_params}"
40
+ end
41
+
42
+ def encoded_params
43
+ Util.encode_and_join_params(params)
44
+ end
45
+
46
+ def execute_request
47
+ request = Net::HTTP::Get.new(request_uri)
48
+
49
+ response = http.request(request)
50
+
51
+ self.response_body = response.body
52
+ self.response_status = response.code
53
+ end
54
+
55
+ def build_result
56
+ case response_status
57
+ when '200'
58
+ self.results = response_hash['completions'].map do |result_hash|
59
+ Result.new(result_hash)
60
+ end
61
+ else
62
+ raise AddressFinder::RequestRejectedError.new(@response_status, @response_body)
63
+ end
64
+ end
65
+
66
+ def response_hash
67
+ @_response_hash ||= MultiJson.load(response_body)
68
+ end
69
+
70
+ def config
71
+ @_config ||= AddressFinder.configuration
72
+ end
73
+
74
+ class Result < OpenStruct
75
+ end
76
+ end
77
+ end
@@ -1,32 +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::Cleanse.new(args.merge(http: http)).perform.result
28
+ AddressFinder::Verification.new(args.merge(http: http)).perform.result
29
+ end
30
+
31
+ def verification(args={})
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
25
37
  end
26
38
 
27
39
  private
28
40
 
29
- attr_reader :http
41
+ attr_reader :http, :verification_version, :default_country
30
42
  end
31
43
  end
32
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
@@ -1,24 +1,44 @@
1
1
  require 'ostruct'
2
2
 
3
3
  module AddressFinder
4
- class Cleanse
4
+ class Verification
5
5
 
6
6
  attr_reader :result
7
7
 
8
- def initialize(q:, country: nil, delivered: nil, post_box: 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['rural'] = rural if rural
14
- @params['region_code'] = region_code if region_code
15
- @params['state_codes'] = state_codes if state_codes
16
29
  @params['census'] = census if census
17
30
  @params['domain'] = domain || config.domain if (domain || config.domain)
18
- @params['format'] = 'json'
19
31
  @params['key'] = key || config.api_key
20
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
21
39
  @country = country || config.default_country
40
+
41
+ @params['format'] = 'json'
22
42
  @http = http
23
43
  end
24
44
 
@@ -37,7 +57,7 @@ module AddressFinder
37
57
  attr_writer :result
38
58
 
39
59
  def build_request
40
- @request_uri = "/api/#{country}/address/cleanse?#{encoded_params}"
60
+ @request_uri = "/api/#{country}/address/verification?#{encoded_params}"
41
61
  end
42
62
 
43
63
  def execute_request
@@ -1,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = '1.6.2'
2
+ VERSION = '1.8.1'
3
3
  end
data/lib/addressfinder.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require 'multi_json'
2
2
  require 'addressfinder/version'
3
3
  require 'addressfinder/configuration'
4
- require 'addressfinder/cleanse'
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'
8
9
  require 'addressfinder/address_search'
10
+ require 'addressfinder/address_autocomplete'
9
11
  require 'addressfinder/bulk'
10
12
  require 'addressfinder/errors'
11
13
  require 'addressfinder/util'
@@ -27,8 +29,16 @@ module AddressFinder
27
29
  @configuration ||= AddressFinder::Configuration.new
28
30
  end
29
31
 
30
- def cleanse(args={})
31
- AddressFinder::Cleanse.new(args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
32
+ def cleanse(args={}) # We are keeping this method for backward compatibility
33
+ AddressFinder::Verification.new(args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
34
+ end
35
+
36
+ def verification(args={})
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
32
42
  end
33
43
 
34
44
  def location_search(args={})
@@ -43,12 +53,16 @@ module AddressFinder
43
53
  AddressFinder::AddressSearch.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.results
44
54
  end
45
55
 
56
+ def address_autocomplete(args={})
57
+ AddressFinder::AddressAutocomplete.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.results
58
+ end
59
+
46
60
  def address_info(args={})
47
61
  AddressFinder::AddressInfo.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.result
48
62
  end
49
63
 
50
64
  def bulk(&block)
51
- 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
52
66
  end
53
67
  end
54
68
  end