postcode_validation 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postcode_validation.rb +3 -0
- data/lib/postcode_validation/domain/address.rb +8 -3
- data/lib/postcode_validation/domain/address_detail.rb +33 -0
- data/lib/postcode_validation/gateway/pca_address_detail.rb +36 -0
- data/lib/postcode_validation/gateway/pca_address_list.rb +1 -1
- data/lib/postcode_validation/use_case/address_detail_retriever.rb +42 -0
- data/lib/postcode_validation/use_case/address_list.rb +4 -1
- data/lib/postcode_validation/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2ee17af8ab9e30269ce747e03640806f649082
|
4
|
+
data.tar.gz: 7fb8833e0a5bdad90fdf10277f9455ca721067f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6890ec86b5ecf3371daff0866f82bbcc845212b524abb80687a76bc518f06d9c6160c3cca9e0ca6bfe63b279fb004f219c8031da99a5dd15b077774e00ea7114
|
7
|
+
data.tar.gz: 9d90f00f2f74fb977d6a89ed34d8b159b84a80a45d67d591760ef098b8a05c128140b1b4c1896e6181ccca976fd00fb70201c3f5ed5e5b9dcb4ccd17529a33d9
|
data/lib/postcode_validation.rb
CHANGED
@@ -4,9 +4,12 @@ module PostcodeValidation
|
|
4
4
|
require 'httparty'
|
5
5
|
require 'postcode_validation/domain/potential_address_match'
|
6
6
|
require 'postcode_validation/domain/address'
|
7
|
+
require 'postcode_validation/domain/address_detail'
|
7
8
|
require 'postcode_validation/error/request_error'
|
8
9
|
require 'postcode_validation/gateway/pca_potential_address_match'
|
9
10
|
require 'postcode_validation/gateway/pca_address_list'
|
11
|
+
require 'postcode_validation/gateway/pca_address_detail'
|
10
12
|
require 'postcode_validation/use_case/validate_address'
|
11
13
|
require 'postcode_validation/use_case/address_list'
|
14
|
+
require 'postcode_validation/use_case/address_detail_retriever'
|
12
15
|
end
|
@@ -1,17 +1,22 @@
|
|
1
1
|
module PostcodeValidation
|
2
2
|
module Domain
|
3
3
|
class Address
|
4
|
-
def initialize(row:)
|
4
|
+
def initialize(row:, key:)
|
5
5
|
@row = row
|
6
|
+
@key = key
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
+
def label
|
9
10
|
"#{row['Text']}, #{row['Description']}"
|
10
11
|
end
|
11
12
|
|
13
|
+
def id
|
14
|
+
row['Id']
|
15
|
+
end
|
16
|
+
|
12
17
|
private
|
13
18
|
|
14
|
-
attr_reader :row
|
19
|
+
attr_reader :row, :key
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module PostcodeValidation
|
2
|
+
module Domain
|
3
|
+
class AddressDetail
|
4
|
+
def initialize(result:)
|
5
|
+
@result = result
|
6
|
+
end
|
7
|
+
|
8
|
+
def company
|
9
|
+
result['Company']
|
10
|
+
end
|
11
|
+
|
12
|
+
def address_line_1
|
13
|
+
result['Line1']
|
14
|
+
end
|
15
|
+
|
16
|
+
def address_line_2
|
17
|
+
result['Line2']
|
18
|
+
end
|
19
|
+
|
20
|
+
def city
|
21
|
+
result['City']
|
22
|
+
end
|
23
|
+
|
24
|
+
def country
|
25
|
+
result['CountryName']
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PostcodeValidation
|
2
|
+
module Gateway
|
3
|
+
class PCAAddressDetail
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
class PCARequestError < PostcodeValidation::Error::RequestError; end
|
7
|
+
|
8
|
+
KEY = ENV['POSTCODE_ANYWHERE_KEY']
|
9
|
+
base_uri 'https://services.postcodeanywhere.co.uk'
|
10
|
+
|
11
|
+
def find(id:)
|
12
|
+
PostcodeValidation::Domain::AddressDetail.new(result: address(id))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def error_message(row)
|
18
|
+
"#{row['Error']} #{row['Cause']} #{row['Resolution']}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def address(id)
|
22
|
+
JSON.parse(
|
23
|
+
self.class.get(
|
24
|
+
'/Capture/Interactive/Retrieve/1.00/json.ws',
|
25
|
+
{
|
26
|
+
query: {
|
27
|
+
Id: id,
|
28
|
+
Key: KEY
|
29
|
+
}
|
30
|
+
}
|
31
|
+
).body
|
32
|
+
).first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'validate_address/format_validator'
|
2
|
+
|
3
|
+
module PostcodeValidation
|
4
|
+
module UseCase
|
5
|
+
class AddressDetailRetriever
|
6
|
+
def initialize(address_detail_retriever_gateway:, logger: nil)
|
7
|
+
@address_detail_retriever_gateway = address_detail_retriever_gateway
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(id:)
|
12
|
+
address = find_address(id)
|
13
|
+
|
14
|
+
formatted(address)
|
15
|
+
rescue PostcodeValidation::Error::RequestError => e
|
16
|
+
log_error(e)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :address_detail_retriever_gateway, :logger
|
22
|
+
|
23
|
+
def formatted(address)
|
24
|
+
{
|
25
|
+
address_line_1: address.address_line_1,
|
26
|
+
address_line_2: address.address_line_2,
|
27
|
+
company: address.company,
|
28
|
+
city: address.city,
|
29
|
+
country: address.country
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def log_error(e)
|
34
|
+
logger.error(e) unless logger.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_address(id)
|
38
|
+
@address_detail_retriever_gateway.find(id: id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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.9
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -125,12 +125,15 @@ files:
|
|
125
125
|
- Rakefile
|
126
126
|
- lib/postcode_validation.rb
|
127
127
|
- lib/postcode_validation/domain/address.rb
|
128
|
+
- lib/postcode_validation/domain/address_detail.rb
|
128
129
|
- lib/postcode_validation/domain/potential_address_match.rb
|
129
130
|
- lib/postcode_validation/error/request_error.rb
|
131
|
+
- lib/postcode_validation/gateway/pca_address_detail.rb
|
130
132
|
- lib/postcode_validation/gateway/pca_address_list.rb
|
131
133
|
- lib/postcode_validation/gateway/pca_potential_address_match.rb
|
132
134
|
- lib/postcode_validation/plugins/solidus.rb
|
133
135
|
- lib/postcode_validation/plugins/solidus/models/concerns/spree_order_postcode_valid.rb
|
136
|
+
- lib/postcode_validation/use_case/address_detail_retriever.rb
|
134
137
|
- lib/postcode_validation/use_case/address_list.rb
|
135
138
|
- lib/postcode_validation/use_case/validate_address.rb
|
136
139
|
- lib/postcode_validation/use_case/validate_address/format_validator.rb
|