addressfinder 1.5.1 → 1.5.2

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
  SHA1:
3
- metadata.gz: 00f132e87a8994d62729692417afd3f3ab3139a8
4
- data.tar.gz: 7b0e282348a00cf69f1d86f67b4f2b375c316163
3
+ metadata.gz: 05ba956f56eb4abdf67174b1c8dc8fa60e429855
4
+ data.tar.gz: 473d3c098ab85f3255409d42fc114dbbddd278bf
5
5
  SHA512:
6
- metadata.gz: 29d29e3a4d9ce40a8dff5bd41638cd0d1afa07c02e6918eba0c2695f7cee6505ae6b781a28fbfb95254e6151aeb90c19cd84d5bd197b7519ae8f0652c184edb3
7
- data.tar.gz: 99c4f04547759bea41ffe1db021d83709ca372881651e1d7484978ffd936d8f4caf123d866308d981d1622cc63b1e321d227a0da4b1ddc19edc16d1715a71da9
6
+ metadata.gz: 9056caa0b3632c4069dc0f78fea84c876fa3fda0438af6cd771bee2a09aab93087e912decf5eabf923b442994360ec09c063f62d014ea86dd959be1dbf031082
7
+ data.tar.gz: 0d20f2503daaeed9e724231973414731e65bfa4aa468f37ad7dadd059b226832bdf0f1ac3eadd49fbc395dc746cf5887e092e98691e9aa09ff4473764c1cba24
@@ -1,3 +1,8 @@
1
+ # AddressFinder 1.5.2 (December 21, 2015) #
2
+
3
+ * Update for the nested response format used in Address Cleanse Australia
4
+ * Add an encoding helper which uses CGI::escape
5
+
1
6
  # AddressFinder 1.5.1 (November 25, 2015) #
2
7
 
3
8
  * Update the ClientProxy #cleanse method to return result instead of an AddressFinder::Cleanse instance
data/README.md CHANGED
@@ -50,11 +50,12 @@ You can obtain your API key and secret from the AddressFinder Portal.
50
50
  See the documentation on the available parameters and expected response here:
51
51
 
52
52
  https://addressfinder.nz/docs/address_cleanse_api/
53
+ https://addressfinder.com.au/docs/address_cleanse_api/
53
54
 
54
55
  Usage example:
55
56
 
