postcode_anywhere-email_validation 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/lib/postcode_anywhere/email_validation/response.rb +51 -0
- data/lib/postcode_anywhere/email_validation/validation_error.rb +17 -0
- data/lib/postcode_anywhere/email_validation/validator.rb +13 -0
- data/lib/postcode_anywhere/email_validation/version.rb +5 -0
- data/lib/postcode_anywhere/email_validation.rb +26 -0
- data/postcodeanywhere-emailvalidation.gemspec +30 -0
- data/spec/features/email_validation_spec.rb +27 -0
- data/spec/features/email_validator_spec.rb +29 -0
- data/spec/lib/postcode_anywhere/email_validation/response_spec.rb +105 -0
- data/spec/lib/postcode_anywhere/email_validation/validation_error_spec.rb +29 -0
- data/spec/lib/postcode_anywhere/email_validation/validator_spec.rb +26 -0
- data/spec/lib/postcode_anywhere/email_validation_spec.rb +73 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_example_com_.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_john_doe_.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/activemodel_validator_with_valid_values_is_not_valid_on_value_fake_jsf_io_.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/activemodel_validator_with_valid_values_is_not_valid_on_value_pablo_google_com_.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_invalid_dns_record.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_invalid_format.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_valid_format_and_valid_dns_record.yml +71 -0
- data/spec/support/fixtures/vcr_cassettes/validating_an_email_address_without_api_key.yml +73 -0
- data/spec/support/validated_class.rb +6 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzQzODgyZDZhM2Y1ZDkwZmVmMjMxZDBiMzM3ZjEyMDY3MzNmMjUwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWE0MGMxMjliOWQzMTg4OTU1Mzc2MWRkYjc2NTc1ZTYzYmQ3YTExYg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWIxZGZmY2M0ZTlhMDYwNWNlZjc0MzBmMDg2ZjMxYjgyMTc0ZGJkNWFkMzlj
|
10
|
+
ZjI5OWRiZDMyYTkxNjRiNTQ1ZmFmOTAyMjJhMjgyMGM2NmFmYzllOWUyYjcw
|
11
|
+
ZjdmNWIxMDJjYThlOWNjMTA3YWNiYTdhNzk1ZjJiMTc2NTUwMDk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjFiM2JjN2UxZDAwMzIwODI4NmFhMzM5ZTkxMDcyZjYzMGM1MWI4ODg2YzYz
|
14
|
+
MjI0YzNjM2VlMjUyYzIwMWM5ZTNlZmMzZDFkNGI1MzU2M2FiOWU3Y2VlNmRk
|
15
|
+
ZDU3M2FkZTMwNGM0ZGNiZWQyNzZlYmNiZTU5MzI0YjQ3NzM0MmY=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Money Advice Service
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# PostcodeAnywhere::EmailValidation
|
2
|
+
|
3
|
+
Verifies the existence of an email address using the
|
4
|
+
[Email Validation web services] [email-validation]
|
5
|
+
from [PostcodeAnywhere].
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem 'postcode_anywhere-email_validation'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ gem install postcode_anywhere-email_validation
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
PostcodeAnywhere::EmailValidation.key = 'AA11-AA11-AA11-AA11'
|
31
|
+
PostcodeAnywhere::EmailValidation.valid?('info@google.com') #=> true
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
41
|
+
|
42
|
+
[postcodeanywhere]: http://www.postcodeanywhere.co.uk/
|
43
|
+
"PostcodeAnywhere"
|
44
|
+
|
45
|
+
[email-validation]: http://www.postcodeanywhere.co.uk/email-validation/
|
46
|
+
"PostcodeAnywhere's Email Validation web services"
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module PostcodeAnywhere
|
4
|
+
module EmailValidation
|
5
|
+
class Response
|
6
|
+
|
7
|
+
def self.parse(json)
|
8
|
+
response = JSON.parse(json)['Items'].first
|
9
|
+
error = if response['Error']
|
10
|
+
ValidationError.new(response['Description'],
|
11
|
+
code: response['Error'],
|
12
|
+
cause: response['Cause'],
|
13
|
+
resolution: response['Resolution'])
|
14
|
+
end
|
15
|
+
|
16
|
+
new(response['ValidFormat'], response['FoundDnsRecord'], error)
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
raise error if error?
|
21
|
+
|
22
|
+
valid_format? && valid_dns_record?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_accessor :valid_format
|
28
|
+
attr_accessor :found_dns_record
|
29
|
+
attr_accessor :error
|
30
|
+
|
31
|
+
def initialize(valid_format, found_dns_record, error)
|
32
|
+
self.valid_format = valid_format
|
33
|
+
self.found_dns_record = found_dns_record
|
34
|
+
self.error = error
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_format?
|
38
|
+
!!valid_format
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_dns_record?
|
42
|
+
!!found_dns_record
|
43
|
+
end
|
44
|
+
|
45
|
+
def error?
|
46
|
+
!!error
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PostcodeAnywhere
|
2
|
+
module EmailValidation
|
3
|
+
class ValidationError < StandardError
|
4
|
+
|
5
|
+
attr_reader :code, :cause, :resolution
|
6
|
+
|
7
|
+
def initialize(message, metadata = {})
|
8
|
+
super(message)
|
9
|
+
|
10
|
+
@code = metadata[:code]
|
11
|
+
@cause = metadata[:cause]
|
12
|
+
@resolution = metadata[:resolution]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
|
3
|
+
module PostcodeAnywhere
|
4
|
+
module EmailValidation
|
5
|
+
class Validator < ActiveModel::EachValidator
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
unless PostcodeAnywhere::EmailValidation.valid?(value)
|
8
|
+
record.errors.add(attribute, :invalid, value: value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'postcode_anywhere/email_validation/response'
|
2
|
+
require 'postcode_anywhere/email_validation/validation_error'
|
3
|
+
require 'postcode_anywhere/email_validation/validator'
|
4
|
+
require 'postcode_anywhere/email_validation/version'
|
5
|
+
|
6
|
+
require 'rest_client'
|
7
|
+
|
8
|
+
module PostcodeAnywhere
|
9
|
+
module EmailValidation
|
10
|
+
|
11
|
+
HOST = 'http://services.postcodeanywhere.co.uk/' +
|
12
|
+
'EmailValidation/Interactive/Validate/v1.10/json3.ws'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :key
|
16
|
+
|
17
|
+
def valid?(email)
|
18
|
+
json = RestClient.get(HOST, params: { Key: key, Email: email })
|
19
|
+
response = Response.parse(json)
|
20
|
+
|
21
|
+
response.valid?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'postcode_anywhere/email_validation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'postcode_anywhere-email_validation'
|
8
|
+
spec.version = PostcodeAnywhere::EmailValidation::VERSION
|
9
|
+
spec.authors = ['Andrew Garner', 'Pablo Manrubia']
|
10
|
+
spec.email = ['andrew@surefirething.co.uk', 'pablo@advera.co.uk']
|
11
|
+
spec.description = %q{Verify the existence of an email address.}
|
12
|
+
spec.summary = %q{Verifies the existence of an email address using the Email Validation web services from PostcodeAnywhere.}
|
13
|
+
spec.homepage = 'https://github.com/moneyadviceservice/postcode_anywhere-email_validation'
|
14
|
+
spec.date = "2013-06-04"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
spec.required_ruby_version = '>= 1.9.2'
|
20
|
+
|
21
|
+
spec.add_dependency 'rest-client', '~> 1.6'
|
22
|
+
spec.add_dependency 'activemodel', '~> 3.2'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'capybara', '~> 2.1'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'vcr', '~> 2.4'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.0'
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Validating an email address', :vcr do
|
4
|
+
|
5
|
+
background do
|
6
|
+
PostcodeAnywhere::EmailValidation.key = ENV['POSTCODE_ANYWHERE_KEY']
|
7
|
+
end
|
8
|
+
|
9
|
+
scenario 'With valid format and valid DNS record' do
|
10
|
+
expect(PostcodeAnywhere::EmailValidation.valid?('info@google.com')).to be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
scenario 'With invalid format' do
|
14
|
+
expect(PostcodeAnywhere::EmailValidation.valid?('@google.com')).to be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
scenario 'With invalid DNS record' do
|
18
|
+
expect(PostcodeAnywhere::EmailValidation.valid?('info@google.google')).to be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
scenario 'Without API key' do
|
22
|
+
PostcodeAnywhere::EmailValidation.key = 'AA11-AA11-AA11-AA11'
|
23
|
+
|
24
|
+
expect { PostcodeAnywhere::EmailValidation.valid?('info@google.com') }.to raise_error(PostcodeAnywhere::EmailValidation::ValidationError)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'ActiveModel validator', :vcr do
|
4
|
+
background do
|
5
|
+
PostcodeAnywhere::EmailValidation.key = ENV['POSTCODE_ANYWHERE_KEY']
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { ValidatedClass.new }
|
9
|
+
|
10
|
+
context 'with invalid values' do
|
11
|
+
%w(@example.com john.doe@).each do |value|
|
12
|
+
scenario "is not valid on value: #{value.inspect}" do
|
13
|
+
subject.email = value
|
14
|
+
expect(subject).to_not be_valid
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with valid values' do
|
21
|
+
%w(pablo@google.com fake@jsf.io).each do |value|
|
22
|
+
scenario "is not valid on value: #{value.inspect}" do
|
23
|
+
subject.email = value
|
24
|
+
expect(subject).to be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PostcodeAnywhere::EmailValidation
|
4
|
+
describe Response do
|
5
|
+
describe '.valid?' do
|
6
|
+
context 'when a DNS record is found and the format is valid' do
|
7
|
+
subject { described_class.new(true, true, nil) }
|
8
|
+
|
9
|
+
it { should be_valid }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when a DNS record is not found' do
|
13
|
+
subject { described_class.new(true, false, nil) }
|
14
|
+
|
15
|
+
it { should_not be_valid }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with invalid format' do
|
19
|
+
subject { described_class.new(false, true, nil) }
|
20
|
+
|
21
|
+
it { should_not be_valid }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'with an error' do
|
25
|
+
let(:error) { ValidationError.new('An error',
|
26
|
+
code: '999',
|
27
|
+
cause: 'A cause',
|
28
|
+
resolution: 'A resolution') }
|
29
|
+
|
30
|
+
subject { described_class.new(nil, nil, error) }
|
31
|
+
|
32
|
+
it 'raises a validation error' do
|
33
|
+
assertions = -> error {
|
34
|
+
expect(error).to be_instance_of(ValidationError)
|
35
|
+
expect(error.to_s).to eql('An error')
|
36
|
+
expect(error.code).to eql('999')
|
37
|
+
expect(error.cause).to eql('A cause')
|
38
|
+
expect(error.resolution).to eql('A resolution')
|
39
|
+
}
|
40
|
+
|
41
|
+
expect { subject.valid? }.to raise_error(&assertions)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#parse' do
|
47
|
+
subject { described_class.parse(json) }
|
48
|
+
|
49
|
+
context 'with a successful response' do
|
50
|
+
let(:json) do
|
51
|
+
'
|
52
|
+
{
|
53
|
+
"Items": [
|
54
|
+
{
|
55
|
+
"Email":"john.doe@example.com",
|
56
|
+
"MailServer":"mail.example.com",
|
57
|
+
"ValidFormat":true,
|
58
|
+
"FoundDnsRecord":true
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns a response' do
|
66
|
+
described_class.should_receive(:new).with(true, true, nil).and_return :response
|
67
|
+
|
68
|
+
expect(subject).to eql(:response)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with an error response' do
|
73
|
+
let(:json) do
|
74
|
+
'
|
75
|
+
{"Items":
|
76
|
+
[
|
77
|
+
{
|
78
|
+
"Error":"999",
|
79
|
+
"Description":"An error",
|
80
|
+
"Cause":"A cause",
|
81
|
+
"Resolution":"A resolution"
|
82
|
+
}
|
83
|
+
]
|
84
|
+
}
|
85
|
+
'
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'parses the error details' do
|
89
|
+
ValidationError.should_receive(:new).with('An error',
|
90
|
+
code: '999',
|
91
|
+
cause: 'A cause',
|
92
|
+
resolution: 'A resolution')
|
93
|
+
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns a response' do
|
98
|
+
described_class.should_receive(:new).with(nil, nil, an_instance_of(ValidationError)).and_return(:response)
|
99
|
+
|
100
|
+
expect(subject).to eql(:response)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PostcodeAnywhere::EmailValidation
|
4
|
+
describe ValidationError do
|
5
|
+
subject { described_class.new('An error') }
|
6
|
+
|
7
|
+
it { should be_kind_of(StandardError) }
|
8
|
+
|
9
|
+
it { should respond_to :message }
|
10
|
+
it { should respond_to :code }
|
11
|
+
it { should respond_to :cause }
|
12
|
+
it { should respond_to :resolution }
|
13
|
+
|
14
|
+
its(:to_s) { should eql('An error') }
|
15
|
+
|
16
|
+
context 'with metadata' do
|
17
|
+
subject do
|
18
|
+
described_class.new('An error',
|
19
|
+
code: '0',
|
20
|
+
cause: 'A cause',
|
21
|
+
resolution: 'A resolution')
|
22
|
+
end
|
23
|
+
|
24
|
+
its(:code) { should eql('0') }
|
25
|
+
its(:cause) { should eql('A cause') }
|
26
|
+
its(:resolution) { should eql('A resolution') }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PostcodeAnywhere
|
4
|
+
module EmailValidation
|
5
|
+
|
6
|
+
describe Validator do
|
7
|
+
|
8
|
+
subject { ::ValidatedClass.new }
|
9
|
+
|
10
|
+
context 'Using Postcode Anywhere' do
|
11
|
+
before { subject.email = 'an_email' }
|
12
|
+
|
13
|
+
it 'is valid if service returns true' do
|
14
|
+
PostcodeAnywhere::EmailValidation.should_receive(:valid?).with('an_email').and_return false
|
15
|
+
expect(subject).to_not be_valid
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'is invalid if service returns false' do
|
19
|
+
PostcodeAnywhere::EmailValidation.should_receive(:valid?).with('an_email').and_return true
|
20
|
+
expect(subject).to be_valid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PostcodeAnywhere
|
4
|
+
describe EmailValidation do
|
5
|
+
it { should respond_to(:key) }
|
6
|
+
it { should respond_to(:valid?).with(1).argument }
|
7
|
+
|
8
|
+
describe ".valid?" do
|
9
|
+
subject { described_class.valid?('john.doe@example.com') }
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
described_class.key = :the_key
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
stub_const('PostcodeAnywhere::EmailValidation::HOST', :host)
|
17
|
+
|
18
|
+
RestClient.
|
19
|
+
should_receive(:get).
|
20
|
+
with(:host, params: { Key: :the_key, Email: 'john.doe@example.com' }).
|
21
|
+
and_return(json)
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with a valid email and a DNS record is found' do
|
25
|
+
let(:json) { build_json }
|
26
|
+
|
27
|
+
it { should be_true }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with invalid email' do
|
31
|
+
let(:json) { build_json(ValidFormat: false) }
|
32
|
+
|
33
|
+
it { should be_false }
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when a DNS entry is not found' do
|
37
|
+
let(:json) { build_json(FoundDnsRecord: false) }
|
38
|
+
|
39
|
+
it { should be_false }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with an error' do
|
43
|
+
let(:json) do
|
44
|
+
%[
|
45
|
+
{"Items":
|
46
|
+
[
|
47
|
+
{
|
48
|
+
"Error":"999",
|
49
|
+
"Description":"An error",
|
50
|
+
"Cause":"A cause",
|
51
|
+
"Resolution":"A resolution"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'raises an exception when error' do
|
59
|
+
expect { subject }.to raise_error(EmailValidation::ValidationError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def build_json(options = {})
|
65
|
+
default_options = { Email: 'john.doe@example.com',
|
66
|
+
MailServer: 'mail.example.com',
|
67
|
+
ValidFormat: true,
|
68
|
+
FoundDnsRecord: true }
|
69
|
+
|
70
|
+
{ Items: [default_options.merge(options)] }.to_json
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
ENV['POSTCODE_ANYWHERE_KEY'] ||= 'AA11-AA11-AA11-AA11'
|
2
|
+
|
3
|
+
require 'postcode_anywhere/email_validation'
|
4
|
+
|
5
|
+
require 'capybara/rspec'
|
6
|
+
require 'vcr'
|
7
|
+
require 'pry'
|
8
|
+
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
10
|
+
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
17
|
+
end
|
18
|
+
|
19
|
+
config.around(:each, :vcr) do |example|
|
20
|
+
name = example.metadata[:full_description].downcase.gsub(/[^\w\/]+/, '_')
|
21
|
+
|
22
|
+
VCR.use_cassette(name) { example.call }
|
23
|
+
end
|
24
|
+
|
25
|
+
config.order = 'random'
|
26
|
+
end
|
27
|
+
|
28
|
+
VCR.configure do |config|
|
29
|
+
config.cassette_library_dir = 'spec/support/fixtures/vcr_cassettes'
|
30
|
+
config.hook_into :webmock
|
31
|
+
config.filter_sensitive_data('{{Key}}') { ENV['POSTCODE_ANYWHERE_KEY'] }
|
32
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://services.postcodeanywhere.co.uk/EmailValidation/Interactive/Validate/v1.10/json3.ws?Email=@example.com&Key={{Key}}
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*; q=0.5, application/xml'
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: !binary |-
|
20
|
+
T0s=
|
21
|
+
headers:
|
22
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
23
|
+
- !binary |-
|
24
|
+
bm8tY2FjaGU=
|
25
|
+
!binary "UHJhZ21h":
|
26
|
+
- !binary |-
|
27
|
+
bm8tY2FjaGU=
|
28
|
+
!binary "Q29udGVudC1UeXBl":
|
29
|
+
- !binary |-
|
30
|
+
YXBwbGljYXRpb24vanNvbjtjaGFyc2V0PVVURi04
|
31
|
+
!binary "Q29udGVudC1FbmNvZGluZw==":
|
32
|
+
- !binary |-
|
33
|
+
Z3ppcA==
|
34
|
+
!binary "RXhwaXJlcw==":
|
35
|
+
- !binary |-
|
36
|
+
LTE=
|
37
|
+
!binary "U2VydmVy":
|
38
|
+
- !binary |-
|
39
|
+
TWljcm9zb2Z0LUlJUy83LjU=
|
40
|
+
!binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctT3JpZ2lu":
|
41
|
+
- !binary |-
|
42
|
+
Kg==
|
43
|
+
!binary "QWNjZXNzLUNvbnRyb2wtQWxsb3ctSGVhZGVycw==":
|
44
|
+
- !binary |-
|
45
|
+
Q29udGVudC1UeXBl
|
46
|
+
!binary "UmVjb3Jkcw==":
|
47
|
+
- !binary |-
|
48
|
+
MQ==
|
49
|
+
!binary "WC1Bc3BuZXQtVmVyc2lvbg==":
|
50
|
+
- !binary |-
|
51
|
+
NC4wLjMwMzE5
|
52
|
+
!binary "WC1Qb3dlcmVkLUJ5":
|
53
|
+
- !binary |-
|
54
|
+
QVNQLk5FVA==
|
55
|
+
!binary "RGF0ZQ==":
|
56
|
+
- !binary |-
|
57
|
+
VHVlLCAwNCBKdW4gMjAxMyAxNTowNjo0NyBHTVQ=
|
58
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
59
|
+
- !binary |-
|
60
|
+
MTk1
|
61
|
+
body:
|
62
|
+
encoding: ASCII-8BIT
|
63
|
+
string: !binary |-
|
64
|
+
H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3m
|
65
|
+
kuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZk
|
66
|
+
AWz2zkrayZ4hgKrIHz9+fB8/In7xR2dtvmg+evS9X/zR6SIryo8effTR6KMv
|
67
|
+
6LfXeX2Z1/L3T2ZlMXtW1Yus/ejReVY2+eijZ9V6OXu6bF7l06qe6ce/5Pu/
|
68
|
+
5P8JAAD//yqv5RRTAAAA
|
69
|
+
http_version:
|
70
|
+
recorded_at: Tue, 04 Jun 2013 15:06:57 GMT
|
71
|
+
recorded_with: VCR 2.5.0
|