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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '088fc75d33abd2357b07acb49dcf0163f6f23693'
|
4
|
+
data.tar.gz: 19cf3164986d0eb2e4521e1d9f948d8bbc8b07a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
5
|
-
@
|
6
|
-
@place = place
|
4
|
+
def initialize(row:)
|
5
|
+
@row = row
|
7
6
|
end
|
8
7
|
|
9
|
-
|
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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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(
|
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
|
-
|
45
|
+
Countries: country,
|
36
46
|
Key: KEY,
|
37
|
-
|
38
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|