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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 969757f1b9dadfcc8c8558149da021ca01ac30f1
4
- data.tar.gz: 74e813efac7b28877b0b1ba5c63e4d78709eb77e
3
+ metadata.gz: 45f5e5e066397a1d1c55a10ea92a47263f9768f7
4
+ data.tar.gz: 509c5abfd707f03c895afe3bd2266f38e03014e0
5
5
  SHA512:
6
- metadata.gz: 4bb9d8016d76ae1fe87201a5e7bd702aadf2b71feee1f88ea36c740e8b4043ac53d7e653961883c0eaf493848cf1f6a8369b1ef26e2ee0f0c2462bd71a3bb24f
7
- data.tar.gz: 1e1cf7282b35ce418aa6c1b496c0471b5518ae164a6d6bc64ab59ab83dac41b3e3bb7390471a579402760541987b85fe775016c9b6f0a1b6c768b364ce536d0c
6
+ metadata.gz: 83f494bed9f25db5205d39dd4ca3f4c7e65e77cf2d608e0e1f5a1a003d752b467ae9ae02358c56d6462177d6ce702d778d6e4239d112550a37e5ee1e9a4fac4d
7
+ data.tar.gz: 5c9ee9e8012e11f1a7d808039472624b2d56ce9e5430a906d931abce73d7869147c01483dcd474c6fe1f878950831b63f8cf538d2c8ed4b97b799ef70f460d9b
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
- before_install: gem install bundler -v 1.13.6 --binstubs
5
+ before_install: gem install bundler -v 1.13.6
6
6
  script:
7
+ - bundle install --binstubs
7
8
  - bundle exec rake spec
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
- TODO
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
- address = first_potential_address
28
- return false if address.nil?
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 first_potential_address
34
- potential_address_matches = @address_match_gateway.query(search_term: postcode,
35
- country: country)
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
@@ -1,3 +1,3 @@
1
1
  module PostcodeValidation
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
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-06 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty