addressfinder 1.11.0 → 1.13.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: 46f5a02e06b4bdc77c39d7b925ac71f901572519461ce39f9d60a89ce7e1643c
4
- data.tar.gz: 72415086c4e0e7b200f12727616b68a9604b559318759e98d3b431f71ca5407a
3
+ metadata.gz: 8e9d77bd22770090ef74d02d1b2135dd3504130442b4a5dfd0de17b90661c468
4
+ data.tar.gz: 91f162b6b301ff9f86c3253f8a37c89c5d5f9f8781dd8e674f49a8f6624cd2ff
5
5
  SHA512:
6
- metadata.gz: 6936156c02c1ed2996aabd83da48d5ac3952fb4ad65c06a4403be957139f9b2dc87146cc9e685b2669c91bba4f96f7dd7b0a7611d481a3628455602d7c1b97ce
7
- data.tar.gz: 46540a8561ef184f0a8b092123166a078ccde5875b30f8688df7f5c98f2c45c5c72bbbf43a59913d59bcf1c946b6d66bc5bcdb141ae941825d7068290a847d35
6
+ metadata.gz: 076b5eb2c9d1200713f7952a631b70852071db5e31321c89c31264b134fd2e4ebb8e40f5820fa97fb9a4c3b43fa0c71b714c656018458a6aa02d5e0d92c20ae6
7
+ data.tar.gz: 651f98846af6d9d31ab6cb135775f6e0cae3855e8d6031aeef342e1a4d7983bd3389432123bd4b7b01b207029632e325fbb73c703e15ba27da2a471e5099a40d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # Addressfinder 1.13.0 (September 2024) #
2
+
3
+ * Add client agent versioning
4
+
5
+ # Addressfinder 1.12.0 (May 2024) #
6
+
7
+ * Add a batch capability with concurrency for Address Verification
8
+ * Include a demo that shows address verification of a CSV file
9
+
1
10
  # Addressfinder 1.11.0 (May 2024) #
2
11
 
3
12
  * Add a batch capability with concurrency for Email Verification
