addressfinder 1.9.1 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38a7d7f3a73582add0efdff05e575601015d7530e87a475b720c14f150455b97
4
- data.tar.gz: 0230c13f16b6a48eecb940baf8a344d64fc832d9bc508649c4ff215675c4b2ae
3
+ metadata.gz: 85227fdfa94c38218cb23aa0f2d637270f5fba6f1e3101c1303404de467e4c72
4
+ data.tar.gz: 44987ff360e797b67691494785388fcdd51c12f08cbc925eb445ac3251a20102
5
5
  SHA512:
6
- metadata.gz: edcb4c8d68f2162090406e40dd9d624f73dff86ed3ebff5dad7d1937715df402ed0a2d568165feb286ba1b703dea73f112f0f1a27604bb90a1aad24477534062
7
- data.tar.gz: ead725e66314a35081276a6f5e2d37c23a709f99af3920aad208a76da711cc45d83e9d067493079b25251db81795ccff98a4ff3a4d05f5f8017346c34aee4b47
6
+ metadata.gz: 132e29b1da5bad8864aa136edfbb37cae2925610a767465cd3c027b70ec61492b9c55ed884e628b85fa87191d86c128153ba5f7476c8728ac09e866e131d7fc9
7
+ data.tar.gz: 6b64c5fd1de404b594e3e077b62bb3104e0aa9cf17e2f50a6ae2c688e449ce5dfd7cf214f677d8add6e32477d4dc562ab8cbc2a49031b9b37310aa3bdf1acfaf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # AddressFinder 1.10.0 (August 2023) #
2
+
3
+ * Add support for Email Verification
4
+ * Add support for Phone Verification
5
+ * Add support for Bulk Email Verification
6
+ * Add support for Bulk Phone Verification
7
+
1
8
  # AddressFinder 1.9.1 (October 2022) #
2
9
 
3
10
  * Add missing kwarg `**` for ruby 3
data/README.md CHANGED
@@ -157,6 +157,28 @@ rescue AddressFinder::RequestRejectedError => e
157
157
  end
158
158
  ```
159
159
 
160
+ #### Email Verification
161
+ ```ruby
162
+ begin
163
+ result = AddressFinder.email_verification(email: 'john.doe')
164
+ $stdout.puts "This email address is verified: #{result.is_verified}"
165
+ rescue AddressFinder::RequestRejectedError => e
166
+ response = JSON.parse(e.body)
167
+ $stdout.puts response['message']
168
+ end
169
+ ```
170
+
171
+ #### Phone Verification
172
+ ```ruby
173
+ begin
174
+ result = AddressFinder.phone_verification(phone_number: '1800 152 363', default_country_code: 'AU')
175
+ $stdout.puts "This phone number is verified: #{result.is_verified}"
176
+ rescue AddressFinder::RequestRejectedError => e
177
+ response = JSON.parse(e.body)
178
+ $stdout.puts response['message']
179
+ end
180
+ ```
181
+
160
182
  ## Advanced Usage
161
183
 
162
184
  #### Bulk Operations
@@ -164,7 +186,7 @@ end
164
186
  If you have a series of API requests, you can use the
165
187
  bulk method to re-use the HTTP connection.
166
188
 
167
- **Note:** The bulk method is currently only available for Address Verification (`#verification`).
189
+ **Note:** The bulk method is currently only available for Address Verification, Email Verification and Phone Verification (`#verification`, `#email_verification`, `#phone_verifiction`).
168
190
 
169
191
  ```ruby
170
192
  AddressFinder.bulk do |af|
@@ -11,13 +11,14 @@ Gem::Specification.new do |gem|
11
11
  gem.summary = 'Provides easy access to AddressFinder APIs'
12
12
  gem.homepage = 'https://github.com/AddressFinder/addressfinder-ruby'
13
13
 
14
- gem.files = `git ls-files`.split($/)
14
+ gem.files = `git ls-files`.split($/).select{|f| f.match(%r{^lib|\.gemspec$|\.md$})}
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(spec|features)/})
17
17
  gem.require_paths = ['lib']
18
18
 
19
- gem.required_ruby_version = '>= 2.1'
19
+ gem.required_ruby_version = '>= 2.6'
20
20
  gem.add_dependency 'multi_json', '~> 1.15'
21
+
21
22
  gem.add_development_dependency 'guard-rspec', '~> 4.7'
22
23
  gem.add_development_dependency 'listen', '~> 3.7'
23
24
  gem.add_development_dependency 'rake', '~> 13.0'
@@ -36,6 +36,14 @@ module AddressFinder
36
36
  end
37
37
  end
38
38
 
39
+ def email_verification(args={})
40
+ AddressFinder::V1::Email::Verification.new(**args.merge(http: http)).perform.result
41
+ end
42
+
43
+ def phone_verification(args={})
44
+ AddressFinder::V1::Phone::Verification.new(**args.merge(http: http)).perform.result
45
+ end
46
+
39
47
  private
40
48
 
41
49
  attr_reader :http, :verification_version, :default_country
@@ -0,0 +1,71 @@
1
+ require 'ostruct'
2
+
3
+ module AddressFinder
4
+ module V1
5
+ class Base
6
+ attr_reader :result
7
+
8
+ def initialize(params:, path:, http:)
9
+ @params = params
10
+ @params[:domain] ||= config.domain if config.domain
11
+ @params[:key] ||= config.api_key
12
+ @params[:secret] ||= config.api_secret
13
+ @params[:format] ||= 'json'
14
+
15
+ @path = path
16
+ @http = http
17
+ end
18
+
19
+ def perform
20
+ build_request
21
+ execute_request
22
+ build_result
23
+
24
+ self
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :request_uri, :params, :http, :path
30
+ attr_accessor :response_body, :response_status
31
+ attr_writer :result
32
+
33
+ def build_request
34
+ @request_uri = "#{path}?#{encoded_params}"
35
+ end
36
+
37
+ def encoded_params
38
+ Util.encode_and_join_params(params)
39
+ end
40
+
41
+ def execute_request
42
+ request = Net::HTTP::Get.new(request_uri)
43
+
44
+ response = http.request(request)
45
+
46
+ self.response_body = response.body
47
+ self.response_status = response.code
48
+ end
49
+
50
+ def build_result
51
+ case response_status
52
+ when '200'
53
+ self.result = Result.new(response_hash)
54
+ else
55
+ raise AddressFinder::RequestRejectedError.new(response_status, response_body)
56
+ end
57
+ end
58
+
59
+ def response_hash
60
+ @_response_hash ||= MultiJson.load(response_body)
61
+ end
62
+
63
+ def config
64
+ @_config ||= AddressFinder.configuration
65
+ end
66
+
67
+ class Result < OpenStruct
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,16 @@
1
+ require 'addressfinder/v1/base'
2
+
3
+ module AddressFinder
4
+ module V1
5
+ module Email
6
+ class Verification < AddressFinder::V1::Base
7
+ attr_reader :result
8
+
9
+ def initialize(email:, http:, **args)
10
+ params = {email: email}.merge(args)
11
+ super(params: params, path: "/api/email/v1/verification", http: http)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'addressfinder/v1/base'
2
+
3
+ module AddressFinder
4
+ module V1
5
+ module Phone
6
+ class Verification < AddressFinder::V1::Base
7
+ attr_reader :result
8
+
9
+ def initialize(phone_number:, default_country_code:, http:, **args)
10
+ params = {phone_number: phone_number, default_country_code: default_country_code}.merge(args)
11
+ super(params: params, path: "/api/phone/v1/verification", http: http)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = '1.9.1'
2
+ VERSION = '1.10.1'
3
3
  end
data/lib/addressfinder.rb CHANGED
@@ -9,6 +9,8 @@ require 'addressfinder/address_info'
9
9
  require 'addressfinder/address_search'
10
10
  require 'addressfinder/address_autocomplete'
11
11
  require 'addressfinder/bulk'
12
+ require 'addressfinder/v1/email/verification'
13
+ require 'addressfinder/v1/phone/verification'
12
14
  require 'addressfinder/errors'
13
15
  require 'addressfinder/util'
14
16
  require 'addressfinder/http'
@@ -61,6 +63,14 @@ module AddressFinder
61
63
  AddressFinder::AddressInfo.new(params: args, http: AddressFinder::HTTP.new(configuration)).perform.result
62
64
  end
63
65
 
66
+ def email_verification(args={})
67
+ AddressFinder::V1::Email::Verification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
68
+ end
69
+
70
+ def phone_verification(args={})
71
+ AddressFinder::V1::Phone::Verification.new(**args.merge(http: AddressFinder::HTTP.new(configuration))).perform.result
72
+ end
73
+
64
74
  def bulk(&block)
65
75
  AddressFinder::Bulk.new(http: AddressFinder::HTTP.new(configuration), verification_version: configuration.verification_version, default_country: configuration.default_country, &block).perform
66
76
  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.9.1
4
+ version: 1.10.1
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: 2022-10-12 00:00:00.000000000 Z
15
+ date: 2023-09-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: multi_json
@@ -109,17 +109,10 @@ executables: []
109
109
  extensions: []
110
110
  extra_rdoc_files: []
111
111
  files:
112
- - ".gitignore"
113
- - ".travis.yml"
114
112
  - CHANGELOG.md
115
- - Dockerfile
116
- - Gemfile
117
- - Guardfile
118
113
  - LICENSE.md
119
114
  - README.md
120
- - Rakefile
121
115
  - addressfinder.gemspec
122
- - docker-compose.yml
123
116
  - lib/addressfinder.rb
124
117
  - lib/addressfinder/address_autocomplete.rb
125
118
  - lib/addressfinder/address_info.rb
@@ -131,20 +124,12 @@ files:
131
124
  - lib/addressfinder/location_info.rb
132
125
  - lib/addressfinder/location_search.rb
133
126
  - lib/addressfinder/util.rb
127
+ - lib/addressfinder/v1/base.rb
128
+ - lib/addressfinder/v1/email/verification.rb
129
+ - lib/addressfinder/v1/phone/verification.rb
134
130
  - lib/addressfinder/v2/au/verification.rb
135
131
  - lib/addressfinder/verification.rb
136
132
  - lib/addressfinder/version.rb
137
- - spec/lib/addressfinder/address_autocomplete_spec.rb
138
- - spec/lib/addressfinder/address_info_spec.rb
139
- - spec/lib/addressfinder/address_search_spec.rb
140
- - spec/lib/addressfinder/bulk_spec.rb
141
- - spec/lib/addressfinder/location_info_spec.rb
142
- - spec/lib/addressfinder/location_search_spec.rb
143
- - spec/lib/addressfinder/util_spec.rb
144
- - spec/lib/addressfinder/v2/au/verification_spec.rb
145
- - spec/lib/addressfinder/verification_spec.rb
146
- - spec/lib/addressfinder_spec.rb
147
- - spec/spec_helper.rb
148
133
  homepage: https://github.com/AddressFinder/addressfinder-ruby
149
134
  licenses:
150
135
  - MIT
@@ -157,26 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
142
  requirements:
158
143
  - - ">="
159
144
  - !ruby/object:Gem::Version
160
- version: '2.1'
145
+ version: '2.6'
161
146
  required_rubygems_version: !ruby/object:Gem::Requirement
162
147
  requirements:
163
148
  - - ">="
164
149
  - !ruby/object:Gem::Version
165
150
  version: '0'
166
151
  requirements: []
167
- rubygems_version: 3.1.6
152
+ rubygems_version: 3.2.33
168
153
  signing_key:
169
154
  specification_version: 4
170
155
  summary: Provides easy access to AddressFinder APIs
171
- test_files:
172
- - spec/lib/addressfinder/address_autocomplete_spec.rb
173
- - spec/lib/addressfinder/address_info_spec.rb
174
- - spec/lib/addressfinder/address_search_spec.rb
175
- - spec/lib/addressfinder/bulk_spec.rb
176
- - spec/lib/addressfinder/location_info_spec.rb
177
- - spec/lib/addressfinder/location_search_spec.rb
178
- - spec/lib/addressfinder/util_spec.rb
179
- - spec/lib/addressfinder/v2/au/verification_spec.rb
180
- - spec/lib/addressfinder/verification_spec.rb
181
- - spec/lib/addressfinder_spec.rb
182
- - spec/spec_helper.rb
156
+ test_files: []
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /spec/reports/
6
-
7
- # for a library or gem, you might want to ignore these files since the code is
8
- # intended to run in multiple environments; otherwise, check them in:
9
- Gemfile.lock
10
- .ruby-version
11
- .ruby-gemset
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.7
4
- - 2.3.1
5
- - 2.4.1
6
- - 2.6.3
data/Dockerfile DELETED
@@ -1,28 +0,0 @@
1
- # Use the barebones version of Ruby 2.7.x
2
- FROM ruby:2.7
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/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard :rspec, cmd: 'bundle exec rspec' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task :default => :spec
7
- task :test => :spec
data/docker-compose.yml DELETED
@@ -1,11 +0,0 @@
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: {}
@@ -1,95 +0,0 @@
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
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::AddressInfo 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::AddressInfo.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 a simple PXID' do
19
- let(:args){ {pxid: '123'} }
20
-
21
- it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&key=XXX&secret=YYY') }
22
- end
23
-
24
- context 'with a country override' do
25
- let(:args){ {pxid: '123', country: 'nz'} }
26
-
27
- it { expect(request_uri).to eq('/api/nz/address/info.json?pxid=123&key=XXX&secret=YYY') }
28
- end
29
-
30
- context 'with a key override' do
31
- let(:args){ {pxid: '123', key:'AAA'} }
32
-
33
- it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&key=AAA&secret=YYY') }
34
- end
35
-
36
- context 'with a secret override' do
37
- let(:args){ {pxid: '123', secret: 'BBB'} }
38
-
39
- it { expect(request_uri).to eq('/api/au/address/info.json?pxid=123&secret=BBB&key=XXX') }
40
- end
41
- end
42
-
43
- describe '#build_result' do
44
- let(:locator){ AddressFinder::AddressInfo.new(params: {q: 'ignored'}, http: nil) }
45
-
46
- before do
47
- locator.send('response_body=', body)
48
- locator.send('response_status=', status)
49
- end
50
-
51
- subject(:result){ locator.send(:build_result) }
52
-
53
- context 'with a successful result' do
54
- let(:body){ '{"pxid":"2-.9.2U.F.F.2I","number":"184","container_only":"false","x":"174.314855382547","y":"-35.6946659390092","postcode":"0112","a":"184 William Jones Drive, Otangarei, Whangarei 0112","postal":"184 William Jones Drive, Otangarei, Whangarei 0112","mailtown":"Whangarei","post_suburb":"Otangarei","ta":"Whangarei District","sufi":932755,"street_type":"drive","city":"Whangarei","suburb":"Otangarei","region":"Northland Region","street":"William Jones Drive","postal_line_1":"184 William Jones Drive","postal_line_2":"Otangarei","postal_line_3":"Whangarei 0112","meshblock":"93700","dpid":"681856"}' }
55
- let(:status){ '200' }
56
-
57
- it { expect(result.class).to eq(AddressFinder::AddressInfo::Result) }
58
- it { expect(result.a).to eq("184 William Jones Drive, Otangarei, Whangarei 0112") }
59
- it { expect(result.pxid).to eq("2-.9.2U.F.F.2I") }
60
- end
61
- end
62
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe AddressFinder::AddressSearch do
4
- before do
5
- AddressFinder.configure do |af|
6
- af.api_key = 'XXX'
7
- af.api_secret = 'YYY'
8
- af.default_country = 'nz'
9
- end
10
- end
11
-
12
- describe '#build_request' do
13
- let(:locator){ AddressFinder::AddressSearch.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/nz/address.json?q=186+willis&key=XXX&secret=YYY') }
22
- end
23
-
24
- context 'with more arguments' do
25
- let(:args){ {q: '186 willis st', delivered: 1, max: 10} }
26
-
27
- it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&delivered=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.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/nz/address.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/nz/address.json?q=186+willis+st&secret=BBB&key=XXX') }
46
- end
47
- end
48
-
49
- describe '#build_result' do
50
- let(:locator){ AddressFinder::AddressSearch.new(params: {q: 'ignored'}, http: nil) }
51
-
52
- before do
53
- locator.send('response_body=', body)
54
- locator.send('response_status=', status)
55
- locator.send(:build_result)
56
- end
57
-
58
- subject(:results){ locator.results }
59
-
60
- context 'with completions' do
61
- 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}' }
62
- let(:status){ '200' }
63
-
64
- it { expect(results.size).to eq(3) }
65
- it { expect(results.first.class).to eq(AddressFinder::AddressSearch::Result) }
66
- it { expect(results.first.a).to eq("184 William Jones Drive, Otangarei, Whangarei 0112") }
67
- end
68
-
69
- context 'with no completions' do
70
- let(:body){ '{"completions":[],"paid":true}' }
71
- let(:status){ '200' }
72
-
73
- it { expect(results).to eq([]) }
74
- end
75
- end
76
- end