postcode_validation 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +24 -2
- data/lib/postcode_validation/use_case/validate_address.rb +7 -7
- data/lib/postcode_validation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f5e5e066397a1d1c55a10ea92a47263f9768f7
|
4
|
+
data.tar.gz: 509c5abfd707f03c895afe3bd2266f38e03014e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83f494bed9f25db5205d39dd4ca3f4c7e65e77cf2d608e0e1f5a1a003d752b467ae9ae02358c56d6462177d6ce702d778d6e4239d112550a37e5ee1e9a4fac4d
|
7
|
+
data.tar.gz: 5c9ee9e8012e11f1a7d808039472624b2d56ce9e5430a906d931abce73d7869147c01483dcd474c6fe1f878950831b63f8cf538d2c8ed4b97b799ef70f460d9b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
# PostcodeValidation
|
1
|
+
# PostcodeValidation [![Build Status](https://travis-ci.org/madetech/postcode_validation.svg?branch=master)](https://travis-ci.org/madetech/postcode_validation)
|
2
2
|
|
3
3
|
This gem provides basic postcode validation functionality which can be used in any application
|
4
4
|
|
5
|
+
The specific validation that we perform goes beyond simple regex matching, to determine if the postcode actually exists.
|
6
|
+
|
7
|
+
To do this it uses PCAPredict.com's Capture+ API.
|
8
|
+
By leveraging this service we are able to provide validation against country's postcode that they support.
|
9
|
+
|
5
10
|
It also comes with out of the box plugins for:
|
11
|
+
|
6
12
|
- Solidus
|
7
13
|
|
8
14
|
## Installation
|
@@ -23,13 +29,24 @@ Or install it yourself as:
|
|
23
29
|
|
24
30
|
## Usage
|
25
31
|
|
32
|
+
This gem relies on ```ENV['POSTCODE_ANYWHERE_KEY']``` being set to a valid PCAPredict service key for Capture+.
|
33
|
+
|
34
|
+
One of the easiest ways to do this is to use the ```dotenv``` gem for this in your host application.
|
35
|
+
|
26
36
|
### Using with Solidus
|
27
37
|
|
28
|
-
|
38
|
+
```ruby
|
39
|
+
require 'postcode_validation'
|
40
|
+
require 'postcode_validation/plugins/solidus'
|
41
|
+
Spree::Order.include(PostcodeValidation::SpreeOrderPostcodeValid)
|
42
|
+
````
|
43
|
+
|
44
|
+
NB: Error reporting currently only works with a Tagged Logger
|
29
45
|
|
30
46
|
### Bespoke application usage
|
31
47
|
|
32
48
|
```ruby
|
49
|
+
require 'postcode_validation'
|
33
50
|
use_case = PostcodeValidation::UseCase::ValidateAddress.new(
|
34
51
|
address_match_gateway: PostcodeValidation::Gateway::PCAPotentialAddressMatch.new
|
35
52
|
)
|
@@ -37,6 +54,11 @@ use_case = PostcodeValidation::UseCase::ValidateAddress.new(
|
|
37
54
|
valid = use_case.execute(postcode: 'SE10SW', country: 'GB')[:valid?]
|
38
55
|
```
|
39
56
|
|
57
|
+
```
|
58
|
+
> valid
|
59
|
+
true
|
60
|
+
```
|
61
|
+
|
40
62
|
Country must be a valid 2-letter ISO country code.
|
41
63
|
Postcode is the postcode under test.
|
42
64
|
|
@@ -24,16 +24,16 @@ module PostcodeValidation
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def valid_postcode?
|
27
|
-
|
28
|
-
return false if
|
27
|
+
matches = potential_address_matches
|
28
|
+
return false if matches.first.nil?
|
29
29
|
|
30
|
-
address.postcode_matches? postcode
|
30
|
+
matches.map { |address| return true if address.postcode_matches? postcode }
|
31
|
+
false
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
potential_address_matches.first
|
34
|
+
def potential_address_matches
|
35
|
+
@address_match_gateway.query(search_term: postcode,
|
36
|
+
country: country)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
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.3
|
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: 2016-12-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|