addressfinder 1.6.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -2
- data/CHANGELOG.md +19 -0
- data/Dockerfile +28 -0
- data/Guardfile +1 -1
- data/LICENSE.md +15 -0
- data/README.md +42 -5
- data/addressfinder.gemspec +5 -5
- data/docker-compose.yml +11 -0
- data/lib/addressfinder/address_autocomplete.rb +77 -0
- data/lib/addressfinder/bulk.rb +16 -6
- data/lib/addressfinder/configuration.rb +2 -0
- data/lib/addressfinder/util.rb +8 -1
- data/lib/addressfinder/v2/au/verification.rb +96 -0
- data/lib/addressfinder/{cleanse.rb → verification.rb} +28 -7
- data/lib/addressfinder/version.rb +1 -1
- data/lib/addressfinder.rb +18 -4
- data/spec/lib/addressfinder/address_autocomplete_spec.rb +95 -0
- data/spec/lib/addressfinder/bulk_spec.rb +22 -6
- data/spec/lib/addressfinder/v2/au/verification_spec.rb +187 -0
- data/spec/lib/addressfinder/{cleanse_spec.rb → verification_spec.rb} +35 -17
- data/spec/spec_helper.rb +3 -0
- metadata +23 -14
- data/LICENSE +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 472a6d05ac8dfbfd58b7a6b3203848d3f133c0dad187a096e70820e89b1915b0
|
4
|
+
data.tar.gz: 710a21c33cd0d14533a1292e3a847be537fa1a906df75d91d5ca6337d9df6e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47797fa15c8aba466c4bda510479dac8e82b2c64120f2c1b549710e22199e01087028b97b2b640f90538f28931b1a0490ed48a18d1d1faeede9f73a7c153f4bd
|
7
|
+
data.tar.gz: 0c252011d9a9df47448c2e3a4e3e7115665361ec31dd0b394d899b8b7052542f00976ca8aa117ac7a0f59a9e9044b0beccb95a4da2d24b0717dff0b2b036ecfb
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# AddressFinder 1.8.0 (October 2021) #
|
2
|
+
|
3
|
+
* Create a V2 API for verification (Australia)
|
4
|
+
* Remove PAF support from V1 verification API (Australia)
|
5
|
+
* Include API version number in configuration
|
6
|
+
|
7
|
+
# AddressFinder 1.7.1 (June 2, 2021) #
|
8
|
+
|
9
|
+
* Add support for PAF verification
|
10
|
+
* Rename cleanse to verification
|
11
|
+
|
12
|
+
# AddressFinder 1.7.0 (May 4, 2020) #
|
13
|
+
|
14
|
+
* Add support for Address Autocomplete API (Australia only)
|
15
|
+
|
16
|
+
# AddressFinder 1.6.2 (September 23, 2019) #
|
17
|
+
|
18
|
+
* Add support for an optional state_codes parameter in the Cleanse class
|
19
|
+
|
1
20
|
# AddressFinder 1.6.1 (January 14, 2019) #
|
2
21
|
|
3
22
|
* Add support for an optional census 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
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.
|
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.
|
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
|
-
|
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 (`#
|
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.
|
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`
|
data/addressfinder.gemspec
CHANGED
@@ -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@
|
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/
|
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', '~>
|
23
|
+
gem.add_development_dependency 'rake', '~> 13.0'
|
24
24
|
gem.add_development_dependency 'webmock', '~> 1.21'
|
25
|
-
gem.add_development_dependency 'listen', '~> 3.
|
25
|
+
gem.add_development_dependency 'listen', '~> 3.2'
|
26
26
|
end
|
data/docker-compose.yml
ADDED
@@ -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
|
data/lib/addressfinder/bulk.rb
CHANGED
@@ -1,32 +1,42 @@
|
|
1
1
|
module AddressFinder
|
2
2
|
class Bulk
|
3
|
-
def initialize(http:, &block)
|
3
|
+
def initialize(http:, verification_version:, &block)
|
4
4
|
@block = block
|
5
|
+
@verification_version = verification_version
|
5
6
|
@http_config = http
|
6
7
|
end
|
7
8
|
|
8
9
|
def perform
|
9
10
|
http_config.start do |http|
|
10
|
-
block.call ClientProxy.new(http: http)
|
11
|
+
block.call ClientProxy.new(http: http, verification_version: verification_version)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
|
-
attr_reader :block, :http_config
|
17
|
+
attr_reader :block, :verification_version, :http_config
|
17
18
|
|
18
19
|
class ClientProxy
|
19
|
-
def initialize(http:)
|
20
|
+
def initialize(http:, verification_version:)
|
21
|
+
@verification_version = verification_version
|
20
22
|
@http = http
|
21
23
|
end
|
22
24
|
|
23
25
|
def cleanse(args={})
|
24
|
-
AddressFinder::
|
26
|
+
AddressFinder::Verification.new(args.merge(http: http)).perform.result
|
27
|
+
end
|
28
|
+
|
29
|
+
def verification(args={})
|
30
|
+
if verification_version&.downcase == "v2"
|
31
|
+
AddressFinder::V2::Au::Verification.new(args.merge(http: http)).perform.result
|
32
|
+
else
|
33
|
+
AddressFinder::Verification.new(args.merge(http: http)).perform.result
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
28
38
|
|
29
|
-
attr_reader :http
|
39
|
+
attr_reader :http, :verification_version
|
30
40
|
end
|
31
41
|
end
|
32
42
|
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
|
data/lib/addressfinder/util.rb
CHANGED
@@ -6,7 +6,14 @@ module AddressFinder
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.encode_and_join_params(params)
|
9
|
-
|
9
|
+
# URI.encode_www_form(params)
|
10
|
+
params.map do |k,v|
|
11
|
+
if v.is_a? Array
|
12
|
+
v.collect {|e| "#{k}[]=#{encode(e)}" }
|
13
|
+
else
|
14
|
+
"#{k}=#{encode(v)}"
|
15
|
+
end
|
16
|
+
end.join('&')
|
10
17
|
end
|
11
18
|
end
|
12
19
|
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, :country, :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,23 +1,44 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
3
|
module AddressFinder
|
4
|
-
class
|
4
|
+
class Verification
|
5
5
|
|
6
6
|
attr_reader :result
|
7
7
|
|
8
|
-
|
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
29
|
@params['census'] = census if census
|
16
30
|
@params['domain'] = domain || config.domain if (domain || config.domain)
|
17
|
-
@params['format'] = 'json'
|
18
31
|
@params['key'] = key || config.api_key
|
19
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
|
20
39
|
@country = country || config.default_country
|
40
|
+
|
41
|
+
@params['format'] = 'json'
|
21
42
|
@http = http
|
22
43
|
end
|
23
44
|
|
@@ -36,7 +57,7 @@ module AddressFinder
|
|
36
57
|
attr_writer :result
|
37
58
|
|
38
59
|
def build_request
|
39
|
-
@request_uri = "/api/#{country}/address/
|
60
|
+
@request_uri = "/api/#{country}/address/verification?#{encoded_params}"
|
40
61
|
end
|
41
62
|
|
42
63
|
def execute_request
|
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/
|
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::
|
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 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, &block).perform
|
52
66
|
end
|
53
67
|
end
|
54
68
|
end
|
@@ -0,0 +1,95 @@
|
|
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
|
@@ -28,9 +28,9 @@ RSpec.describe AddressFinder::Bulk do
|
|
28
28
|
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
29
29
|
let(:block){
|
30
30
|
Proc.new do |proxy|
|
31
|
-
proxy.
|
32
|
-
proxy.
|
33
|
-
proxy.
|
31
|
+
proxy.verification(q: "1 Willis")
|
32
|
+
proxy.verification(q: "2 Willis")
|
33
|
+
proxy.verification(q: "3 Willis")
|
34
34
|
end
|
35
35
|
}
|
36
36
|
|
@@ -38,7 +38,7 @@ 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', &block).perform
|
42
42
|
end
|
43
43
|
|
44
44
|
it "re-establishes the http connection and continues where we left off when a Net::OpenTimeout, Net::ReadTimeout or SocketError is raised" do
|
@@ -50,8 +50,24 @@ RSpec.describe AddressFinder::Bulk do
|
|
50
50
|
expect(net_http).to receive(:transport_request).once.and_raise(SocketError) # Retry 2 Willis (error)
|
51
51
|
expect(net_http).to receive(:transport_request).exactly(2).and_return(response) # Retry 2 Willis (success) & 3 Willis (success)
|
52
52
|
expect(net_http).to receive(:do_finish).exactly(4).times.and_call_original
|
53
|
-
AddressFinder::Bulk.new(http: http, &block).perform
|
53
|
+
AddressFinder::Bulk.new(http: http, verification_version: 'v2', &block).perform
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with the deprecated cleanse method" do
|
58
|
+
let(:response){ double(:response, body: %Q({"success": true}), code: "200") }
|
59
|
+
let(:block){
|
60
|
+
Proc.new do |proxy|
|
61
|
+
proxy.cleanse(q: "1 Willis")
|
62
|
+
end
|
63
|
+
}
|
64
|
+
|
65
|
+
it "has the same behaviour as the verification method" do
|
66
|
+
expect(net_http).to receive(:do_start).once.and_call_original
|
67
|
+
expect(net_http).to receive(:transport_request).once.and_return(response)
|
68
|
+
expect(net_http).to receive(:do_finish).once.and_call_original
|
69
|
+
AddressFinder::Bulk.new(http: http, verification_version: 'v2', &block).perform
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
57
|
-
end
|
73
|
+
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe AddressFinder::
|
3
|
+
RSpec.describe AddressFinder::Verification do
|
4
4
|
before do
|
5
5
|
AddressFinder.configure do |af|
|
6
6
|
af.api_key = 'XXX'
|
@@ -11,7 +11,7 @@ RSpec.describe AddressFinder::Cleanse do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
let(:
|
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
|
|
@@ -21,7 +21,7 @@ RSpec.describe AddressFinder::Cleanse do
|
|
21
21
|
before do
|
22
22
|
WebMock.allow_net_connect!(net_http_connect_on_start: true)
|
23
23
|
allow(http).to receive(:sleep)
|
24
|
-
allow(
|
24
|
+
allow(verification_module).to receive(:request_uri).and_return("/test/path")
|
25
25
|
expect(http).to_not receive(:re_establish_connection)
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ RSpec.describe AddressFinder::Cleanse do
|
|
29
29
|
WebMock.disable_net_connect!
|
30
30
|
end
|
31
31
|
|
32
|
-
subject(:execute_request){
|
32
|
+
subject(:execute_request){ verification_module.send(:execute_request) }
|
33
33
|
|
34
34
|
it "retries an errored request another time before succeeding" do
|
35
35
|
expect(net_http).to receive(:do_start).twice.and_call_original
|
@@ -62,42 +62,60 @@ RSpec.describe AddressFinder::Cleanse do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe '#build_request' do
|
65
|
-
subject(:request_uri){
|
65
|
+
subject(:request_uri){ verification_module.send(:build_request) }
|
66
66
|
|
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/
|
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
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/
|
76
|
+
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&census=2013&key=XXX&secret=YYY&delivered=true®ion_code=A&format=json') }
|
77
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/
|
82
|
+
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&format=json') }
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with a state codes as an array' do
|
86
|
+
let(:args){ {q: '186 willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
|
87
|
+
|
88
|
+
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'with a reserved character in the query' do
|
92
|
+
let(:args){ {q: '186=willis st', country: 'au', state_codes: ['ACT','NSW'], http: http} }
|
93
|
+
|
94
|
+
it { expect(request_uri).to eq('/api/au/address/verification?q=186%3Dwillis+st&key=XXX&secret=YYY&state_codes[]=ACT&state_codes[]=NSW&format=json') }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'with a state codes as a string' do
|
98
|
+
let(:args){ {q: '186 willis st', country: 'au', state_codes: 'ACT,NSW', http: http} }
|
99
|
+
|
100
|
+
it { expect(request_uri).to eq('/api/au/address/verification?q=186+willis+st&key=XXX&secret=YYY&state_codes=ACT%2CNSW&format=json') }
|
83
101
|
end
|
84
102
|
|
85
103
|
context 'with a key override' do
|
86
104
|
let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
|
87
105
|
|
88
|
-
it { expect(request_uri).to eq('/api/nz/address/
|
106
|
+
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=AAA&secret=YYY&format=json') }
|
89
107
|
end
|
90
108
|
|
91
109
|
context 'with a secret override' do
|
92
110
|
let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
|
93
111
|
|
94
|
-
it { expect(request_uri).to eq('/api/nz/address/
|
112
|
+
it { expect(request_uri).to eq('/api/nz/address/verification?q=186+willis+st&key=XXX&secret=BBB&format=json') }
|
95
113
|
end
|
96
114
|
|
97
115
|
context 'with a domain given' do
|
98
116
|
let(:args){ {q: '123', domain: 'testdomain.com', http: http} }
|
99
117
|
|
100
|
-
it { expect(request_uri).to eq('/api/nz/address/
|
118
|
+
it { expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=testdomain.com&key=XXX&secret=YYY&format=json') }
|
101
119
|
|
102
120
|
context 'given in the AF configuration' do
|
103
121
|
|
@@ -105,7 +123,7 @@ RSpec.describe AddressFinder::Cleanse do
|
|
105
123
|
|
106
124
|
it 'should use the config domain if set' do
|
107
125
|
AddressFinder.configuration.domain = 'anotherdomain.com'
|
108
|
-
expect(request_uri).to eq('/api/nz/address/
|
126
|
+
expect(request_uri).to eq('/api/nz/address/verification?q=123&domain=anotherdomain.com&key=XXX&secret=YYY&format=json')
|
109
127
|
AddressFinder.configuration.domain = nil # set back to nil after
|
110
128
|
end
|
111
129
|
end
|
@@ -116,17 +134,17 @@ RSpec.describe AddressFinder::Cleanse do
|
|
116
134
|
let(:args){ {q: 'ignored', http: nil} }
|
117
135
|
|
118
136
|
before do
|
119
|
-
|
120
|
-
|
137
|
+
verification_module.send('response_body=', body)
|
138
|
+
verification_module.send('response_status=', status)
|
121
139
|
end
|
122
140
|
|
123
|
-
subject(:result){
|
141
|
+
subject(:result){ verification_module.send(:build_result) }
|
124
142
|
|
125
143
|
context 'with a successful nz result' do
|
126
144
|
let(:body){ '{"matched": true, "postal_address": "Texas"}' }
|
127
145
|
let(:status){ '200' }
|
128
146
|
|
129
|
-
it { expect(result.class).to eq(AddressFinder::
|
147
|
+
it { expect(result.class).to eq(AddressFinder::Verification::Result) }
|
130
148
|
|
131
149
|
it { expect(result.matched).to eq(true) }
|
132
150
|
|
@@ -137,7 +155,7 @@ RSpec.describe AddressFinder::Cleanse do
|
|
137
155
|
let(:body){ %Q({"matched": true, "success": true, "address": {"full_address": "Texas"}}) }
|
138
156
|
let(:status){ '200' }
|
139
157
|
|
140
|
-
it { expect(result.class).to eq(AddressFinder::
|
158
|
+
it { expect(result.class).to eq(AddressFinder::Verification::Result) }
|
141
159
|
|
142
160
|
it { expect(result.full_address).to eq("Texas") }
|
143
161
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 1.8.0
|
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:
|
15
|
+
date: 2021-10-25 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: '
|
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: '
|
72
|
+
version: '13.0'
|
72
73
|
- !ruby/object:Gem::Dependency
|
73
74
|
name: webmock
|
74
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,20 +90,21 @@ dependencies:
|
|
89
90
|
requirements:
|
90
91
|
- - "~>"
|
91
92
|
- !ruby/object:Gem::Version
|
92
|
-
version: 3.
|
93
|
+
version: '3.2'
|
93
94
|
type: :development
|
94
95
|
prerelease: false
|
95
96
|
version_requirements: !ruby/object:Gem::Requirement
|
96
97
|
requirements:
|
97
98
|
- - "~>"
|
98
99
|
- !ruby/object:Gem::Version
|
99
|
-
version: 3.
|
100
|
+
version: '3.2'
|
100
101
|
description: Ruby client library for AddressFinder
|
101
102
|
email:
|
102
|
-
- nigel.ramsay@
|
103
|
+
- nigel.ramsay@addressfinder.nz
|
103
104
|
- naiki.pohe@abletech.co.nz
|
104
105
|
- seanarnie@gmail.com
|
105
106
|
- alex@abletech.nz
|
107
|
+
- cassandre.guinut@addressfinder.nz
|
106
108
|
executables: []
|
107
109
|
extensions: []
|
108
110
|
extra_rdoc_files: []
|
@@ -110,33 +112,39 @@ files:
|
|
110
112
|
- ".gitignore"
|
111
113
|
- ".travis.yml"
|
112
114
|
- CHANGELOG.md
|
115
|
+
- Dockerfile
|
113
116
|
- Gemfile
|
114
117
|
- Guardfile
|
115
|
-
- LICENSE
|
118
|
+
- LICENSE.md
|
116
119
|
- README.md
|
117
120
|
- Rakefile
|
118
121
|
- addressfinder.gemspec
|
122
|
+
- docker-compose.yml
|
119
123
|
- lib/addressfinder.rb
|
124
|
+
- lib/addressfinder/address_autocomplete.rb
|
120
125
|
- lib/addressfinder/address_info.rb
|
121
126
|
- lib/addressfinder/address_search.rb
|
122
127
|
- lib/addressfinder/bulk.rb
|
123
|
-
- lib/addressfinder/cleanse.rb
|
124
128
|
- lib/addressfinder/configuration.rb
|
125
129
|
- lib/addressfinder/errors.rb
|
126
130
|
- lib/addressfinder/http.rb
|
127
131
|
- lib/addressfinder/location_info.rb
|
128
132
|
- lib/addressfinder/location_search.rb
|
129
133
|
- lib/addressfinder/util.rb
|
134
|
+
- lib/addressfinder/v2/au/verification.rb
|
135
|
+
- lib/addressfinder/verification.rb
|
130
136
|
- lib/addressfinder/version.rb
|
137
|
+
- spec/lib/addressfinder/address_autocomplete_spec.rb
|
131
138
|
- spec/lib/addressfinder/address_info_spec.rb
|
132
139
|
- spec/lib/addressfinder/address_search_spec.rb
|
133
140
|
- spec/lib/addressfinder/bulk_spec.rb
|
134
|
-
- spec/lib/addressfinder/cleanse_spec.rb
|
135
141
|
- spec/lib/addressfinder/location_info_spec.rb
|
136
142
|
- spec/lib/addressfinder/location_search_spec.rb
|
137
143
|
- spec/lib/addressfinder/util_spec.rb
|
144
|
+
- spec/lib/addressfinder/v2/au/verification_spec.rb
|
145
|
+
- spec/lib/addressfinder/verification_spec.rb
|
138
146
|
- spec/spec_helper.rb
|
139
|
-
homepage: https://github.com/
|
147
|
+
homepage: https://github.com/AddressFinder/addressfinder-ruby
|
140
148
|
licenses:
|
141
149
|
- MIT
|
142
150
|
metadata: {}
|
@@ -155,17 +163,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
163
|
- !ruby/object:Gem::Version
|
156
164
|
version: '0'
|
157
165
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.6.8
|
166
|
+
rubygems_version: 3.0.3
|
160
167
|
signing_key:
|
161
168
|
specification_version: 4
|
162
169
|
summary: Provides easy access to AddressFinder APIs
|
163
170
|
test_files:
|
171
|
+
- spec/lib/addressfinder/address_autocomplete_spec.rb
|
164
172
|
- spec/lib/addressfinder/address_info_spec.rb
|
165
173
|
- spec/lib/addressfinder/address_search_spec.rb
|
166
174
|
- spec/lib/addressfinder/bulk_spec.rb
|
167
|
-
- spec/lib/addressfinder/cleanse_spec.rb
|
168
175
|
- spec/lib/addressfinder/location_info_spec.rb
|
169
176
|
- spec/lib/addressfinder/location_search_spec.rb
|
170
177
|
- spec/lib/addressfinder/util_spec.rb
|
178
|
+
- spec/lib/addressfinder/v2/au/verification_spec.rb
|
179
|
+
- spec/lib/addressfinder/verification_spec.rb
|
171
180
|
- 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
|
-
|