verifalia 1.2.0 → 2.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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +5 -5
  3. data/LICENSE +3 -4
  4. data/README.md +415 -82
  5. data/Rakefile +4 -0
  6. data/lib/verifalia/client.rb +89 -0
  7. data/lib/verifalia/credits/balance.rb +59 -0
  8. data/lib/verifalia/credits/client.rb +54 -0
  9. data/lib/verifalia/email_validation/client.rb +237 -0
  10. data/lib/verifalia/email_validation/completion_callback.rb +44 -0
  11. data/lib/verifalia/email_validation/entry.rb +124 -0
  12. data/lib/verifalia/email_validation/entry_classification.rb +49 -0
  13. data/lib/verifalia/email_validation/entry_status.rb +181 -0
  14. data/lib/verifalia/email_validation/exported_entries_format.rb +46 -0
  15. data/lib/verifalia/email_validation/job.rb +107 -0
  16. data/lib/verifalia/email_validation/job_status.rb +49 -0
  17. data/lib/verifalia/email_validation/overview.rb +108 -0
  18. data/lib/verifalia/email_validation/progress.rb +48 -0
  19. data/lib/verifalia/email_validation/request.rb +48 -0
  20. data/lib/verifalia/email_validation/request_entry.rb +43 -0
  21. data/lib/verifalia/email_validation/wait_options.rb +82 -0
  22. data/lib/verifalia/rest/client.rb +111 -0
  23. data/lib/verifalia/security/certificate_authenticator.rb +50 -0
  24. data/lib/verifalia/security/username_password_authenticator.rb +51 -0
  25. data/lib/verifalia.rb +49 -21
  26. data/sig/completion_callback.rbs +5 -0
  27. data/sig/verifalia/client.rbs +11 -0
  28. data/sig/verifalia/credits/balance.rbs +11 -0
  29. data/sig/verifalia/credits/client.rbs +7 -0
  30. data/sig/verifalia/email_validations/client.rbs +24 -0
  31. data/sig/verifalia/email_validations/entry.rbs +24 -0
  32. data/sig/verifalia/email_validations/entry_classification.rbs +10 -0
  33. data/sig/verifalia/email_validations/entry_status.rbs +50 -0
  34. data/sig/verifalia/email_validations/exported_entries_format.rbs +9 -0
  35. data/sig/verifalia/email_validations/job.rbs +13 -0
  36. data/sig/verifalia/email_validations/job_status.rbs +10 -0
  37. data/sig/verifalia/email_validations/overview.rbs +20 -0
  38. data/sig/verifalia/email_validations/progress.rbs +8 -0
  39. data/sig/verifalia/email_validations/request.rbs +13 -0
  40. data/sig/verifalia/email_validations/request_entry.rbs +8 -0
  41. data/sig/verifalia/email_validations/wait_options.rbs +20 -0
  42. data/sig/verifalia/rest/client.rbs +12 -0
  43. data/sig/verifalia/rest.rbs +6 -0
  44. data/sig/verifalia/security/certificate_authenticator.rbs +8 -0
  45. data/sig/verifalia/security/username_password_authenticator.rbs +10 -0
  46. data/verifalia.gemspec +27 -18
  47. metadata +72 -64
  48. data/.gitignore +0 -24
  49. data/lib/rest/account_balance.rb +0 -93
  50. data/lib/rest/client.rb +0 -83
  51. data/lib/rest/email_validations.rb +0 -195
  52. data/lib/verifalia/util/configuration.rb +0 -7
  53. data/lib/verifalia/version.rb +0 -3
  54. data/spec/rest/account_balance_spec.rb +0 -93
  55. data/spec/rest/client_spec.rb +0 -105
  56. data/spec/rest/email_validations_spec.rb +0 -322
  57. data/spec/spec_helper.rb +0 -21
  58. data/spec/util/configuration_spec.rb +0 -15
  59. data/spec/verifalia_spec.rb +0 -17
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Verifalia::REST::AccountBalance do
4
- let(:config) { { hosts: ["https://api.fake.com", "https://api-2.fake.com"], api_version: "v" } }
5
-
6
- describe '#initialize' do
7
-
8
- it 'create RestClient::Resource with correct parameters' do
9
- opts = {
10
- user: 'someSid',
11
- password: 'someToken',
12
- headers: { content_type: :json, user_agent: "verifalia-rest-client/ruby/#{Verifalia::VERSION}" }
13
- }
14
- config[:hosts].each do |host|
15
- api_url = "#{host}/#{config[:api_version]}/account-balance"
16
- expect(RestClient::Resource).to receive(:new).with(api_url, opts)
17
- end
18
- Verifalia::REST::AccountBalance.new(config, 'someSid', 'someToken')
19
- end
20
-
21
- it 'associate RestClient::Resource to @resources' do
22
- resource = double()
23
- allow(RestClient::Resource).to receive(:new).and_return(resource)
24
- account_balance = Verifalia::REST::AccountBalance.new(config, 'someSid', 'someToken')
25
- expect(account_balance.instance_variable_get('@resources')).to include(resource)
26
- expect(account_balance.instance_variable_get('@resources').size).to eq(config[:hosts].size)
27
- end
28
- end
29
-
30
- context 'initialized' do
31
- let(:resources) { [ double().as_null_object, double().as_null_object ] }
32
- let(:response) { double().as_null_object }
33
- let(:response_json) { double().as_null_object }
34
-
35
- before(:each) do
36
- @account_balance = Verifalia::REST::AccountBalance.new(config, 'someSid', 'someToken')
37
- @account_balance.instance_variable_set('@resources', resources)
38
- end
39
-
40
- describe '#balance' do
41
-
42
- context 'without errors' do
43
- it 'call #get on @resources' do
44
- resources.each { |resource| allow(resource).to receive(:get).and_return(response) }
45
- expect(JSON).to receive(:parse).with(response).and_return(response_json)
46
- @account_balance.balance
47
- end
48
-
49
- it 'return parsed json' do
50
- parsed = double()
51
- resources.each { |resource| allow(resource).to receive(:get).and_return(response) }
52
- expect(JSON).to receive(:parse).and_return(parsed)
53
- result = @account_balance.balance
54
- expect(result).to eq(parsed)
55
- end
56
- end
57
-
58
- context 'request failed' do
59
-
60
- before(:each) do
61
- resources.each { |resource| allow(resource).to receive(:get).and_raise(RestClient::Exception.new(nil, 402))}
62
- end
63
-
64
- it 'raise exception, call #compute_error and return false' do
65
- result = @account_balance.balance
66
- expect(result).to eq(false)
67
- end
68
-
69
- it 'raise exception, call #compute_error and return correct error' do
70
- result = @account_balance.balance
71
- expect(result).to eq(false)
72
- expect(@account_balance.error).to eq(:payment_required)
73
- end
74
- end
75
-
76
- context 'with one request failed with 500' do
77
- before(:each) do
78
- expect(resources).to receive(:shuffle).and_return([resources[0], resources[1]])
79
- expect(resources[0]).to receive(:get).and_raise(RestClient::Exception.new(nil, 500))
80
- expect(resources[1]).to receive(:get).and_return(response)
81
- end
82
-
83
- it 'return parsed json' do
84
- parsed = double()
85
- expect(JSON).to receive(:parse).and_return(parsed)
86
- result = @account_balance.balance
87
- expect(result).to eq(parsed)
88
- end
89
- end
90
- end
91
- end
92
-
93
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Verifalia::REST::Client do
4
- describe 'config at class level' do
5
- after(:each) do
6
- Verifalia.instance_variable_set('@configuration', nil)
7
- end
8
-
9
- it 'should set the account sid and auth token with a config block' do
10
- Verifalia.configure do |config|
11
- config.account_sid = 'someSid'
12
- config.auth_token = 'someToken'
13
- end
14
-
15
- client = Verifalia::REST::Client.new
16
- expect(client.account_sid).to eq('someSid')
17
- expect(client.instance_variable_get('@auth_token')).to eq('someToken')
18
- end
19
-
20
- it 'should overwrite account sid and auth token if passed to initializer' do
21
- Verifalia.configure do |config|
22
- config.account_sid = 'someSid'
23
- config.auth_token = 'someToken'
24
- end
25
-
26
- client = Verifalia::REST::Client.new 'otherSid', 'otherToken'
27
- expect(client.account_sid).to eq('otherSid')
28
- expect(client.instance_variable_get('@auth_token')).to eq('otherToken')
29
- end
30
-
31
- it 'should overwrite the account sid if only the sid is given' do
32
- Verifalia.configure do |config|
33
- config.account_sid = 'someSid'
34
- config.auth_token = 'someToken'
35
- end
36
-
37
- client = Verifalia::REST::Client.new 'otherSid'
38
- expect(client.account_sid).to eq('otherSid')
39
- expect(client.instance_variable_get('@auth_token')).to eq('someToken')
40
- end
41
-
42
- it 'should allow options after setting up auth with config' do
43
- Verifalia.configure do |config|
44
- config.account_sid = 'someSid'
45
- config.auth_token = 'someToken'
46
- end
47
-
48
- client = Verifalia::REST::Client.new :hosts => ['api.fake.com']
49
-
50
- config = client.instance_variable_get('@config')
51
- expect(config[:hosts]).to eq(['api.fake.com'])
52
- end
53
-
54
- it 'should throw an argument error if the sid and token isn\'t set' do
55
- expect { Verifalia::REST::Client.new }.to raise_error(ArgumentError)
56
- end
57
-
58
- it 'should throw an argument error if only the account_sid is set' do
59
- expect { Verifalia::REST::Client.new 'someSid' }.to raise_error(ArgumentError)
60
- end
61
- end
62
-
63
- describe '#email_validations' do
64
- before(:each) do
65
- Verifalia.configure do |config|
66
- config.account_sid = 'someSid'
67
- config.auth_token = 'someToken'
68
- end
69
- @client = Verifalia::REST::Client.new
70
- end
71
-
72
- context 'without parameters' do
73
- it 'call #new on Verifalia::REST::EmailValidations with correct paramenters' do
74
- config = @client.instance_variable_get('@config')
75
- expect(Verifalia::REST::EmailValidations).to receive(:new).with(config, 'someSid', 'someToken')
76
- @client.email_validations
77
- end
78
- end
79
-
80
- context 'with parameter' do
81
- it 'call #new on Verifalia::REST::EmailValidations with correct paramenters' do
82
- config = @client.instance_variable_get('@config')
83
- expect(Verifalia::REST::EmailValidations).to receive(:new).with(config, 'someSid', 'someToken', :unique_id => 'fake')
84
- @client.email_validations(:unique_id => 'fake')
85
- end
86
- end
87
- end
88
-
89
-
90
- describe '#account_balance' do
91
- before(:each) do
92
- Verifalia.configure do |config|
93
- config.account_sid = 'someSid'
94
- config.auth_token = 'someToken'
95
- end
96
- @client = Verifalia::REST::Client.new
97
- end
98
-
99
- it 'call #new on Verifalia::REST::AccountBalance with correct paramenters' do
100
- config = @client.instance_variable_get('@config')
101
- expect(Verifalia::REST::AccountBalance).to receive(:new).with(config, 'someSid', 'someToken')
102
- @client.account_balance
103
- end
104
- end
105
- end
@@ -1,322 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Verifalia::REST::EmailValidations do
4
- let(:config) { { hosts: ["https://api.fake.com", "https://api-2.fake.com"], api_version: "v" } }
5
-
6
- describe '#initialize' do
7
-
8
- it 'create RestClient::Resource with correct parameters' do
9
- opts = {
10
- user: 'someSid',
11
- password: 'someToken',
12
- headers: { content_type: :json, user_agent: "verifalia-rest-client/ruby/#{Verifalia::VERSION}" }
13
- }
14
- config[:hosts].each do |host|
15
- api_url = "#{host}/#{config[:api_version]}/email-validations"
16
- expect(RestClient::Resource).to receive(:new).with(api_url, opts)
17
- end
18
- Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
19
- end
20
-
21
- it 'associate RestClient::Resource to @resources' do
22
- resource = double()
23
- allow(RestClient::Resource).to receive(:new).and_return(resource)
24
- email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
25
- expect(email_validations.instance_variable_get('@resources')).to include(resource)
26
- expect(email_validations.instance_variable_get('@resources').size).to eq(config[:hosts].size)
27
- end
28
-
29
- it 'associate :unique_id to @unique_id' do
30
- unique_id = double()
31
- email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken', unique_id: unique_id)
32
- expect(email_validations.instance_variable_get('@unique_id')).to eq(unique_id)
33
- end
34
-
35
- end
36
-
37
- context 'initialized' do
38
- let(:resources) { [ double().as_null_object, double().as_null_object ] }
39
- let(:response) { double().as_null_object }
40
- let(:response_json) { double().as_null_object }
41
- before(:each) do
42
- @email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
43
- @email_validations.instance_variable_set('@resources', resources)
44
- end
45
-
46
- describe '#verify' do
47
-
48
- it 'raise ArgumentError with nil emails' do
49
- expect{ @email_validations.verify(nil) }.to raise_error(ArgumentError)
50
- end
51
-
52
- it 'raise ArgumentError with empty emails' do
53
- expect{ @email_validations.verify([]) }.to raise_error(ArgumentError)
54
- end
55
-
56
- it 'raise ArgumentError with unvalid options' do
57
- emails = ['first', 'second']
58
- expect{ @email_validations.verify(emails, 'a string') }.to raise_error(ArgumentError)
59
- end
60
-
61
-
62
- it 'raise ArgumentError with with hash array parameters with invalid value' do
63
- inputs = [
64
- {
65
- fakeKey: 'fake second'
66
- },
67
- {
68
- fakeKey: 'fake second'
69
- }
70
- ]
71
- expect{ @email_validations.verify(inputs) }.to raise_error(ArgumentError)
72
- end
73
-
74
- context 'without errors' do
75
-
76
- it 'call #post on resource with string array parameters' do
77
- emails = ['first', 'second']
78
- data = emails.map { |email| { inputData: email }}
79
- content = { entries: data }.to_json
80
- resources.each { |resource| allow(resource).to receive(:post).with(content).and_return(response) }
81
- expect(JSON).to receive(:parse).with(response).and_return(response_json)
82
- @email_validations.verify(emails)
83
- end
84
-
85
- it 'call #post on resource with string array parameters and options' do
86
- emails = ['first', 'second']
87
- options = { option_1: 'test' }
88
- data = emails.map { |email| { inputData: email }}
89
- content = { entries: data, option_1: 'test' }.to_json
90
- resources.each { |resource| allow(resource).to receive(:post).with(content).and_return(response) }
91
- expect(JSON).to receive(:parse).with(response).and_return(response_json)
92
- @email_validations.verify(emails, options)
93
- end
94
-
95
- it 'call #post on @resources with hash array parameters with valid value' do
96
- data = [
97
- {
98
- inputData: 'first'
99
- },
100
- {
101
- inputData: 'second'
102
- }
103
- ]
104
- content = { entries: data }.to_json
105
- resources.each { |resource| allow(resource).to receive(:post).with(content).and_return(response) }
106
- expect(JSON).to receive(:parse).with(response).and_return(response_json)
107
- @email_validations.verify(data)
108
- end
109
-
110
- it 'associate @unique_id' do
111
- emails = ['first', 'second']
112
- unique_id = 'fake'
113
- parsed = double()
114
- expect(JSON).to receive(:parse).and_return(parsed)
115
- expect(parsed).to receive(:[]).with("uniqueID").and_return(unique_id)
116
- @email_validations.verify(emails)
117
- expect(@email_validations.instance_variable_get('@unique_id')).to eq(unique_id)
118
- end
119
-
120
- it 'return @unique_id' do
121
- emails = ['first', 'second']
122
- unique_id = 'fake'
123
- parsed = double()
124
- expect(JSON).to receive(:parse).and_return(parsed)
125
- expect(parsed).to receive(:[]).with("uniqueID").and_return(unique_id)
126
- result = @email_validations.verify(emails)
127
- expect(result).to eq(unique_id)
128
- end
129
- end
130
-
131
- context 'requests failed' do
132
-
133
- before(:each) do
134
- resources.each { |resource| allow(resource).to receive(:post).and_raise(RestClient::Exception.new(nil, 402))}
135
- end
136
-
137
- it 'raise exception, call #compute_error and return false' do
138
- emails = ['first', 'second']
139
- result = @email_validations.verify(emails)
140
- expect(result).to eq(false)
141
- end
142
-
143
- it 'raise exception, call #compute_error and return correct error' do
144
- emails = ['first', 'second']
145
- result = @email_validations.verify(emails)
146
- expect(result).to eq(false)
147
- expect(@email_validations.error).to eq(:payment_required)
148
- end
149
- end
150
-
151
- context 'with one request failed with 500' do
152
- before(:each) do
153
- expect(resources).to receive(:shuffle).and_return([resources[0], resources[1]])
154
- expect(resources[0]).to receive(:post).and_raise(RestClient::Exception.new(nil, 500))
155
- expect(resources[1]).to receive(:post).and_return(response)
156
- end
157
-
158
- it 'should return @unique_id' do
159
- emails = ['first', 'second']
160
- unique_id = 'fake'
161
- expect(JSON).to receive(:parse).with(response).and_return(response_json)
162
- expect(response_json).to receive(:[]).with("uniqueID").and_return(unique_id)
163
- result = @email_validations.verify(emails)
164
- expect(result).to eq(unique_id)
165
- end
166
- end
167
- end
168
-
169
- describe '#query' do
170
- it 'raise ArgumentError without @unique_id' do
171
- expect{ @email_validations.query }.to raise_error(ArgumentError)
172
- end
173
-
174
- context 'with @unique_id' do
175
- before(:each) do
176
- @email_validations.instance_variable_set('@unique_id', 'fake')
177
- end
178
-
179
- context 'without errors' do
180
- it 'call #get on @resource[@uniqueId] with correct parameters' do
181
- request = double()
182
- resources.each do |resource|
183
- allow(resource).to receive(:[]).with('fake').and_return(request)
184
- allow(request).to receive(:get).and_return(double().as_null_object)
185
- end
186
- expect(JSON).to receive(:parse)
187
- @email_validations.query
188
- end
189
-
190
- it 'should return parsed json' do
191
- request = double()
192
- parsed = double()
193
- resources.each do |resource|
194
- allow(resource).to receive(:[]).with('fake').and_return(request)
195
- allow(request).to receive(:get).and_return(double().as_null_object)
196
- end
197
- expect(JSON).to receive(:parse).and_return(parsed)
198
- result = @email_validations.query
199
- expect(result).to eq(parsed)
200
- end
201
-
202
- context 'with completion' do
203
- it 'call #get on @resource[@uniqueId] multiple time' do
204
- request = double()
205
- resources.each do |resource|
206
- allow(resource).to receive(:[]).with('fake').and_return(request)
207
- allow(request).to receive(:get).and_return(double().as_null_object)
208
- end
209
- allow(JSON).to receive(:parse)
210
- @email_validations.query(wait_for_completion: true, completion_max_retry: 2)
211
- end
212
- end
213
- end
214
-
215
- context 'request failed' do
216
-
217
- before(:each) do
218
- request = double()
219
- resources.each do |resource|
220
-
221
- end
222
- end
223
-
224
- it 'raise exception, call #compute_error and return false' do
225
- expect(@email_validations).to receive(:compute_error).and_return(double())
226
- result = @email_validations.query
227
- expect(result).to eq(false)
228
- end
229
- end
230
-
231
- context 'with one request failed with 500' do
232
- before(:each) do
233
- request_1 = double()
234
- request_2 = double()
235
- response = double()
236
- expect(resources).to receive(:shuffle).and_return([resources[0], resources[1]])
237
- expect(resources[0]).to receive(:[]).with('fake').and_return(request_1)
238
- expect(request_1).to receive(:get).and_raise(RestClient::Exception.new(nil, 500))
239
- expect(resources[1]).to receive(:[]).with('fake').and_return(request_2)
240
- allow(request_2).to receive(:get).and_return(double().as_null_object)
241
- end
242
-
243
- it 'should return parsed json' do
244
- parsed = double()
245
- expect(JSON).to receive(:parse).and_return(parsed)
246
- result = @email_validations.query
247
- expect(result).to eq(parsed)
248
- end
249
- end
250
- end
251
- end
252
-
253
- describe '#destroy' do
254
- it 'raise ArgumentError without @unique_id' do
255
- expect{ @email_validations.destroy }.to raise_error(ArgumentError)
256
- end
257
-
258
- context 'with @unique_id' do
259
- before(:each) do
260
- @email_validations.instance_variable_set('@unique_id', 'fake')
261
- end
262
-
263
- context 'without errors' do
264
-
265
- it 'call #delete on @resource[@uniqueId]' do
266
- request = double()
267
- resources.each do |resource|
268
- allow(resource).to receive(:[]).with('fake').and_return(request)
269
- allow(request).to receive(:delete).and_return(double().as_null_object)
270
- end
271
- @email_validations.destroy
272
- end
273
-
274
- it 'clear @response, @unique_id and @error' do
275
- request = double()
276
- resources.each do |resource|
277
- allow(resource).to receive(:[]).with('fake').and_return(request)
278
- allow(request).to receive(:delete).and_return(double().as_null_object)
279
- end
280
- @email_validations.destroy
281
- expect(@email_validations.instance_variable_get('@response')).to eq(nil)
282
- expect(@email_validations.instance_variable_get('@unique_id')).to eq(nil)
283
- expect(@email_validations.instance_variable_get('@error')).to eq(nil)
284
- end
285
-
286
- end
287
- end
288
- end
289
-
290
- describe '#completed?' do
291
- let(:response) { double().as_null_object }
292
-
293
- before(:each) do
294
- @email_validations.instance_variable_set('@response', response)
295
- end
296
-
297
-
298
- context 'with 202 http code response' do
299
- before(:each) do
300
- allow(response).to receive(:code).and_return(202)
301
- end
302
-
303
- it 'should return false' do
304
- expect(@email_validations.completed?).to be false
305
- end
306
- end
307
-
308
- context 'with 200 http code response' do
309
-
310
- before(:each) do
311
- allow(response).to receive(:code).and_return(200)
312
- end
313
-
314
- it 'should return true' do
315
- expect(@email_validations.completed?).to be true
316
- end
317
- end
318
- end
319
-
320
- end
321
-
322
- end
data/spec/spec_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
-
3
- require 'bundler'
4
- Bundler.setup
5
-
6
- require 'verifalia'
7
-
8
- RSpec.configure do |config|
9
- config.expect_with :rspec do |c|
10
- c.syntax = :expect
11
- end
12
- end
13
-
14
- if ENV["CI"]
15
- require 'coveralls'
16
- Coveralls.wear!
17
- else
18
- require "simplecov"
19
- SimpleCov.start
20
- end
21
-
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Verifalia::Util::Configuration do
4
- it 'should have an account sid attribute' do
5
- config = Verifalia::Util::Configuration.new
6
- config.account_sid = 'someSid'
7
- expect(config.account_sid).to eq('someSid')
8
- end
9
-
10
- it 'should have an auth token attribute' do
11
- config = Verifalia::Util::Configuration.new
12
- config.auth_token = 'someToken'
13
- expect(config.auth_token).to eq('someToken')
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Verifalia do
4
- after(:each) do
5
- Verifalia.instance_variable_set('@configuration', nil)
6
- end
7
-
8
- it 'should set the account sid and auth token with a config block' do
9
- Verifalia.configure do |config|
10
- config.account_sid = 'someSid'
11
- config.auth_token = 'someToken'
12
- end
13
-
14
- expect(Verifalia.account_sid).to eq('someSid')
15
- expect(Verifalia.auth_token).to eq('someToken')
16
- end
17
- end