56
57
  ```ruby
57
- result = AddressFinder.cleanse(q: '186 Willis St, Wellington')
58
+ result = AddressFinder.cleanse(q: '186 Willis St, Wellington', country: 'nz')
58
59
 
59
60
  if result
60
61
  $stdout.puts "Success: #{result.postal}"
@@ -9,6 +9,7 @@ require 'addressfinder/address_info'
9
9
  require 'addressfinder/address_search'
10
10
  require 'addressfinder/bulk'
11
11
  require 'addressfinder/errors'
12
+ require 'addressfinder/util'
12
13
 
13
14
  module AddressFinder
14
15
  class << self
@@ -33,8 +33,7 @@ module AddressFinder
33
33
  end
34
34
 
35
35
  def encoded_params
36
- query = params.map{|k,v| "#{k}=#{v}"}.join('&')
37
- URI::encode(query)
36
+ Util.encode_and_join_params(params)
38
37
  end
39
38
 
40
39
  def execute_request
@@ -33,8 +33,7 @@ module AddressFinder
33
33
  end
34
34
 
35
35
  def encoded_params
36
- query = params.map{|k,v| "#{k}=#{v}"}.join('&')
37
- URI::encode(query)
36
+ Util.encode_and_join_params(params)
38
37
  end
39
38
 
40
39
  def execute_request
@@ -53,18 +53,14 @@ module AddressFinder
53
53
  end
54
54
 
55
55
  if response_hash['matched']
56
- self.result = Result.new(response_hash)
56
+ self.result = Result.new(response_hash['address'] || response_hash)
57
57
  else
58
58
  self.result = nil
59
59
  end
60
60
  end
61
61
 
62
62
  def encoded_params
63
- query_params = params.map do |k,v|
64
- "#{k}=#{ERB::Util.url_encode(v)}"
65
- end
66
-
67
- query_params.join('&')
63
+ Util.encode_and_join_params(params)
68
64
  end
69
65
 
70
66
  def response_hash
@@ -34,8 +34,7 @@ module AddressFinder
34
34
  end
35
35
 
36
36
  def encoded_params
37
- query = params.map{|k,v| "#{k}=#{v}"}.join('&')
38
- URI::encode(query)
37
+ Util.encode_and_join_params(params)
39
38
  end
40
39
 
41
40
  def execute_request
@@ -34,8 +34,7 @@ module AddressFinder
34
34
  end
35
35
 
36
36
  def encoded_params
37
- query = params.map{|k,v| "#{k}=#{v}"}.join('&')
38
- URI::encode(query)
37
+ Util.encode_and_join_params(params)
39
38
  end
40
39
 
41
40
  def execute_request
@@ -0,0 +1,12 @@
1
+ module AddressFinder
2
+ class Util
3
+
4
+ def self.encode(v)
5
+ CGI::escape(v.to_s)
6
+ end
7
+
8
+ def self.encode_and_join_params(params)
9
+ params.map{ |k,v| "#{k}=#{encode(v)}" }.join('&')
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module AddressFinder
2
- VERSION = '1.5.1'
2
+ VERSION = '1.5.2'
3
3
  end
@@ -18,31 +18,31 @@ RSpec.describe AddressFinder::AddressSearch do
18
18
  context 'with minimal arguments' do
19
19
  let(:args){ {q: '186 willis'} }
20
20
 
21
- it { expect(request_uri).to eq('/api/nz/address.json?q=186%20willis&key=XXX&secret=YYY') }
21
+ it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis&key=XXX&secret=YYY') }
22
22
  end
23
23
 
24
24
  context 'with more arguments' do
25
25
  let(:args){ {q: '186 willis st', delivered: 1, max: 10} }
26
26
 
27
- it { expect(request_uri).to eq('/api/nz/address.json?q=186%20willis%20st&delivered=1&max=10&key=XXX&secret=YYY') }
27
+ it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&delivered=1&max=10&key=XXX&secret=YYY') }
28
28
  end
29
29
 
30
30
  context 'with a country override' do
31
31
  let(:args){ {q: '186 willis st', country: 'au'} }
32
32
 
33
- it { expect(request_uri).to eq('/api/au/address.json?q=186%20willis%20st&key=XXX&secret=YYY') }
33
+ it { expect(request_uri).to eq('/api/au/address.json?q=186+willis+st&key=XXX&secret=YYY') }
34
34
  end
35
35
 
36
36
  context 'with a key override' do
37
37
  let(:args){ {q: '186 willis st', key: 'AAA'} }
38
38
 
39
- it { expect(request_uri).to eq('/api/nz/address.json?q=186%20willis%20st&key=AAA&secret=YYY') }
39
+ it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&key=AAA&secret=YYY') }
40
40
  end
41
41
 
42
42
  context 'with a secret override' do
43
43
  let(:args){ {q: '186 willis st', secret: 'BBB'} }
44
44
 
45
- it { expect(request_uri).to eq('/api/nz/address.json?q=186%20willis%20st&secret=BBB&key=XXX') }
45
+ it { expect(request_uri).to eq('/api/nz/address.json?q=186+willis+st&secret=BBB&key=XXX') }
46
46
  end
47
47
  end
48
48
 
@@ -18,31 +18,31 @@ RSpec.describe AddressFinder::Cleanse do
18
18
  context 'with minimal arguments' do
19
19
  let(:args){ {q: '186 willis st', http: http} }
20
20
 
21
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186%20willis%20st&format=json&key=XXX&secret=YYY') }
21
+ it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=YYY') }
22
22
  end
23
23
 
24
24
  context 'with more arguments' do
25
25
  let(:args){ {q: '186 willis st', delivered: true, region_code: 'A', http: http} }
26
26
 
27
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186%20willis%20st&delivered=true&region_code=A&format=json&key=XXX&secret=YYY') }
27
+ it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&delivered=true&region_code=A&format=json&key=XXX&secret=YYY') }
28
28
  end
29
29
 
30
30
  context 'with a country override' do
31
31
  let(:args){ {q: '186 willis st', country: 'au', http: http} }
32
32
 
33
- it { expect(request_uri).to eq('/api/au/address/cleanse?q=186%20willis%20st&format=json&key=XXX&secret=YYY') }
33
+ it { expect(request_uri).to eq('/api/au/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=YYY') }
34
34
  end
35
35
 
36
36
  context 'with a key override' do
37
37
  let(:args){ {q: '186 willis st', key: 'AAA', http: http} }
38
38
 
39
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186%20willis%20st&format=json&key=AAA&secret=YYY') }
39
+ it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=AAA&secret=YYY') }
40
40
  end
41
41
 
42
42
  context 'with a secret override' do
43
43
  let(:args){ {q: '186 willis st', secret: 'BBB', http: http} }
44
44
 
45
- it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186%20willis%20st&format=json&key=XXX&secret=BBB') }
45
+ it { expect(request_uri).to eq('/api/nz/address/cleanse?q=186+willis+st&format=json&key=XXX&secret=BBB') }
46
46
  end
47
47
 
48
48
  context 'with a domain given' do
@@ -73,7 +73,7 @@ RSpec.describe AddressFinder::Cleanse do
73
73
 
74
74
  subject(:result){ cleanser.send(:build_result) }
75
75
 
76
- context 'with a successful result' do
76
+ context 'with a successful nz result' do
77
77
  let(:body){ '{"matched": true, "postal_address": "Texas"}' }
78
78
  let(:status){ '200' }
79
79
 
@@ -84,39 +84,20 @@ RSpec.describe AddressFinder::Cleanse do
84
84
  it { expect(result.postal_address).to eq("Texas") }
85
85
  end
86
86
 
87
- context 'with an unfound result' do
88
- let(:body){ '{"matched": false}' }
87
+ context 'with a successful au result' do
88
+ let(:body){ %Q({"matched": true, "success": true, "address": {"full_address": "Texas"}}) }
89
89
  let(:status){ '200' }
90
90
 
91
- it { expect(result).to eq(nil) }
92
- end
93
- end
94
-
95
- describe '#encoded_params' do
96
- subject(:encoded_params){ AddressFinder::Cleanse.new(q: q, http: nil).send(:encoded_params) }
97
-
98
- context 'with a question mark value' do
99
- let(:q){ '?' }
100
-
101
- it { expect(encoded_params).to eq('q=%3F&format=json&key=XXX&secret=YYY') }
102
- end
103
-
104
- context 'with a normal address value' do
105
- let(:q){ '12 high' }
106
-
107
- it { expect(encoded_params).to eq('q=12%20high&format=json&key=XXX&secret=YYY') }
108
- end
109
-
110
- context 'with a blank value' do
111
- let(:q){ '' }
91
+ it { expect(result.class).to eq(AddressFinder::Cleanse::Result) }
112
92
 
113
- it { expect(encoded_params).to eq('q=&format=json&key=XXX&secret=YYY') }
93
+ it { expect(result.full_address).to eq("Texas") }
114
94
  end
115
95
 
116
- context 'with a nil value' do
117
- let(:q){ nil }
96
+ context 'with an unfound result' do
97
+ let(:body){ '{"matched": false}' }
98
+ let(:status){ '200' }
118
99
 
119
- it { expect(encoded_params).to eq('q=&format=json&key=XXX&secret=YYY') }
100
+ it { expect(result).to eq(nil) }
120
101
  end
121
102
  end
122
103
  end
@@ -24,25 +24,25 @@ RSpec.describe AddressFinder::LocationSearch do
24
24
  context 'with more arguments' do
25
25
  let(:args){ {q: 'willis st', street: 1, max: 10} }
26
26
 
27
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis%20st&street=1&max=10&key=XXX&secret=YYY') }
27
+ it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&street=1&max=10&key=XXX&secret=YYY') }
28
28
  end
29
29
 
30
30
  context 'with a country override' do
31
31
  let(:args){ {q: 'willis st', country: 'au'} }
32
32
 
33
- it { expect(request_uri).to eq('/api/au/location.json?q=willis%20st&key=XXX&secret=YYY') }
33
+ it { expect(request_uri).to eq('/api/au/location.json?q=willis+st&key=XXX&secret=YYY') }
34
34
  end
35
35
 
36
36
  context 'with a key override' do
37
37
  let(:args){ {q: 'willis st', key: 'AAA'} }
38
38
 
39
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis%20st&key=AAA&secret=YYY') }
39
+ it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&key=AAA&secret=YYY') }
40
40
  end
41
41
 
42
42
  context 'with a secret override' do
43
43
  let(:args){ {q: 'willis st', secret: 'BBB'} }
44
44
 
45
- it { expect(request_uri).to eq('/api/nz/location.json?q=willis%20st&secret=BBB&key=XXX') }
45
+ it { expect(request_uri).to eq('/api/nz/location.json?q=willis+st&secret=BBB&key=XXX') }
46
46
  end
47
47
 
48
48
  context 'with a domain given' do
@@ -0,0 +1,37 @@
1
+ require 'addressfinder/util'
2
+
3
+ RSpec.describe AddressFinder::Util do
4
+ describe '.encode_and_join_params' do
5
+ subject { AddressFinder::Util.encode_and_join_params(params) }
6
+
7
+ context 'with a question mark value' do
8
+ let(:params){ {q:'?',format:'json',key:'XXX',secret:'YYY'} }
9
+
10
+ it { is_expected.to eq('q=%3F&format=json&key=XXX&secret=YYY') }
11
+ end
12
+
13
+ context 'with an ampersand value' do
14
+ let(:params){ {q:'&',format:'json',key:'XXX',secret:'YYY'} }
15
+
16
+ it { is_expected.to eq('q=%26&format=json&key=XXX&secret=YYY') }
17
+ end
18
+
19
+ context 'with a normal address value' do
20
+ let(:params){ {q:'12 high',format:'json',key:'XXX',secret:'YYY'} }
21
+
22
+ it { is_expected.to eq('q=12+high&format=json&key=XXX&secret=YYY') }
23
+ end
24
+
25
+ context 'with a blank value' do
26
+ let(:params){ {q:'',format:'json',key:'XXX',secret:'YYY'} }
27
+
28
+ it { is_expected.to eq('q=&format=json&key=XXX&secret=YYY') }
29
+ end
30
+
31
+ context 'with a nil value' do
32
+ let(:params){ {q:nil,format:'json',key:'XXX',secret:'YYY'} }
33
+
34
+ it { is_expected.to eq('q=&format=json&key=XXX&secret=YYY') }
35
+ end
36
+ end
37
+ 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.5.1
4
+ version: 1.5.2
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: 2015-11-25 00:00:00.000000000 Z
14
+ date: 2015-12-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -111,12 +111,14 @@ files:
111
111
  - lib/addressfinder/errors.rb
112
112
  - lib/addressfinder/location_info.rb
113
113
  - lib/addressfinder/location_search.rb
114
+ - lib/addressfinder/util.rb
114
115
  - lib/addressfinder/version.rb
115
116
  - spec/lib/addressfinder/address_info_spec.rb
116
117
  - spec/lib/addressfinder/address_search_spec.rb
117
118
  - spec/lib/addressfinder/cleanse_spec.rb
118
119
  - spec/lib/addressfinder/location_info_spec.rb
119
120
  - spec/lib/addressfinder/location_search_spec.rb
121
+ - spec/lib/addressfinder/util_spec.rb
120
122
  - spec/spec_helper.rb
121
123
  homepage: https://github.com/AbleTech/addressfinder-ruby
122
124
  licenses:
@@ -148,4 +150,5 @@ test_files:
148
150
  - spec/lib/addressfinder/cleanse_spec.rb
149
151
  - spec/lib/addressfinder/location_info_spec.rb
150
152
  - spec/lib/addressfinder/location_search_spec.rb
153
+ - spec/lib/addressfinder/util_spec.rb
151
154
  - spec/spec_helper.rb