addressfinder 1.6.2 → 1.7.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: de05727d08ca624896115f6fe76ae68bb3dd36ed99195468153cf982c9af07a0
4
- data.tar.gz: 30ba24d9f052a8884ec5772b8d0d492f1334636674ae29e265ddd3fb105d51dd
3
+ metadata.gz: b611487efde8627017242a6a2c631fb4c617b9c4721ed803f75c85ee466c86e3
4
+ data.tar.gz: 4d3f919d8b9e2217b4911f8b7da663c7793b8f09bd61377474760b69f3818907
5
5
  SHA512:
6
- metadata.gz: 160bee2722353ec131681b401a1ddb92748cb606b4e0bf5d1572a924becf1475a61431ef8382f39df9e361a4133d300714ec029033a631285f62f646c3428e17
7
- data.tar.gz: e1d026848279132f2cd4b2e1ba35061adee84fcac56e89b54fc336b7caff2386e4123a9f5686ea0792dc371fd6a2ba6fa35195d8dfd28a858de43e376cc423f5
6
+ metadata.gz: 7241c2ec121dcd4b3381968bf53394ec8911b0dfe6b1a03436055c739ad50c12180371ebd3ec48209fa82d63d0a0d8fcffeda44389054a132f84bff3edd60153
7
+ data.tar.gz: d1e00512432a0c15f8f19fc4b5a629408d2eab5ee216e9d76176e2574e4071080c1c181d250343da997d58ff6d799d5dd74bb87849fc88296d9e92b422a13326
@@ -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
@@ -1,3 +1,7 @@
1
+ # AddressFinder 1.7.0 (May 4, 2020) #
2
+
3
+ * Add support for Address Autocomplete API (Australia only)
4
+
1
5
  # AddressFinder 1.6.2 (September 23, 2019) #
2
6
 
3
7
  * Add support for an optional state_codes parameter in the Cleanse class
@@ -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 cleansing directories
19
+ RUN mkdir -p $INSTALL_PATH/cleansing/originals
20
+ RUN mkdir -p $INSTALL_PATH/cleansing/cleansed
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/README.md CHANGED
@@ -65,7 +65,12 @@ else
65
65
  end
66
66
  ```
67
67
 
68
- #### Address Autocomplete
68
+ #### Address Search
69
+
70
+ The Address Search API supports the following address sets:
71
+
72
+ * New Zealand addresses
73
+ * Australian addresses from the GNAF dataset only
69
74
 
70
75
  ```ruby
71
76
  begin
@@ -81,6 +86,26 @@ rescue AddressFinder::RequestRejectedError => e
81
86
  end
82
87
  ```
83
88
 
89
+ #### Address Autocomplete
90
+
91
+ The Address Autocomplete API supports the following address sets:
92
+
93
+ * Australian addresses from the GNAF and PAF datasets only
94
+
95
+ ```ruby
96
+ begin
97
+ results = AddressFinder.address_autocomplete(q: '275 high st, bel', au_paf: '1')
98
+ if results.any?
99
+ $stdout.puts "Success: #{results}"
100
+ else
101
+ $stdout.puts "Sorry, there were no address matches"
102
+ end
103
+ rescue AddressFinder::RequestRejectedError => e
104
+ response = JSON.parse(e.body)
105
+ $stdout.puts response['message']
106
+ end
107
+ ```
108
+
84
109
  #### Address Metadata
85
110
 
86
111
  ```ruby
@@ -171,3 +196,13 @@ rescue AddressFinder::RequestRejectedError => e
171
196
  end
172
197
  ```
173
198
 
199
+ ### Testing
200
+
201
+ You can run all the specs with the following command:
202
+
203
+ `docker-compose up`
204
+
205
+ You can `guard` for repeating test runs (while editing new code):
206
+
207
+ `docker-compose run ruby bundle exec guard`
208
+
@@ -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: {}
@@ -6,6 +6,7 @@ require 'addressfinder/location_info'
6
6
  require 'addressfinder/location_search'
7
7
  require 'addressfinder/address_info'
8
8
  require 'addressfinder/address_search'
9
+ require 'addressfinder/address_autocomplete'
9
10
  require 'addressfinder/bulk'
10
11
  require 'addressfinder/errors'
11
12
  require 'addressfinder/util'
@@ -43,6 +44,10 @@ module AddressFinder
43
44
  AddressFinder::AddressSearch.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.results
44
45
  end
45
46
 
47
+ def address_autocomplete(args={})
48
+ AddressFinder::AddressAutocomplete.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.results
49
+ end
50
+
46
51
  def address_info(args={})
47
52
  AddressFinder::AddressInfo.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.result
48
53
  end
@@ -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,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = '1.6.2'
2
+ VERSION = '1.7.0'
3
3
  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
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.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nigel Ramsay
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-09-23 00:00:00.000000000 Z
14
+ date: 2020-05-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -61,14 +61,14 @@ dependencies:
61
61
  requirements:
62
62
  - - "~>"
63
63
  - !ruby/object:Gem::Version
64
- version: '10.4'
64
+ version: '13.0'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - "~>"
70
70
  - !ruby/object:Gem::Version
71
- version: '10.4'
71
+ version: '13.0'
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: webmock
74
74
  requirement: !ruby/object:Gem::Requirement
@@ -89,14 +89,14 @@ dependencies:
89
89
  requirements:
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
- version: 3.0.0
92
+ version: '3.2'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: 3.0.0
99
+ version: '3.2'
100
100
  description: Ruby client library for AddressFinder
101
101
  email:
102
102
  - nigel.ramsay@abletech.co.nz
@@ -110,13 +110,16 @@ files:
110
110
  - ".gitignore"
111
111
  - ".travis.yml"
112
112
  - CHANGELOG.md
113
+ - Dockerfile
113
114
  - Gemfile
114
115
  - Guardfile
115
116
  - LICENSE
116
117
  - README.md
117
118
  - Rakefile
118
119
  - addressfinder.gemspec
120
+ - docker-compose.yml
119
121
  - lib/addressfinder.rb
122
+ - lib/addressfinder/address_autocomplete.rb
120
123
  - lib/addressfinder/address_info.rb
121
124
  - lib/addressfinder/address_search.rb
122
125
  - lib/addressfinder/bulk.rb
@@ -128,6 +131,7 @@ files:
128
131
  - lib/addressfinder/location_search.rb
129
132
  - lib/addressfinder/util.rb
130
133
  - lib/addressfinder/version.rb
134
+ - spec/lib/addressfinder/address_autocomplete_spec.rb
131
135
  - spec/lib/addressfinder/address_info_spec.rb
132
136
  - spec/lib/addressfinder/address_search_spec.rb
133
137
  - spec/lib/addressfinder/bulk_spec.rb
@@ -160,6 +164,7 @@ signing_key:
160
164
  specification_version: 4
161
165
  summary: Provides easy access to AddressFinder APIs
162
166
  test_files:
167
+ - spec/lib/addressfinder/address_autocomplete_spec.rb
163
168
  - spec/lib/addressfinder/address_info_spec.rb
164
169
  - spec/lib/addressfinder/address_search_spec.rb
165
170
  - spec/lib/addressfinder/bulk_spec.rb