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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9268cdfd8adf22bf8c53aaccb317df2ca89c73d
4
- data.tar.gz: 0c875f61b52640e85ea599761af5eba0894d431e
3
+ metadata.gz: 2c358b49dba6da5733e1237ac5720e346841e86d
4
+ data.tar.gz: 719bab74ee4ad157eb5ee0dd43c770acd88d7ae6
5
5
  SHA512:
6
- metadata.gz: 1fba2b844ea0d21a932f734804954ab41b9422ea4554edd340ac297283e463c5b29752cd62065541180c8f1f452e67e50377d3eaa5eebf646679af085ede140d
7
- data.tar.gz: f35f86c72f10877bd0de0442241ac93284e5cd4cf49862420b01646f5a19c1d2abcf2a9840509dc6626463398f7051e3b6a5d5ed4a19ddba5c101129383375c5
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
- unless @response
52
+ if @response == nil || @response.code != 200
51
53
  begin
52
- r = @resource[@unique_id].get
53
- @response = JSON.parse(r)
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
- @response
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
@@ -1,3 +1,3 @@
1
1
  module Verifalia
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -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(response)
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(:completed_query) do
148
- { "progress"=> { "noOfTotalEntries" => 1, "noOfCompletedEntries" => 1 } }
149
- end
150
- let(:incompleted_query) do
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
- it 'should return true if completed' do
155
- expect(@email_validations).to receive(:query).and_return(completed_query)
156
- expect(@email_validations.completed?).to be true
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
- it 'should return false if not completed' do
160
- expect(@email_validations).to receive(:query).and_return(incompleted_query)
161
- expect(@email_validations.completed?).to be false
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verifalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Verifalia