data/README.md CHANGED
@@ -54,21 +54,75 @@ end
54
54
  For available parameters and example responses, see the API documentation pages for [New Zealand](https://addressfinder.nz/docs?utm_source=github&utm_medium=readme&utm_campaign=addressfinder_rubygem&utm_term=New%20Zealand) or [Australia](https://addressfinder.com.au/docs?utm_source=github&utm_medium=readme&utm_campaign=addressfinder_rubygem&utm_term=Australia).
55
55
 
56
56
 
57
- #### Address Verification
57
+ ### Address Verification
58
+
59
+ #### New Zealand addresses
60
+
61
+ To verify a single New Zealand address, use the following method:
62
+
63
+ ```ruby
64
+ result = AddressFinder.address_verification(q: "186 Willis St, Wellington", country: "nz")
65
+
66
+ if result
67
+ $stdout.puts "Success: '#{result.a}'"
68
+ else
69
+ $stdout.puts "Sorry, can't find that address"
70
+ end
71
+ ```
72
+
73
+ You can also verify a batch of New Zealand addresses using the following method.
74
+ We suggest that you send up to 100 addresses in each batch.
75
+
76
+ ```ruby
77
+ addresses = ["186 Willis St, Wellington", "1 Ghuznee St, Te Aro, Wellington 6011", "bad address"]
78
+
79
+ results = AddressFinder.address_verification_nz_batch(addresses: addresses, concurrency: 10)
80
+
81
+ results.each_with_index do |result, index|
82
+ if result
83
+ $stdout.puts "Success: matched '#{addresses[index]}' with '#{result.a}'"
84
+ else
85
+ $stdout.puts "Sorry, can't find address: '#{addresses[index]}'"
86
+ end
87
+ end
88
+ ```
89
+
90
+ There is a demo of processing a CSV file of sample New Zealand address in the [/demo/batch](/demo/verification/) folder.
91
+
92
+ #### Australian addresses
93
+
94
+ To verify a single Australian address, use the following method:
58
95
 
59
96
  ```ruby
60
- result = AddressFinder.verification(q: '186 Willis St, Wellington', country: 'nz')
97
+ result = AddressFinder.address_verification(q: '10/274 Harbour Drive, Coffs Harbour NSW 2450', gnaf: "1", country: 'au')
61
98
 
62
99
  if result
63
- $stdout.puts "Success: #{result.postal}"
100
+ $stdout.puts "Success: #{result.full_address}"
64
101
  else
65
102
  $stdout.puts "Sorry, can't find that address"
66
103
  end
67
104
  ```
68
105
 
69
- **Note:** The deprecated method `cleanse` is still available now but will be dropped in the future.
106
+ You can also verify a batch of Australian addresses using the following method:
107
+ We suggest that you send up to 100 addresses in each batch.
108
+
109
+ ```ruby
110
+ addresses = ["10/274 Harbour Drive, Coffs Harbour NSW 2450", "49 CORNISH ST, COBAR NSW 2835", "bad address"]
111
+
112
+ results = AddressFinder.address_verification_au_batch(addresses: addresses, gnaf: "1", concurrency: 10)
113
+
114
+ results.each_with_index do |result, index|
115
+ if result
116
+ $stdout.puts "Success: matched '#{addresses[index]}' with '#{result.a}'"
117
+ else
118
+ $stdout.puts "Sorry, can't find address: '#{addresses[index]}'"
119
+ end
120
+ end
121
+ ```
122
+
123
+ There is a demo of processing a CSV file of sample Australian address in the [/demo/batch](/demo/verification/) folder.
70
124
 
71
- #### Address Search
125
+ ### Address Search
72
126
 
73
127
  The Address Search API supports the following address sets:
74
128
 
@@ -89,7 +143,7 @@ rescue AddressFinder::RequestRejectedError => e
89
143
  end
90
144
  ```
91
145
 
92
- #### Address Autocomplete
146
+ ### Address Autocomplete
93
147
 
94
148
  The Address Autocomplete API supports the following address sets:
95
149
 
@@ -109,7 +163,7 @@ rescue AddressFinder::RequestRejectedError => e
109
163
  end
110
164
  ```
111
165
 
112
- #### Address Metadata
166
+ ### Address Metadata
113
167
 
114
168
  ```ruby
115
169
  begin
@@ -125,7 +179,7 @@ rescue AddressFinder::RequestRejectedError => e
125
179
  end
126
180
  ```
127
181
 
128
- #### Location Autocomplete
182
+ ### Location Autocomplete
129
183
 
130
184
  ```ruby
131
185
  begin
@@ -141,7 +195,7 @@ rescue AddressFinder::RequestRejectedError => e
141
195
  end
142
196
  ```
143
197
 
144
- #### Location Metadata
198
+ ### Location Metadata
145
199
 
146
200
  ```ruby
147
201
  begin
@@ -157,7 +211,7 @@ rescue AddressFinder::RequestRejectedError => e
157
211
  end
158
212
  ```
159
213
 
160
- #### Email Verification
214
+ ### Email Verification
161
215
 
162
216
  This example shows how to request verification of a single email address.
163
217
 
@@ -191,7 +245,7 @@ end
191
245
  The emails will be verified concurrently, and returned in the same order in
192
246
  which they were provided.
193
247
 
194
- #### Phone Verification
248
+ ### Phone Verification
195
249
 
196
250
  ```ruby
197
251
  begin
@@ -205,29 +259,7 @@ end
205
259
 
206
260
  ## Advanced Usage
207
261
 
208
- #### Bulk Operations
209
-
210
- If you have a series of API requests, you can use the
211
- bulk method to re-use the HTTP connection.
212
-
213
- **Note:** The bulk method is currently only available for Address Verification, Email Verification and Phone Verification (`#verification`, `#email_verification`, `#phone_verifiction`).
214
-
215
- ```ruby
216
- AddressFinder.bulk do |af|
217
- CSV.foreach('auckland_addresses.csv') do |row|
218
- result = af.verification(q: row[0], region_code: '1')
219
-
220
- if result
221
- $stdout.puts "Success: #{result.postal}"
222
- else
223
- $stdout.puts "Sorry, can't find that address"
224
- end
225
- end
226
- end
227
- ```
228
-
229
-
230
- #### Key and Secret override
262
+ ### Key and Secret override
231
263
 
232
264
  What if you want to use another account for a specific query? You can override the `api_key` and `api_secret`.
233
265
 
@@ -245,7 +277,7 @@ rescue AddressFinder::RequestRejectedError => e
245
277
  end
246
278
  ```
247
279
 
248
- ### Testing
280
+ ## Testing
249
281
 
250
282
  You can run all the specs with the following command:
251
283
 
@@ -0,0 +1,68 @@
1
+ # Address Verification demo using the batch functions
2
+
3
+ In this folder there are two Ruby scripts that demonstrate how to use the
4
+ address verification functions for New Zealand and Australia. These functions
5
+ seek to process a CSV file of sample addresses, and generate a CSV stream on
6
+ standard output.
7
+
8
+ ## Usage instructions
9
+
10
+ ```
11
+ bundle exec ruby process_nz_address_csv.rb <input-file.csv>
12
+ ```
13
+
14
+ or
15
+
16
+ ```
17
+ bundle exec ruby process_au_address_csv.rb <input-file.csv>
18
+ ```
19
+
20
+ We have provided two sample CSV files for demonstration purposes. The files contain a
21
+ selection of various addresses for each country.
22
+
23
+ You will also need to set the following environment variables:
24
+
25
+ - `AF_KEY` - your API key for accessing the Addressfinder API
26
+ - `AF_SECRET` - the API secret corresponding to your API key
27
+
28
+ You can obtain an API key by registering for a free trial account at https://addressfinder.com/
29
+
30
+ ## Example execution
31
+
32
+ Processing a CSV file of New Zealand address records:
33
+
34
+ ```
35
+ > export AF_KEY=XXXXXXXXXXXXXXX
36
+ > export AF_SECRET=YYYYYYYYYYYYYYY
37
+ > bundle exec ruby process_nz_address_csv.rb sample_addresses_nz.csv
38
+ address_id,address_query,address_query_length,full_address,address_id
39
+ 1,133 wilton road wilton wellington,33,"133 Wilton Road, Wilton, Wellington 6012",2-.F.1W.v.Torm
40
+ 2,1 ghuznee st te aro wellington 6011,35,"1 Ghuznee Street, Te Aro, Wellington 6011",2-2eNwG1oBJExni2nUFJm1cW
41
+ 3,40 severne st springlands blemnheim,35,"40 Severne Street, Yelverton, Blenheim 7201",2-.7.7.E.4$2
42
+ 4,hahaha,6,"",""
43
+ 5,"14 Espin Crescent, Karori, Wellington 6012",42,"14 Espin Crescent, Karori, Wellington 6012",2-.F.1W.J.tx4
44
+ 6,"Level 7, 45 Johnston Street, Wellington Central, Wellington 6011",64,"Level 7, 45 Johnston Street, Wellington Central, Wellington 6011",3-.2u
45
+ # ...
46
+ ```
47
+
48
+ Processing a CSV file of Australian address records:
49
+
50
+ ```
51
+ > bundle exec ruby process_au_address_csv.rb sample_addresses_au.csv
52
+ address_id,address_query,address_query_length,full_address,address_id
53
+ 1,"10/274 harbour drive, coffs harbour NSW 2450",44,"Unit 10, 274 Harbour Drive, COFFS HARBOUR NSW 2450",670cd8c3-b883-ee24-2874-74440e515b80
54
+ 2,"9/274 harbour drive, coffs harbour NSW 2450",43,"Unit 9, 274 Harbour Drive, COFFS HARBOUR NSW 2450",42ae5625-d679-266b-5d66-5ece6bbfb179
55
+ 3,"8/274 harbour drive, coffs harbour NSW 2450",43,"Unit 8, 274 Harbour Drive, COFFS HARBOUR NSW 2450",447a0952-c354-80de-712f-e3458f71bf1a
56
+ 4,hahaha,6,"",""
57
+ 5,"Unit 56, Level C, 12 Limburg Way, GREENWAY ACT 2900",51,"Unit 56, Level C, 12 Limburg Way, GREENWAY ACT 2900",275aa5ff-401e-3cd8-9de9-e9c36eb262cb
58
+ # ...
59
+ ```
60
+
61
+ ## Code example
62
+
63
+ Take close look at the function `process_csv` which manages the reading of the CSV file and the creation of
64
+ each block. In the example, fairly small block sizes are used, but you will likely want to use a larger size
65
+ of around 100 records.
66
+
67
+ The `process_block` function is responsible for making the API call and processing the response. The response
68
+ is used to compose each CSV line, which is written to `$stdout`.
@@ -44,9 +44,7 @@ module AddressFinder
44
44
  end
45
45
 
46
46
  def execute_request
47
- request = Net::HTTP::Get.new(request_uri)
48
-
49
- response = http.request(request)
47
+ response = http.request(request_uri)
50
48
 
51
49
  self.response_body = response.body
52
50
  self.response_status = response.code
@@ -37,9 +37,7 @@ module AddressFinder
37
37
  end
38
38
 
39
39
  def execute_request
40
- request = Net::HTTP::Get.new(request_uri)
41
-
42
- response = http.request(request)
40
+ response = http.request(request_uri)
43
41
 
44
42
  self.response_body = response.body
45
43
  self.response_status = response.code
@@ -37,9 +37,7 @@ module AddressFinder
37
37
  end
38
38
 
39
39
  def execute_request
40
- request = Net::HTTP::Get.new(request_uri)
41
-
42
- response = http.request(request)
40
+ response = http.request(request_uri)
43
41
 
44
42
  self.response_body = response.body
45
43
  self.response_status = response.code
@@ -14,6 +14,7 @@ module AddressFinder
14
14
  attr_accessor :domain
15
15
  attr_accessor :retries
16
16
  attr_accessor :retry_delay
17
+ attr_accessor :ca
17
18
 
18
19
  def initialize
19
20
  self.hostname = 'api.addressfinder.io'
@@ -23,6 +24,7 @@ module AddressFinder
23
24
  self.retry_delay = 5
24
25
  self.default_country = 'nz'
25
26
  self.verification_version = 'v1'
27
+ self.ca = "Ruby/#{AddressFinder::VERSION}"
26
28
  end
27
29
  end
28
30
  end
@@ -15,11 +15,15 @@ module AddressFinder
15
15
  end
16
16
  end
17
17
 
18
- def request(args)
18
+ def request(request_uri)
19
19
  retries = 0
20
20
  begin
21
21
  re_establish_connection if @connection_is_bad
22
- net_http.request(args)
22
+
23
+ uri = build_uri(request_uri)
24
+ request = Net::HTTP::Get.new(uri)
25
+
26
+ net_http.request(request)
23
27
  rescue Net::ReadTimeout, Net::OpenTimeout, SocketError => error
24
28
  if retries < config.retries
25
29
  retries += 1
@@ -40,6 +44,19 @@ module AddressFinder
40
44
  net_http.start
41
45
  end
42
46
 
47
+ def build_uri(request_uri)
48
+ uri = URI(request_uri)
49
+ encoded_ca = URI.encode_www_form_component(config.ca)
50
+
51
+ if uri.query
52
+ uri.query += "&ca=#{encoded_ca}"
53
+ else
54
+ uri.query = "ca=#{encoded_ca}"
55
+ end
56
+
57
+ uri.to_s
58
+ end
59
+
43
60
  def net_http
44
61
  @net_http ||= begin
45
62
  http = Net::HTTP.new(config.hostname, config.port, config.proxy_host,
@@ -38,9 +38,7 @@ module AddressFinder
38
38
  end
39
39
 
40
40
  def execute_request
41
- request = Net::HTTP::Get.new(request_uri)
42
-
43
- response = http.request(request)
41
+ response = http.request(request_uri)
44
42
 
45
43
  self.response_body = response.body
46
44
  self.response_status = response.code
@@ -38,9 +38,7 @@ module AddressFinder
38
38
  end
39
39
 
40
40
  def execute_request
41
- request = Net::HTTP::Get.new(request_uri)
42
-
43
- response = http.request(request)
41
+ response = http.request(request_uri)
44
42
 
45
43
  self.response_body = response.body
46
44
  self.response_status = response.code
@@ -20,12 +20,12 @@ module AddressFinder
20
20
  build_request
21
21
  execute_request
22
22
  build_result
23
-
23
+
24
24
  self
25
25
  end
26
26
 
27
27
  private
28
-
28
+
29
29
  attr_reader :request_uri, :params, :http, :path
30
30
  attr_accessor :response_body, :response_status
31
31
  attr_writer :result
@@ -33,20 +33,18 @@ module AddressFinder
33
33
  def build_request
34
34
  @request_uri = "#{path}?#{encoded_params}"
35
35
  end
36
-
36
+
37
37
  def encoded_params
38
38
  Util.encode_and_join_params(params)
39
39
  end
40
-
40
+
41
41
  def execute_request
42
- request = Net::HTTP::Get.new(request_uri)
43
-
44
- response = http.request(request)
45
-
42
+ response = http.request(request_uri)
43
+
46
44
  self.response_body = response.body
47
45
  self.response_status = response.code
48
46
  end
49
-
47
+
50
48
  def build_result
51
49
  case response_status
52
50
  when '200'
@@ -55,15 +53,15 @@ module AddressFinder
55
53
  raise AddressFinder::RequestRejectedError.new(response_status, response_body)
56
54
  end
57
55
  end
58
-
56
+
59
57
  def response_hash
60
58
  @_response_hash ||= MultiJson.load(response_body)
61
59
  end
62
-
60
+
63
61
  def config
64
62
  @_config ||= AddressFinder.configuration
65
63
  end
66
-
64
+
67
65
  class Result < OpenStruct
68
66
  end
69
67
  end
@@ -0,0 +1,70 @@
1
+ module AddressFinder
2
+ module V1
3
+ module Nz
4
+ class BatchVerification
5
+ attr_reader :addresses, :results
6
+
7
+ # Verifies an array of addresses using concurrency to reduce the execution time.
8
+ #
9
+ # The results of the verification are stored in the `results` attribute, in the same order
10
+ # in which they were supplied.
11
+ #
12
+ # @param [Array<String>] addresses array of address query strings
13
+ # @param [AddressFinder::HTTP] http HTTP connection helper
14
+ # @param [Integer] concurrency How many threads to use for verification
15
+ # @param [Hash] args Any additional arguments that will be passed onto the Address Verification API
16
+ def initialize(addresses:, http: nil, concurrency: 2, **args)
17
+ @addresses = addresses
18
+ @concurrency = concurrency
19
+ @http = http
20
+ @args = args
21
+ end
22
+
23
+ def perform
24
+ confirm_concurrency_level
25
+ verify_each_address_concurrently
26
+
27
+ self
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :args, :concurrency, :http
33
+
34
+ MAX_CONCURRENCY_LEVEL = 5
35
+
36
+ def confirm_concurrency_level
37
+ return unless @concurrency > MAX_CONCURRENCY_LEVEL
38
+
39
+ warn "WARNING: Concurrency level of #{@concurrency} is higher than the maximum of #{MAX_CONCURRENCY_LEVEL}. Using #{MAX_CONCURRENCY_LEVEL}."
40
+ @concurrency = MAX_CONCURRENCY_LEVEL
41
+ end
42
+
43
+ def verify_each_address_concurrently
44
+ @results = Concurrent::Array.new(addresses.length)
45
+
46
+ pool = Concurrent::FixedThreadPool.new(concurrency)
47
+
48
+ addresses.each_with_index do |address, index_of_address|
49
+ # Start a new thread for each task
50
+ pool.post do
51
+ verify_address(address, index_of_address)
52
+ end
53
+ end
54
+
55
+ ## Shutdown the pool and wait for all tasks to complete
56
+ pool.shutdown
57
+ pool.wait_for_termination
58
+ end
59
+
60
+ # Verifies a single address, and writes the result into @results
61
+ def verify_address(address, index_of_address)
62
+ @results[index_of_address] =
63
+ AddressFinder::Verification.new(q: address, http: http.clone, **args).perform.result
64
+ rescue AddressFinder::RequestRejectedError => e
65
+ @results[index_of_address] = OpenStruct.new(success: false, body: e.body, status: e.status)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,70 @@
1
+ module AddressFinder
2
+ module V2
3
+ module Au
4
+ class BatchVerification
5
+ attr_reader :addresses, :results
6
+
7
+ # Verifies an array of addresses using concurrency to reduce the execution time.
8
+ #
9
+ # The results of the verification are stored in the `results` attribute, in the same order
10
+ # in which they were supplied.
11
+ #
12
+ # @param [Array<String>] addresses array of address query strings
13
+ # @param [AddressFinder::HTTP] http HTTP connection helper
14
+ # @param [Integer] concurrency How many threads to use for verification
15
+ # @param [Hash] args Any additional arguments that will be passed onto the Address Verification API
16
+ def initialize(addresses:, http: nil, concurrency: 2, **args)
17
+ @addresses = addresses
18
+ @concurrency = concurrency
19
+ @http = http
20
+ @args = args
21
+ end
22
+
23
+ def perform
24
+ confirm_concurrency_level
25
+ verify_each_address_concurrently
26
+
27
+ self
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :args, :concurrency, :http
33
+
34
+ MAX_CONCURRENCY_LEVEL = 5
35
+
36
+ def confirm_concurrency_level
37
+ return unless @concurrency > MAX_CONCURRENCY_LEVEL
38
+
39
+ warn "WARNING: Concurrency level of #{@concurrency} is higher than the maximum of #{MAX_CONCURRENCY_LEVEL}. Using #{MAX_CONCURRENCY_LEVEL}."
40
+ @concurrency = MAX_CONCURRENCY_LEVEL
41
+ end
42
+
43
+ def verify_each_address_concurrently
44
+ @results = Concurrent::Array.new(addresses.length)
45
+
46
+ pool = Concurrent::FixedThreadPool.new(concurrency)
47
+
48
+ addresses.each_with_index do |address, index_of_address|
49
+ # Start a new thread for each task
50
+ pool.post do
51
+ verify_address(address, index_of_address)
52
+ end
53
+ end
54
+
55
+ ## Shutdown the pool and wait for all tasks to complete
56
+ pool.shutdown
57
+ pool.wait_for_termination
58
+ end
59
+
60
+ # Verifies a single address, and writes the result into @results
61
+ def verify_address(address, index_of_address)
62
+ @results[index_of_address] =
63
+ AddressFinder::V2::Au::Verification.new(q: address, http: http.clone, **args).perform.result
64
+ rescue AddressFinder::RequestRejectedError => e
65
+ @results[index_of_address] = OpenStruct.new(success: false, body: e.body, status: e.status)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,10 +1,9 @@
1
- require 'ostruct'
1
+ require "ostruct"
2
2
 
3
3
  module AddressFinder
4
4
  module V2
5
5
  module Au
6
6
  class Verification
7
-
8
7
  attr_reader :result
9
8
 
10
9
  # V2 AU expected attributes:
@@ -19,21 +18,22 @@ module AddressFinder
19
18
  # params[:gps] --> nil or '1',
20
19
  # params[:extended] --> nil or '1',
21
20
  # 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)
21
+ def initialize(q:, http:, post_box: nil, census: nil, domain: nil, key: nil, secret: nil, paf: nil, gnaf: nil,
22
+ gps: nil, state_codes: nil, extended: nil, country: nil)
23
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'
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
37
  @http = http
38
38
  end
39
39
 
@@ -56,23 +56,17 @@ module AddressFinder
56
56
  end
57
57
 
58
58
  def execute_request
59
- request = Net::HTTP::Get.new(request_uri)
60
-
61
- response = http.request(request)
59
+ response = http.request(request_uri)
62
60
 
63
61
  self.response_body = response.body
64
62
  self.response_status = response.code
65
63
  end
66
64
 
67
65
  def build_result
68
- if response_status != '200'
69
- raise AddressFinder::RequestRejectedError.new(@response_status, @response_body)
70
- end
66
+ raise AddressFinder::RequestRejectedError.new(@response_status, @response_body) if response_status != "200"
71
67
 
72
- if response_hash['matched']
73
- self.result = Result.new(response_hash['address'] || response_hash)
74
- else
75
- self.result = nil
68
+ self.result = if response_hash["matched"]
69
+ Result.new(response_hash["address"] || response_hash)
76
70
  end
77
71
  end
78
72
 
@@ -92,5 +86,5 @@ module AddressFinder
92
86
  end
93
87
  end
94
88
  end
95
- end
89
+ end
96
90
  end
@@ -1,8 +1,7 @@
1
- require 'ostruct'
1
+ require "ostruct"
2
2
 
3
3
  module AddressFinder
4
4
  class Verification
5
-
6
5
  attr_reader :result
7
6
 
8
7
  # AU V1 expected attributes:
@@ -21,24 +20,25 @@ module AddressFinder
21
20
  # params[:domain] --> used for reporting does not affect query results
22
21
  # params[:key] --> unique AddressFinder public key
23
22
  # 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:)
23
+ def initialize(q:, http:, post_box: nil, census: nil, domain: nil, key: nil, secret: nil, state_codes: nil,
24
+ delivered: nil, rural: nil, region_code: nil, country: nil)
25
25
  @params = {}
26
26
  # Common to AU and NZ
27
- @params['q'] = q
28
- @params['post_box'] = post_box if post_box
29
- @params['census'] = census if census
30
- @params['domain'] = domain || config.domain if (domain || config.domain)
31
- @params['key'] = key || config.api_key
32
- @params['secret'] = secret || config.api_secret
27
+ @params["q"] = q
28
+ @params["post_box"] = post_box if post_box
29
+ @params["census"] = census if census
30
+ @params["domain"] = domain || config.domain if domain || config.domain
31
+ @params["key"] = key || config.api_key
32
+ @params["secret"] = secret || config.api_secret
33
33
  # AU params
34
- @params['state_codes'] = state_codes if state_codes
34
+ @params["state_codes"] = state_codes if state_codes
35
35
  # NZ params
36
- @params['delivered'] = delivered if delivered
37
- @params['rural'] = rural if rural
38
- @params['region_code'] = region_code if region_code
36
+ @params["delivered"] = delivered if delivered
37
+ @params["rural"] = rural if rural
38
+ @params["region_code"] = region_code if region_code
39
39
  @country = country || config.default_country
40
40
 
41
- @params['format'] = 'json'
41
+ @params["format"] = "json"
42
42
  @http = http
43
43
  end
44
44
 
@@ -61,23 +61,17 @@ module AddressFinder
61
61
  end
62
62
 
63
63
  def execute_request
64
- request = Net::HTTP::Get.new(request_uri)
65
-
66
- response = http.request(request)
64
+ response = http.request(request_uri)
67
65
 
68
66
  self.response_body = response.body
69
67
  self.response_status = response.code
70
68
  end
71
69
 
72
70
  def build_result
73
- if response_status != '200'
74
- raise AddressFinder::RequestRejectedError.new(@response_status, @response_body)
75
- end
71
+ raise AddressFinder::RequestRejectedError.new(@response_status, @response_body) if response_status != "200"
76
72
 
77
- if response_hash['matched']
78
- self.result = Result.new(response_hash['address'] || response_hash)
79
- else
80
- self.result = nil
73
+ self.result = if response_hash["matched"]
74
+ Result.new(response_hash["address"] || response_hash)
81
75
  end
82
76
  end
83
77
 
@@ -1,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = "1.11.0"
2
+ VERSION = "1.13.0"
3
3
  end
data/lib/addressfinder.rb CHANGED
@@ -4,7 +4,9 @@ require "concurrent/array"
4
4
  require "addressfinder/version"
5
5
  require "addressfinder/configuration"
6
6
  require "addressfinder/verification"
7
+ require "addressfinder/v1/nz/batch_verification"
7
8
  require "addressfinder/v2/au/verification"
9
+ require "addressfinder/v2/au/batch_verification"
8
10
  require "addressfinder/location_info"
9
11
  require "addressfinder/location_search"
10
12
  require "addressfinder/address_info"
@@ -22,12 +24,12 @@ module AddressFinder
22
24
  class << self
23
25
  def configure(config_hash = nil)
24
26
  config_hash&.each do |k, v|
25
- if configuration.respond_to?(:"#{k}=")
26
- begin
27
- configuration.send(:"#{k}=", v)
28
- rescue
29
- nil
30
- end
27
+ next unless configuration.respond_to?(:"#{k}=")
28
+
29
+ begin
30
+ configuration.send(:"#{k}=", v)
31
+ rescue
32
+ nil
31
33
  end
32
34
  end
33
35
 
@@ -38,11 +40,7 @@ module AddressFinder
38
40
  @configuration ||= AddressFinder::Configuration.new
39
41
  end
40
42
 
41
- def cleanse(args = {}) # We are keeping this method for backward compatibility
42
- AddressFinder::Verification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
43
- end
44
-
45
- def verification(args = {})
43
+ def address_verification(args = {})
46
44
  if (args[:country] || configuration.default_country) == "au" && configuration.verification_version&.downcase == "v2"
47
45
  AddressFinder::V2::Au::Verification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
48
46
  else
@@ -50,6 +48,22 @@ module AddressFinder
50
48
  end
51
49
  end
52
50
 
51
+ def verification(args = {}) # We are keeping this method for backward compatibility
52
+ address_verification(args)
53
+ end
54
+
55
+ def cleanse(args = {}) # We are keeping this method for backward compatibility
56
+ address_verification(args)
57
+ end
58
+
59
+ def address_verification_nz_batch(args = {})
60
+ AddressFinder::V1::Nz::BatchVerification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.results
61
+ end
62
+
63
+ def address_verification_au_batch(args = {})
64
+ AddressFinder::V2::Au::BatchVerification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.results
65
+ end
66
+
53
67
  def location_search(args = {})
54
68
  AddressFinder::LocationSearch.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.results
55
69
  end
@@ -83,7 +97,9 @@ module AddressFinder
83
97
  end
84
98
 
85
99
  def bulk(&block)
86
- AddressFinder::Bulk.new(http: AddressFinder::HTTP.new(configuration), verification_version: configuration.verification_version, default_country: configuration.default_country, &block).perform
100
+ AddressFinder::Bulk.new(
101
+ http: AddressFinder::HTTP.new(configuration), verification_version: configuration.verification_version, default_country: configuration.default_country, &block
102
+ ).perform
87
103
  end
88
104
  end
89
105
  end
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.11.0
4
+ version: 1.13.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: 2024-05-05 00:00:00.000000000 Z
15
+ date: 2024-09-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: multi_json
@@ -155,6 +155,7 @@ files:
155
155
  - LICENSE.md
156
156
  - README.md
157
157
  - addressfinder.gemspec
158
+ - demo/verification/README.md
158
159
  - lib/addressfinder.rb
159
160
  - lib/addressfinder/address_autocomplete.rb
160
161
  - lib/addressfinder/address_info.rb
@@ -169,7 +170,9 @@ files:
169
170
  - lib/addressfinder/v1/base.rb
170
171
  - lib/addressfinder/v1/email/batch_verification.rb
171
172
  - lib/addressfinder/v1/email/verification.rb
173
+ - lib/addressfinder/v1/nz/batch_verification.rb
172
174
  - lib/addressfinder/v1/phone/verification.rb
175
+ - lib/addressfinder/v2/au/batch_verification.rb
173
176
  - lib/addressfinder/v2/au/verification.rb
174
177
  - lib/addressfinder/verification.rb
175
178
  - lib/addressfinder/version.rb
@@ -192,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
195
  - !ruby/object:Gem::Version
193
196
  version: '0'
194
197
  requirements: []
195
- rubygems_version: 3.4.6
198
+ rubygems_version: 3.4.13
196
199
  signing_key:
197
200
  specification_version: 4
198
201
  summary: Provides easy access to Addressfinder APIs