verifalia 1.0.3 → 1.1.0
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 +4 -4
- data/README.md +35 -1
- data/lib/rest/client.rb +13 -13
- data/lib/rest/email_validations.rb +14 -4
- data/lib/verifalia/version.rb +1 -1
- data/spec/rest/email_validations_spec.rb +44 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc088dd144b948e544784c59efe27b5ccb8fe225
|
4
|
+
data.tar.gz: 1164f7c900fce6f4d16eddad18c9fefe3f87b345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2b30d6e970065d07f88be34ad8a393c16aea08497054dcbd8ed21f3e9183b03fc4b89f1950ed033eaee4562db3aa36a9cfe7c3f58cd0a3ff7c93150676ec0a
|
7
|
+
data.tar.gz: 91e06b91158db5bff1465e86d318603a7c39278611cfe009c5e916f21fa7f8d7cb84e9549445dd1126b10a61da1f8de0c1961361b6654cd18e33411b956307e1
|
data/README.md
CHANGED
@@ -64,6 +64,40 @@ else
|
|
64
64
|
error = @client.email_validations.error
|
65
65
|
end
|
66
66
|
|
67
|
+
##with additional email data
|
68
|
+
emails = [
|
69
|
+
{ inputData: 'alice@example.com', custom: 'custom data' }, #view verifalia API documentation
|
70
|
+
{ inputData: 'bob@example.net', custom: 'custom data' } #view verifalia API documentation
|
71
|
+
]
|
72
|
+
if (unique_id = @client.email_validations.verify(emails))
|
73
|
+
#response is an hash with all the values returned
|
74
|
+
response = @client.email_validations.query
|
75
|
+
@client.email_validations.destroy
|
76
|
+
else
|
77
|
+
#error is HTTP status code in symbol (:bad_request)
|
78
|
+
error = @client.email_validations.error
|
79
|
+
end
|
80
|
+
|
81
|
+
##with additional options data
|
82
|
+
emails = [
|
83
|
+
{ inputData: 'alice@example.com', custom: 'custom data' }, #view verifalia API documentation
|
84
|
+
{ inputData: 'bob@example.net', custom: 'custom data' } #view verifalia API documentation
|
85
|
+
]
|
86
|
+
options = { #view verifalia API documentation
|
87
|
+
quality: 'high',
|
88
|
+
priority: 100,
|
89
|
+
deduplication: 'safe'
|
90
|
+
}
|
91
|
+
|
92
|
+
if (unique_id = @client.email_validations.verify(emails, options))
|
93
|
+
#response is an hash with all the values returned
|
94
|
+
response = @client.email_validations.query
|
95
|
+
@client.email_validations.destroy
|
96
|
+
else
|
97
|
+
#error is HTTP status code in symbol (:bad_request)
|
98
|
+
error = @client.email_validations.error
|
99
|
+
end
|
100
|
+
|
67
101
|
|
68
102
|
##with previous unique id
|
69
103
|
unique_id = "example-example"
|
@@ -71,7 +105,7 @@ unique_id = "example-example"
|
|
71
105
|
#query job
|
72
106
|
response = @client.email_validations(unique_id: unique_id).query
|
73
107
|
|
74
|
-
#delete job
|
108
|
+
#delete job
|
75
109
|
@client.email_validations(unique_id: unique_id).destroy
|
76
110
|
|
77
111
|
# checking job status
|
data/lib/rest/client.rb
CHANGED
@@ -19,16 +19,16 @@ module Verifalia
|
|
19
19
|
# ==== @client.email_validations
|
20
20
|
#
|
21
21
|
class Client
|
22
|
-
|
22
|
+
|
23
23
|
attr_reader :account_sid, :account_token
|
24
|
-
|
25
|
-
API_VERSION = 'v1.
|
26
|
-
|
24
|
+
|
25
|
+
API_VERSION = 'v1.4'
|
26
|
+
|
27
27
|
DEFAULTS = {
|
28
28
|
host: 'https://api.verifalia.com',
|
29
|
-
api_version: 'v1.
|
29
|
+
api_version: 'v1.4'
|
30
30
|
}
|
31
|
-
|
31
|
+
|
32
32
|
##
|
33
33
|
# Instantiate a new HTTP client to talk to Verifalia. The parameters
|
34
34
|
# +account_sid+ and +auth_token+ are required, unless you have configured
|
@@ -46,17 +46,17 @@ module Verifalia
|
|
46
46
|
@config = DEFAULTS.merge! options
|
47
47
|
@account_sid = args[0] || Verifalia.account_sid
|
48
48
|
@auth_token = args[1] || Verifalia.auth_token
|
49
|
-
|
49
|
+
|
50
50
|
if @account_sid.nil? || @auth_token.nil?
|
51
51
|
raise ArgumentError, 'Account SID and auth token are required'
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
##
|
57
|
-
# Instantiate a new HTTP client to talk to Verifalia Email Validation Api.
|
57
|
+
# Instantiate a new HTTP client to talk to Verifalia Email Validation Api.
|
58
58
|
# The +args+ parameter is a hash of configuration
|
59
|
-
# The following keys are supported:
|
59
|
+
# The following keys are supported:
|
60
60
|
#
|
61
61
|
# === <tt>unique_id: 'example-example'</tt>
|
62
62
|
#
|
@@ -69,7 +69,7 @@ module Verifalia
|
|
69
69
|
EmailValidations.new @config, @account_sid, @auth_token, args
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
end
|
74
74
|
end
|
75
|
-
end
|
75
|
+
end
|
@@ -25,10 +25,20 @@ module Verifalia
|
|
25
25
|
#
|
26
26
|
# An array of emails to validate
|
27
27
|
#
|
28
|
-
def verify(
|
29
|
-
raise ArgumentError, '
|
30
|
-
|
31
|
-
|
28
|
+
def verify(inputs, options = {})
|
29
|
+
raise ArgumentError, 'inputs must be not empty' if (inputs.nil? || inputs.empty?)
|
30
|
+
raise ArgumentError, 'options must be hash' if (!options.is_a?(Hash))
|
31
|
+
data = inputs.map do |input|
|
32
|
+
if (input.is_a? String)
|
33
|
+
{ inputData: input }
|
34
|
+
elsif (input.is_a? Hash)
|
35
|
+
raise ArgumentError, 'if inputs content is a Hash you need to supply :inputData as key' if (!input.has_key?(:inputData))
|
36
|
+
input
|
37
|
+
else
|
38
|
+
raise ArgumentError, 'inputs content must be a String or a Hash'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
content = ({ entries: data }.merge(options)).to_json
|
32
42
|
begin
|
33
43
|
r = @resource.post content
|
34
44
|
@unique_id = JSON.parse(r)["uniqueID"]
|
data/lib/verifalia/version.rb
CHANGED
@@ -51,7 +51,25 @@ describe Verifalia::REST::EmailValidations do
|
|
51
51
|
expect{ @email_validations.verify([]) }.to raise_error(ArgumentError)
|
52
52
|
end
|
53
53
|
|
54
|
-
it '
|
54
|
+
it 'raise ArgumentError with unvalid options' do
|
55
|
+
emails = ['first', 'second']
|
56
|
+
expect{ @email_validations.verify(emails, 'a string') }.to raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
it 'raise ArgumentError with with hash array parameters with invalid value' do
|
61
|
+
inputs = [
|
62
|
+
{
|
63
|
+
fakeKey: 'fake second'
|
64
|
+
},
|
65
|
+
{
|
66
|
+
fakeKey: 'fake second'
|
67
|
+
}
|
68
|
+
]
|
69
|
+
expect{ @email_validations.verify(inputs) }.to raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'call #post on @resources with string array parameters' do
|
55
73
|
emails = ['first', 'second']
|
56
74
|
data = emails.map { |email| { inputData: email }}
|
57
75
|
content = { entries: data }.to_json
|
@@ -60,6 +78,31 @@ describe Verifalia::REST::EmailValidations do
|
|
60
78
|
@email_validations.verify(emails)
|
61
79
|
end
|
62
80
|
|
81
|
+
it 'call #post on @resources with string array parameters and options' do
|
82
|
+
emails = ['first', 'second']
|
83
|
+
options = { option_1: 'test' }
|
84
|
+
data = emails.map { |email| { inputData: email }}
|
85
|
+
content = { entries: data, option_1: 'test' }.to_json
|
86
|
+
expect(resource).to receive(:post).with(content).and_return(response)
|
87
|
+
expect(JSON).to receive(:parse).with(response).and_return(response_json)
|
88
|
+
@email_validations.verify(emails, options)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'call #post on @resources with hash array parameters with valid value' do
|
92
|
+
data = [
|
93
|
+
{
|
94
|
+
inputData: 'first'
|
95
|
+
},
|
96
|
+
{
|
97
|
+
inputData: 'second'
|
98
|
+
}
|
99
|
+
]
|
100
|
+
content = { entries: data }.to_json
|
101
|
+
expect(resource).to receive(:post).with(content).and_return(response)
|
102
|
+
expect(JSON).to receive(:parse).with(response).and_return(response_json)
|
103
|
+
@email_validations.verify(data)
|
104
|
+
end
|
105
|
+
|
63
106
|
it 'associate @unique_id and clear @response and @error' do
|
64
107
|
emails = ['first', 'second']
|
65
108
|
unique_id = 'fake'
|