verifalia 1.2.0 → 2.0.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 (50) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +5 -5
  3. data/LICENSE +3 -4
  4. data/README.md +328 -82
  5. data/Rakefile +4 -0
  6. data/lib/verifalia/client.rb +60 -0
  7. data/lib/verifalia/credits/balance.rb +30 -0
  8. data/lib/verifalia/credits/client.rb +25 -0
  9. data/lib/verifalia/email_validation/client.rb +207 -0
  10. data/lib/verifalia/email_validation/completion_callback.rb +15 -0
  11. data/lib/verifalia/email_validation/entry.rb +89 -0
  12. data/lib/verifalia/email_validation/job.rb +75 -0
  13. data/lib/verifalia/email_validation/overview.rb +76 -0
  14. data/lib/verifalia/email_validation/progress.rb +19 -0
  15. data/lib/verifalia/email_validation/request.rb +19 -0
  16. data/lib/verifalia/email_validation/request_entry.rb +14 -0
  17. data/lib/verifalia/email_validation/wait_options.rb +53 -0
  18. data/lib/verifalia/rest/client.rb +82 -0
  19. data/lib/verifalia/security/certificate_authenticator.rb +21 -0
  20. data/lib/verifalia/security/username_password_authenticator.rb +22 -0
  21. data/lib/verifalia.rb +8 -23
  22. data/sig/completion_callback.rbs +5 -0
  23. data/sig/verifalia/client.rbs +11 -0
  24. data/sig/verifalia/credits/balance.rbs +11 -0
  25. data/sig/verifalia/credits/client.rbs +7 -0
  26. data/sig/verifalia/email_validations/client.rbs +24 -0
  27. data/sig/verifalia/email_validations/entry.rbs +22 -0
  28. data/sig/verifalia/email_validations/job.rbs +13 -0
  29. data/sig/verifalia/email_validations/overview.rbs +20 -0
  30. data/sig/verifalia/email_validations/progress.rbs +8 -0
  31. data/sig/verifalia/email_validations/request.rbs +13 -0
  32. data/sig/verifalia/email_validations/request_entry.rbs +8 -0
  33. data/sig/verifalia/email_validations/wait_options.rbs +20 -0
  34. data/sig/verifalia/rest/client.rbs +12 -0
  35. data/sig/verifalia/rest.rbs +6 -0
  36. data/sig/verifalia/security/username_password_authenticator.rbs +10 -0
  37. data/verifalia.gemspec +27 -18
  38. metadata +56 -57
  39. data/.gitignore +0 -24
  40. data/lib/rest/account_balance.rb +0 -93
  41. data/lib/rest/client.rb +0 -83
  42. data/lib/rest/email_validations.rb +0 -195
  43. data/lib/verifalia/util/configuration.rb +0 -7
  44. data/lib/verifalia/version.rb +0 -3
  45. data/spec/rest/account_balance_spec.rb +0 -93
  46. data/spec/rest/client_spec.rb +0 -105
  47. data/spec/rest/email_validations_spec.rb +0 -322
  48. data/spec/spec_helper.rb +0 -21
  49. data/spec/util/configuration_spec.rb +0 -15
  50. data/spec/verifalia_spec.rb +0 -17
@@ -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