postcode_validation 0.0.7 → 0.0.8

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: 85d70cc5c0dca698702ada4030e4cec7930669e4
4
- data.tar.gz: aed97e95e68d47aef10598b777465df5cc688201
3
+ metadata.gz: '088fc75d33abd2357b07acb49dcf0163f6f23693'
4
+ data.tar.gz: 19cf3164986d0eb2e4521e1d9f948d8bbc8b07a2
5
5
  SHA512:
6
- metadata.gz: 976aa07fbedf7c9b5623657f75799bc64edb7c7da61f004dbd843bde8cdb009bef972768f0c3d21e3a3c066e42a71db6993c84b2dbffe01963b29eac5eac6cc7
7
- data.tar.gz: a8a18ee919b5740f47e6f21cc7f5ca9ebff572b8ac40817a3e05650ac368453884302c23c5a3983fb63d105a1e8d492bac86a9ab54a197f37094dc0da0fc8c37
6
+ metadata.gz: a0bf80a864292625c161faef98f79bdf3105d34d8d593584b82c630337767a1a55312bcf7c053998e74429e00495d4c0e5ca52f4a93fc870e502e38bff230fde
7
+ data.tar.gz: 7603b41258a1d3e18d7ded44c4741f2ad18aa0bbcf5c3de0259d62d88996aa31616e9d5c997329d08094ddd78c271a597c7e72a6cc35cb3658d7e5c9ea7b15e8
@@ -1,12 +1,17 @@
1
1
  module PostcodeValidation
2
2
  module Domain
3
3
  class Address
4
- def initialize(street_address:, place:)
5
- @street_address = street_address
6
- @place = place
4
+ def initialize(row:)
5
+ @row = row
7
6
  end
8
7
 
9
- attr_reader :street_address, :place
8
+ def street_address
9
+ "#{row['Text']}, #{row['Description']}"
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :row
10
15
  end
11
16
  end
12
17
  end
@@ -8,15 +8,20 @@ module PostcodeValidation
8
8
  KEY = ENV['POSTCODE_ANYWHERE_KEY']
9
9
  base_uri 'https://services.postcodeanywhere.co.uk'
10
10
 
11
- def query(search_term:, country:)
12
- response = address_list_for_postcode(country, search_term)
13
-
14
- response.map do |row|
11
+ def query(search_term:, country:, more_results_id: nil)
12
+ address_list_for_postcode(country, search_term, more_results_id).map do |row|
15
13
  raise PCARequestError, error_message(row) if row.key?('Error')
16
14
 
17
- PostcodeValidation::Domain::Address.new(street_address: row['StreetAddress'],
18
- place: row['Place'])
19
- end
15
+ if row['Type'] == 'Postcode'
16
+ self.class.new.query(
17
+ country: country,
18
+ search_term: search_term,
19
+ more_results_id: row['Id']
20
+ )
21
+ elsif row['Type'] == 'Address'
22
+ PostcodeValidation::Domain::Address.new(row: row)
23
+ end
24
+ end.flatten
20
25
  end
21
26
 
22
27
  private
@@ -25,19 +30,27 @@ module PostcodeValidation
25
30
  "#{row['Error']} #{row['Cause']} #{row['Resolution']}"
26
31
  end
27
32
 
28
- def address_list_for_postcode(country, search_term)
29
- JSON.parse(self.class.get('/PostcodeAnywhere/Interactive/Find/1.1/json.ws', lookup_parameters(country, search_term)).body)
33
+ def address_list_for_postcode(country, search_term, more_results_id)
34
+ JSON.parse(
35
+ self.class.get(
36
+ '/Capture/Interactive/Find/1.00/json.ws',
37
+ lookup_parameters(country, search_term, more_results_id)
38
+ ).body
39
+ )
30
40
  end
31
41
 
32
- def lookup_parameters(country, search_term)
33
- {
42
+ def lookup_parameters(country, search_term, more_results_id)
43
+ result = {
34
44
  query: {
35
- Country: country,
45
+ Countries: country,
36
46
  Key: KEY,
37
- SearchTerm: search_term,
38
- Filter: 'None'
47
+ Text: search_term,
48
+ Limit: 8
39
49
  }
40
50
  }
51
+
52
+ result[:query].merge!(Container: more_results_id) unless more_results_id.nil?
53
+ result
41
54
  end
42
55
  end
43
56
  end
@@ -22,7 +22,7 @@ module PostcodeValidation
22
22
 
23
23
  def formatted(addresses)
24
24
  addresses.map do |address|
25
- { street_address: address.street_address, place: address.place }
25
+ { street_address: address.street_address }
26
26
  end
27
27
  end
28
28
 
@@ -1,3 +1,3 @@
1
1
  module PostcodeValidation
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postcode_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig J. Bass
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-08 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty