verifalia 1.0.2 → 1.0.3
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/lib/rest/email_validations.rb +10 -7
- data/lib/verifalia/version.rb +1 -1
- data/spec/rest/email_validations_spec.rb +39 -14
- 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: 2c358b49dba6da5733e1237ac5720e346841e86d
|
4
|
+
data.tar.gz: 719bab74ee4ad157eb5ee0dd43c770acd88d7ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3229ddab59f599439431eb78da0a2db5f75ce200f8cc1d328d51e19e273da8a91d588d055c7cade4f8059af7a5681c487da79a1a25ae4f413ff7b6a1de27cd
|
7
|
+
data.tar.gz: 868e9a260e23e6f883b9c10ecfb421bb13c9c50a09d17b60238682f04fb47026ec27978500f78e4829a3a5997cdac6534bce6239ccba62495783ddb47a70f828
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
require 'json'
|
2
3
|
module Verifalia
|
3
4
|
module REST
|
4
5
|
class EmailValidations
|
@@ -33,6 +34,7 @@ module Verifalia
|
|
33
34
|
@unique_id = JSON.parse(r)["uniqueID"]
|
34
35
|
@response = nil
|
35
36
|
@error = nil
|
37
|
+
@query_result = nil
|
36
38
|
@unique_id
|
37
39
|
rescue => e
|
38
40
|
compute_error(e)
|
@@ -47,17 +49,17 @@ module Verifalia
|
|
47
49
|
#
|
48
50
|
def query
|
49
51
|
raise ArgumentError, 'You must call verify first or supply and uniqueId' unless @unique_id
|
50
|
-
|
52
|
+
if @response == nil || @response.code != 200
|
51
53
|
begin
|
52
|
-
|
53
|
-
@
|
54
|
+
@response = @resource[@unique_id].get
|
55
|
+
@query_result = JSON.parse(@response)
|
54
56
|
@error = nil
|
55
57
|
rescue => e
|
56
58
|
compute_error(e)
|
57
59
|
return false
|
58
60
|
end
|
59
61
|
end
|
60
|
-
@
|
62
|
+
@query_result
|
61
63
|
end
|
62
64
|
|
63
65
|
##
|
@@ -71,6 +73,7 @@ module Verifalia
|
|
71
73
|
r = @resource[@unique_id].delete
|
72
74
|
@error = nil
|
73
75
|
@response = nil
|
76
|
+
@query_result = nil
|
74
77
|
@unique_id = nil
|
75
78
|
true
|
76
79
|
rescue => e
|
@@ -85,7 +88,7 @@ module Verifalia
|
|
85
88
|
#
|
86
89
|
def completed?
|
87
90
|
query_progress = query["progress"]
|
88
|
-
query_progress["noOfTotalEntries"] == query_progress["noOfCompletedEntries"]
|
91
|
+
@response.code == 200 && query_progress["noOfTotalEntries"] == query_progress["noOfCompletedEntries"]
|
89
92
|
end
|
90
93
|
|
91
94
|
def error
|
@@ -119,8 +122,8 @@ module Verifalia
|
|
119
122
|
def build_resource(config, account_sid, account_token)
|
120
123
|
api_url = "#{config[:host]}/#{config[:api_version]}/email-validations"
|
121
124
|
opts = {
|
122
|
-
user: account_sid,
|
123
|
-
password: account_token,
|
125
|
+
user: account_sid,
|
126
|
+
password: account_token,
|
124
127
|
headers: { content_type: :json }
|
125
128
|
}
|
126
129
|
return RestClient::Resource.new api_url, opts
|
data/lib/verifalia/version.rb
CHANGED
@@ -8,8 +8,8 @@ describe Verifalia::REST::EmailValidations do
|
|
8
8
|
it 'create RestClient::Resource with correct parameters' do
|
9
9
|
api_url = "#{config[:host]}/#{config[:api_version]}/email-validations"
|
10
10
|
opts = {
|
11
|
-
user: 'someSid',
|
12
|
-
password: 'someToken',
|
11
|
+
user: 'someSid',
|
12
|
+
password: 'someToken',
|
13
13
|
headers: { content_type: :json }
|
14
14
|
}
|
15
15
|
|
@@ -35,6 +35,7 @@ describe Verifalia::REST::EmailValidations do
|
|
35
35
|
context 'initialized' do
|
36
36
|
let(:resource) { double().as_null_object }
|
37
37
|
let(:response) { double().as_null_object }
|
38
|
+
let(:response_json) { double().as_null_object }
|
38
39
|
before(:each) do
|
39
40
|
@email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
|
40
41
|
@email_validations.instance_variable_set('@resource', resource)
|
@@ -55,7 +56,7 @@ describe Verifalia::REST::EmailValidations do
|
|
55
56
|
data = emails.map { |email| { inputData: email }}
|
56
57
|
content = { entries: data }.to_json
|
57
58
|
expect(resource).to receive(:post).with(content).and_return(response)
|
58
|
-
expect(JSON).to receive(:parse).with(response).and_return(
|
59
|
+
expect(JSON).to receive(:parse).with(response).and_return(response_json)
|
59
60
|
@email_validations.verify(emails)
|
60
61
|
end
|
61
62
|
|
@@ -144,21 +145,45 @@ describe Verifalia::REST::EmailValidations do
|
|
144
145
|
end
|
145
146
|
|
146
147
|
describe '#completed?' do
|
147
|
-
let(:
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
{ "progress"=> { "noOfTotalEntries" => 0, "noOfCompletedEntries" => 1 } }
|
148
|
+
let(:response) { double().as_null_object }
|
149
|
+
|
150
|
+
before(:each) do
|
151
|
+
@email_validations.instance_variable_set('@response', response)
|
152
152
|
end
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
154
|
+
|
155
|
+
context 'with 202 http code response' do
|
156
|
+
before(:each) do
|
157
|
+
allow(response).to receive(:code).and_return(202)
|
158
|
+
allow(@email_validations).to receive(:query).and_return({ "progress" => nil })
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should return false' do
|
162
|
+
expect(@email_validations.completed?).to be false
|
163
|
+
end
|
157
164
|
end
|
158
165
|
|
159
|
-
|
160
|
-
|
161
|
-
|
166
|
+
context 'with 200 http code response' do
|
167
|
+
let(:completed_query) do
|
168
|
+
{ "progress"=> { "noOfTotalEntries" => 1, "noOfCompletedEntries" => 1 } }
|
169
|
+
end
|
170
|
+
let(:incompleted_query) do
|
171
|
+
{ "progress"=> { "noOfTotalEntries" => 0, "noOfCompletedEntries" => 1 } }
|
172
|
+
end
|
173
|
+
|
174
|
+
before(:each) do
|
175
|
+
allow(response).to receive(:code).and_return(200)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should return true if completed' do
|
179
|
+
allow(@email_validations).to receive(:query).and_return(completed_query)
|
180
|
+
expect(@email_validations.completed?).to be true
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should return false if not completed' do
|
184
|
+
allow(@email_validations).to receive(:query).and_return(incompleted_query)
|
185
|
+
expect(@email_validations.completed?).to be false
|
186
|
+
end
|
162
187
|
end
|
163
188
|
end
|
164
189
|
|