postcode_validation 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '088fc75d33abd2357b07acb49dcf0163f6f23693'
4
- data.tar.gz: 19cf3164986d0eb2e4521e1d9f948d8bbc8b07a2
3
+ metadata.gz: 9a2ee17af8ab9e30269ce747e03640806f649082
4
+ data.tar.gz: 7fb8833e0a5bdad90fdf10277f9455ca721067f9
5
5
  SHA512:
6
- metadata.gz: a0bf80a864292625c161faef98f79bdf3105d34d8d593584b82c630337767a1a55312bcf7c053998e74429e00495d4c0e5ca52f4a93fc870e502e38bff230fde
7
- data.tar.gz: 7603b41258a1d3e18d7ded44c4741f2ad18aa0bbcf5c3de0259d62d88996aa31616e9d5c997329d08094ddd78c271a597c7e72a6cc35cb3658d7e5c9ea7b15e8
6
+ metadata.gz: 6890ec86b5ecf3371daff0866f82bbcc845212b524abb80687a76bc518f06d9c6160c3cca9e0ca6bfe63b279fb004f219c8031da99a5dd15b077774e00ea7114
7
+ data.tar.gz: 9d90f00f2f74fb977d6a89ed34d8b159b84a80a45d67d591760ef098b8a05c128140b1b4c1896e6181ccca976fd00fb70201c3f5ed5e5b9dcb4ccd17529a33d9
@@ -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 street_address
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
@@ -19,7 +19,7 @@ module PostcodeValidation
19
19
  more_results_id: row['Id']
20
20
  )
21
21
  elsif row['Type'] == 'Address'
22
- PostcodeValidation::Domain::Address.new(row: row)
22
+ PostcodeValidation::Domain::Address.new(row: row, key: KEY)
23
23
  end
24
24
  end.flatten
25
25
  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
@@ -22,7 +22,10 @@ module PostcodeValidation
22
22
 
23
23
  def formatted(addresses)
24
24
  addresses.map do |address|
25
- { street_address: address.street_address }
25
+ {
26
+ id: address.id,
27
+ label: address.label
28
+ }
26
29
  end
27
30
  end
28
31
 
@@ -1,3 +1,3 @@
1
1
  module PostcodeValidation
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
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.8
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-09 00:00:00.000000000 Z
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