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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 13ecdf0dda8a8b5eed02d2fbc681f57f46905e4e
4
- data.tar.gz: 45a067871869dacd52fce6649d6ecf6f244a71e8
2
+ SHA256:
3
+ metadata.gz: 14650c8b1a2409f0c037e1e5348c445434fcf22930bb465f78e548c7fb42b4ca
4
+ data.tar.gz: ceb6552a4935d73b4488558d8e11ae1de15de1b740a92811eb9240984497e446
5
5
  SHA512:
6
- metadata.gz: fc7beb23842a872e087cfc3e44af72cef66e67fbc4f36a303610fe39185cc13afbc0bad27370fb65fdb5abaf3e274b18d4b2c7364615f2c33c0f6b5fdd32d633
7
- data.tar.gz: 7676bc471f56549a75b4e7303341500c69b86f091567b0edfa7f7a6dcca4ab0443e5aba2ac5273c3a6c2bd60ab72d5433ddc2ece045aa5e8ea50cf3b2ba1a6bf
6
+ metadata.gz: 346075e83859afee3fa6c24b696d889973634eef9bab43febf7c60742b992f08d80035457c6c334f06e8995ac78016ff5b7300cd179a6299804755650fa18691
7
+ data.tar.gz: 8e5b6be8fe6528bd04b605ff61e39289017a114f31322229595bfd90964f1d6ac596d1aeb0a2eac4317752e367002d68f278a8aae0519e3fc4797beb6a6d8130
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in verifalia.gemspec
4
6
  gemspec
5
7
 
6
- group :test do
7
- gem 'rspec', '~> 3.0'
8
- gem 'coveralls', require: false
9
- end
8
+ gem "rake", "~> 13.0"
9
+ gem "rubocop", "~> 1.21"
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2014 Verifalia
3
+ Copyright (c) 2014-2023 Cobisi Research - https://verifalia.com/
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,5 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,121 +1,367 @@
1
- [![Circle CI](https://circleci.com/gh/verifalia/verifalia-ruby-sdk.svg?style=shield)](https://circleci.com/gh/verifalia/verifalia-ruby-sdk)
1
+ ![Verifalia API](https://img.shields.io/badge/Verifalia%20API-v2.4-green)
2
2
  [![Gem Version](https://badge.fury.io/rb/verifalia.svg)](https://badge.fury.io/rb/verifalia)
3
- [![Dependency Status](https://gemnasium.com/verifalia/verifalia-ruby-sdk.svg)](https://gemnasium.com/verifalia/verifalia-ruby-sdk)
4
- [![Code Climate](https://codeclimate.com/github/verifalia/verifalia-ruby-sdk/badges/gpa.svg)](https://codeclimate.com/github/verifalia/verifalia-ruby-sdk)
5
- [![Coverage Status](https://coveralls.io/repos/verifalia/verifalia-ruby-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/verifalia/verifalia-ruby-sdk?branch=master)
6
- [![Inline docs](http://inch-ci.org/github/verifalia/verifalia-ruby-sdk.svg?branch=master)](http://inch-ci.org/github/verifalia/verifalia-ruby-sdk)
7
3
 
8
- # Verifalia RESTful API - Ruby gem
4
+ # Verifalia - Ruby gem
9
5
 
10
- Verifalia provides a simple HTTPS-based API for validating email addresses and checking whether or not they are deliverable;
11
- this Ruby gem allows to communicate with the Verifalia API, scrubbing lists of email addresses in a couple of lines of code.
12
- To learn more about Verifalia, please visit http://verifalia.com
6
+ [Verifalia](https://verifalia.com/) provides a simple HTTPS-based API for **validating email addresses in
7
+ real-time** and checking whether they are deliverable or not; this SDK library integrates with Verifalia
8
+ and allows to [verify email addresses](https://verifalia.com/) in **Ruby 2.6.0 or higher**.
13
9
 
14
- ## Installation
10
+ To learn more about Verifalia please see [https://verifalia.com](https://verifalia.com/)
15
11
 
16
- Add this line to your application's Gemfile:
12
+ ## Table of contents
17
13
 
18
- gem 'verifalia'
14
+ - [Adding Verifalia to your Ruby app](#adding-verifalia-to-your-ruby-app)
15
+ * [Authentication](#authentication)
16
+ + [Authenticating via X.509 client certificate (TLS mutual authentication)](#authenticating-via-x509-client-certificate--tls-mutual-authentication-)
17
+ - [Validating email addresses](#validating-email-addresses)
18
+ * [How to validate an email address](#how-to-validate-an-email-address)
19
+ * [How to validate a list of email addresses](#how-to-validate-a-list-of-email-addresses)
20
+ * [Processing options](#processing-options)
21
+ + [Quality level](#quality-level)
22
+ + [Deduplication mode](#deduplication-mode)
23
+ + [Data retention](#data-retention)
24
+ * [Wait options](#wait-options)
25
+ + [Avoid waiting](#avoid-waiting)
26
+ + [Progress tracking](#progress-tracking)
27
+ * [Completion callbacks](#completion-callbacks)
28
+ * [Retrieving jobs](#retrieving-jobs)
29
+ * [Exporting email verification results in different output formats](#exporting-email-verification-results-in-different-output-formats)
30
+ * [Don't forget to clean up, when you are done](#don-t-forget-to-clean-up--when-you-are-done)
31
+ - [Managing credits](#managing-credits)
32
+ * [Getting the credits balance](#getting-the-credits-balance)
33
+ - [Changelog / What's new](#changelog---what-s-new)
19
34
 
20
- And then execute:
35
+ ## Adding Verifalia to your Ruby app
21
36
 
22
- $ bundle
37
+ To install using [Bundler](https://bundler.io/) grab the latest version:
23
38
 
24
- Or install it yourself as:
39
+ ```ruby
40
+ gem 'verifalia'
41
+ ```
42
+
43
+ To manually install `verifalia` via Rubygems simply run `gem install`:
44
+
45
+ ```ruby
46
+ gem install verifalia
47
+ ```
48
+
49
+ ### Authentication ###
25
50
 
26
- $ gem install verifalia
51
+ First things first: authentication to the Verifalia API is performed by way of either the credentials
52
+ of your root Verifalia account or of one of its users (previously known as sub-accounts): if you don't
53
+ have a Verifalia account, just [register for a free one](https://verifalia.com/sign-up/free).
54
+ For security reasons, it is always advisable to [create and use a dedicated user](https://verifalia.com/client-area#/users/new)
55
+ for accessing the API, as doing so will allow to assign only the specific needed permissions to it.
27
56
 
28
- ## Getting Started With REST ##
57
+ Learn more about authenticating to the Verifalia API at [https://verifalia.com/developers#authentication](https://verifalia.com/developers#authentication)
29
58
 
30
- ### Setup Work ###
59
+ Once you have your Verifalia credentials at hand, use them while creating a new instance of the
60
+ `Verifalia::Client` class, which will be the starting point to every other operation against the
61
+ Verifalia API: the supplied credentials will be automatically provided to the API using the HTTP
62
+ Basic Auth method.
31
63
 
32
64
  ```ruby
33
65
  require 'verifalia'
34
66
 
35
- # put your own credentials here (grabbed from your Verifalia client account area)
36
- account_sid = 'YOUR-ACCOUNT-SID'
37
- auth_token = 'YOUR-AUTH-TOKEN'
67
+ # ...
38
68
 
39
- # set up a client to talk to the Verifalia REST API
40
- @client = Verifalia::REST::Client.new account_sid, auth_token
69
+ verifalia = Verifalia::Client.new username: 'your-username', password: 'your-password'
70
+ ```
41
71
 
42
- # alternatively, you can preconfigure the client like so
43
- Verifalia.configure do |config|
44
- config.account_sid = account_sid
45
- config.auth_token = auth_token
46
- end
72
+ #### Authenticating via X.509 client certificate (TLS mutual authentication)
73
+
74
+ In addition to the HTTP Basic Auth method, this SDK also supports using a cryptographic X.509 client
75
+ certificate to authenticate against the Verifalia API, through the TLS protocol. This method, also
76
+ called mutual TLS authentication (mTLS) or two-way authentication, offers the highest degree of
77
+ security, as only a cryptographically-derived key (and not the actual credentials) is sent over
78
+ the wire on each request.
79
+
80
+ ```ruby
81
+ # my-cert.pem contains both the private and public (certificate) key, but
82
+ # you may specify different files if needed.
83
+
84
+ verifalia = Verifalia::Client.new ssl_client_cert: './my-cert.pem',
85
+ ssl_client_key: './my-cert.pem'
86
+ ```
87
+
88
+ See [how to create a self-signed X.509 client certificate for TLS mutual authentication](https://verifalia.com/help/sub-accounts/how-to-create-self-signed-client-certificate-for-tls-mutual-authentication)
89
+ on the Verifalia website, for more information on creating your own certificates for the Verifalia API.
90
+
91
+ ## Validating email addresses ##
92
+
93
+ Every operation related to verifying / validating email addresses is performed through the
94
+ `email_validations` property exposed by the `Verifalia::Client` instance you created above, which
95
+ exposes some useful functions: in the next few paragraphs we are looking at the most used ones, so
96
+ it is strongly advisable to explore the library and look at the embedded help for other opportunities.
97
+
98
+ **The library automatically waits for the completion of email verification jobs**: if needed, it is possible
99
+ to adjust the wait options and have more control over the entire underlying polling process. Please refer to
100
+ the [Wait options](#wait-options) section below for additional details.
101
+
102
+ ### How to validate an email address ###
103
+
104
+ To validate an email address from a Ruby application you can invoke the `submit()` method: it
105
+ accepts one or more email addresses and any eventual verification options you wish to pass to Verifalia,
106
+ including the expected results quality, deduplication preferences, processing priority.
47
107
 
48
- # and then you can create a new client without parameters
49
- @client = Verifalia::REST::Client.new
108
+ In the following example, we verify an email address with this library, using the default options:
50
109
 
110
+ ```ruby
111
+ job = verifalia.email_validations.submit 'batman@gmail.com'
112
+
113
+ # At this point the address has been validated: let's print its validation
114
+ # result to the console.
115
+
116
+ entry = job.entries[0]
117
+ puts "Classification: #{entry.classification} (status: #{entry.status})"
118
+
119
+ # Classification: Deliverable (status: Success)
51
120
  ```
52
121
 
53
- ### Email Validations ###
122
+ ### How to validate a list of email addresses ###
123
+
124
+ To verify a list of email addresses - instead of a single address - it is possible to pass an array of strings with the
125
+ emails to verify to the `submit()` method; here is an example showing how to verify an array with some
126
+ email addresses:
54
127
 
55
128
  ```ruby
56
- ##from scratch
57
- emails = ['alice@example.com', 'bob@example.net']
58
- if (unique_id = @client.email_validations.verify(emails))
59
- #response is an hash with all the values returned
60
- response = @client.email_validations.query
61
- @client.email_validations.destroy
62
- else
63
- #error is HTTP status code in symbol (:bad_request)
64
- error = @client.email_validations.error
129
+ job = verifalia.email_validations.submit ['batman@gmail.com', 'samantha42@yahoo.it']
130
+
131
+ job.entries.each do |entry|
132
+ puts "#{entry.input_data} => #{entry.classification} (#{entry.status})"
65
133
  end
66
134
 
67
- ##with additional email data
135
+ # batman@gmail.com => Deliverable (Success)
136
+ # samantha42@yahoo.it => Deliverable (Success)
137
+ ```
138
+
139
+ ### Processing options
140
+
141
+ While submitting one or more email addresses for verification, it is possible to specify several
142
+ options which affect the behavior of the Verifalia processing engine as well as the verification flow
143
+ from the API consumer standpoint.
144
+
145
+ #### Quality level
146
+
147
+ Verifalia offers three distinct quality levels - namely, _Standard_, _High_ and _Extreme_ - which rule out how the email verification engine should
148
+ deal with temporary undeliverability issues, with slower mail exchangers and other potentially transient
149
+ problems which can affect the quality of the verification results. The `submit()` method accepts a `quality` keyword
150
+ argument which allows
151
+ to specify the desired quality level; here is an example showing how to verify an email address using
152
+ the _High_ quality level:
153
+
154
+ ```ruby
155
+ job = verifalia.email_validations.submit 'batman@gmail.com', quality: 'High'
156
+ ```
157
+
158
+ #### Deduplication mode
159
+
160
+ While accepting multiple email addresses at once, the `submit()` method allows to specify how to
161
+ deal with duplicated entries pertaining to the same input set; Verifalia supports a _Safe_ deduplication
162
+ mode, which strongly adheres to the old IETF standards, and a _Relaxed_ mode which is more in line with
163
+ what can be found in the majority of today's mail exchangers configurations.
164
+
165
+ In the next example, we show how to import and verify a list of email addresses and mark duplicated
166
+ entries using the _Relaxed_ deduplication mode:
167
+
168
+ ```ruby
68
169
  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
170
+ 'batman@gmail.com',
171
+ 'steve.vai@best.music',
172
+ 'samantha42@yahoo.it'
173
+ ]
174
+
175
+ job = verifalia.email_validations.submit entries, deduplication: 'Relaxed'
176
+ ```
177
+
178
+ #### Data retention
179
+
180
+ Verifalia automatically deletes completed email verification jobs according to the data retention
181
+ policy defined at the account level, which can be eventually overridden at the user level: one can
182
+ use the [Verifalia clients area](https://verifalia.com/client-area) to configure these settings.
183
+
184
+ It is also possible to specify a per-job data retention policy which govern the time to live of a submitted
185
+ email verification job; to do that, provide the `submit()` method with the keyword argument `retention`
186
+ set according to the `dd.hh:MM:ss` format, with the `dd.` part being optional.
187
+
188
+ Here is how, for instance, one can set a data retention policy of 10 minutes while verifying
189
+ an email address:
190
+
191
+ ```ruby
192
+ job = verifalia.email_validations.submit 'batman@gmail.com', retention: '0:10:0'
193
+ ```
194
+
195
+ ### Wait options
196
+
197
+ By default, the `submit()` method submits an email verification job to Verifalia and waits
198
+ for its completion; the entire process may require some time to complete depending on the plan of the
199
+ Verifalia account, the number of email addresses the submission contains, the specified quality level
200
+ and other network factors including the latency of the mail exchangers under test.
201
+
202
+ In waiting for the completion of a given email verification job, the library automatically polls the
203
+ underlying Verifalia API until the results are ready; by default, it tries to take advantage of the long
204
+ polling mode introduced with the Verifalia API v2.4, which allows to minimize the number of requests
205
+ and get the verification results faster.
206
+
207
+ #### Avoid waiting
208
+
209
+ In certain scenarios (in a microservice architecture, for example), however, it may preferable to avoid
210
+ waiting for a job completion and ask the Verifalia API, instead, to just queue it: in that case, the library
211
+ would just return the job overview (and not its verification results) and it will be necessary to retrieve
212
+ the verification results using the `get()` method.
213
+
214
+ To do that, it is possible to specify the `Verifalia::EmailValidations::WaitOptions.no_wait` as the value
215
+ for the `wait_options` keyword argument of the `submit()` method, as shown in the next example:
216
+
217
+ ```ruby
218
+ wait_options = Verifalia::EmailValidations::WaitOptions.no_wait
219
+ job = verifalia.email_validations.submit 'elon.musk@tesla.com', wait_options: wait_options
220
+
221
+ puts "Status: #{job.overview.status}"
222
+ # Status: InProgress
223
+ ```
224
+
225
+ #### Progress tracking
226
+
227
+ For jobs with a large number of email addresses, it could be useful to track progress as they are processed
228
+ by the Verifalia email verification engine; to do that, it is possible to create an instance of the
229
+ `Verifalia::EmailValidations::WaitOptions` class and provide a lambda which eventually receives progress notifications through the
230
+ `progress` property.
231
+
232
+ Here is how to define a progress notification handler which displays the progress percentage of a submitted
233
+ job to the console window:
234
+
235
+ ```ruby
236
+ WaitOptions = Verifalia::EmailValidations::WaitOptions
237
+
238
+ progress = ->(overview) do
239
+ puts "Progress: #{(overview.progress&.percentage || 0) * 100}%..."
79
240
  end
80
241
 
81
- ##with additional options data
242
+ wait_options = WaitOptions.new 30 * 1000, 30 * 1000, progress: progress
243
+
82
244
  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 #destroy the job on the Verifalia server
96
- else
97
- #error is HTTP status code in symbol (:bad_request)
98
- error = @client.email_validations.error
99
- end
245
+ 'alice@example.com',
246
+ 'bob@example.net',
247
+ 'charlie@example.org'
248
+ ]
249
+
250
+ job = verifalia.email_validations.submit emails, wait_options: wait_options
251
+ ```
252
+
253
+ ### Completion callbacks
100
254
 
101
- #you can wait for job completion using options on query
102
- response = @client.email_validations.query(wait_for_completion: true, completion_max_retry: 2, completion_interval: 1)
255
+ Along with each email validation job, it is possible to specify an URL which
256
+ Verifalia will invoke (POST) once the job completes: this URL must use the HTTPS or HTTP
257
+ scheme and be publicly accessible over the Internet.
258
+ To learn more about completion callbacks, please see https://verifalia.com/developers#email-validations-completion-callback
103
259
 
260
+ To specify a completion callback URL, specify the `completion_callback` keyword argument while
261
+ invoking the `submit()` method, as shown in the example below:
262
+
263
+ ```ruby
264
+ verifalia.email_validations.submit 'batman@gmail.com',
265
+ completion_callback: {
266
+ 'url' => 'https://your-website-here/foo/bar'
267
+ }
268
+ ```
104
269
 
105
- ##with previous unique id
106
- unique_id = "example-example"
270
+ Note that completion callbacks are invoked asynchronously and it could take up to
271
+ several seconds for your callback URL to get invoked.
272
+
273
+ ### Retrieving jobs
274
+
275
+ It is possible to retrieve a job through the `get()` method, which
276
+ returns, respectively, a `Verifalia::EmailValidations::Job` instance for the desired
277
+ email verification job. While doing that, the library automatically waits for the completion of
278
+ the job, and it is possible to adjust this behavior by passing to the aforementioned method
279
+ a `wait_options` keyword argument, in the exactly same fashion as described for the `submit()` method;
280
+ please see the [Wait options](#wait-options) section for additional details.
281
+
282
+ Here is an example showing how to retrieve a job, given its identifier:
283
+
284
+ ```ruby
285
+ job_id = 'ec415ecd-0d0b-49c4-a5f0-f35c182e40ea'
286
+ job = verifalia.email_validations.get job_id
287
+ ```
107
288
 
108
- #query job
109
- response = @client.email_validations(unique_id: unique_id).query
289
+ ### Exporting email verification results in different output formats
110
290
 
111
- #delete job
112
- @client.email_validations(unique_id: unique_id).destroy
291
+ This library also allows to export the entries of a completed email validation
292
+ job in different output formats through the `export()` method, with the goal of
293
+ generating a human-readable representation of the verification results.
113
294
 
114
- # checking job status
115
- if @client.email_validations(unique_id: unique_id).completed?
116
- response = @client.email_validations(unique_id: unique_id).query
295
+ > **WARNING**: While the output schema (columns / labels / data format) is fairly
296
+ > complete, you should always consider it as subject to change: use the `get()`
297
+ > method instead if you need to rely on a stable output schema.
298
+
299
+ Here is an example showing how to export a given email verification job as an
300
+ Excel (xslx) file:
301
+
302
+ ```ruby
303
+ job_id = 'ec415ecd-0d0b-49c4-a5f0-f35c182e40ea'
304
+ format = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
305
+
306
+ data = verifalia.email_validations.export job_id, format
307
+
308
+ File.open('./export.xlsx', 'wb') do |fp|
309
+ fp.write(data)
117
310
  end
311
+ ```
312
+
313
+ ### Don't forget to clean up, when you are done
118
314
 
119
- #checking account_balance. Remember to enable this feature in Verifalia dashboard or you get a :forbidden error
120
- @client.account_balance.balance
315
+ Verifalia automatically deletes completed jobs after a configurable
316
+ data-retention policy (see the related section) but it is strongly advisable that
317
+ you delete your completed jobs as soon as possible, for privacy and security reasons.
318
+ To do that, you can invoke the `delete()` method passing the job Id you wish to get rid of:
319
+
320
+ ```ruby
321
+ verifalia.email_validations.delete job_id
121
322
  ```
323
+
324
+ Once deleted, a job is gone and there is no way to retrieve its email validation results.
325
+
326
+ ## Managing credits ##
327
+
328
+ To manage the Verifalia credits for your account you can use the `credits` property exposed
329
+ by the `Verifalia::Client` instance created above. Like for the previous topic, in the next
330
+ few paragraphs we are looking at the most used operations, so it is strongly advisable to
331
+ explore the library and look at the embedded documentation for other opportunities.
332
+
333
+ ### Getting the credits balance ###
334
+
335
+ One of the most common tasks you may need to perform on your account is retrieving the available
336
+ number of free daily credits and credit packs. To do that, you can use the `get_balance()` method,
337
+ which returns a `Verifalia::Credits::Balance` object, as shown in the next example:
338
+
339
+ ```ruby
340
+ balance = verifalia.credits.get_balance
341
+
342
+ puts "Credit packs: #{balance.credit_packs}"
343
+ puts "Free daily credits: #{balance.free_credits} (will reset in #{balance.free_credits_reset_in})"
344
+
345
+ # Credit packs: 956.332
346
+ # Free daily credits: 128.66 (will reset in 09:08:23)
347
+ ```
348
+
349
+ To add credit packs to your Verifalia account visit [https://verifalia.com/client-area#/credits/add](https://verifalia.com/client-area#/credits/add).
350
+
351
+ ## Changelog / What's new
352
+
353
+ This section lists the changelog for the current major version of the library: for older versions,
354
+ please see the [project releases](https://github.com/verifalia/verifalia-ruby-sdk/releases).
355
+
356
+ ### v2.0
357
+
358
+ Released on March 12<sup>th</sup>, 2023
359
+
360
+ - Added support for API v2.4
361
+ - Added support for new completion callback options
362
+ - Added support for specifying a custom wait time while submitting and retrieving email verification jobs
363
+ - Added support for exporting completed email verification jobs in different output formats (CSV, Excel, Excel 97-2003)
364
+ - Breaking change: the default job submission and retrieval behavior is now to wait for the completion
365
+ of jobs (but it is possible to change that through the new `WaitOptions` class)
366
+ - Bumped dependencies
367
+ - Improved documentation
data/Rakefile CHANGED
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
 
5
+ task default: %i[spec rubocop]
6
+
3
7
  desc "Open an irb session preloaded with this library"
4
8
  task :console do
5
9
  sh "irb -rubygems -I lib -r verifalia.rb"
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl/x509'
4
+ require_relative './rest/client'
5
+
6
+ module Verifalia
7
+ # HTTPS-based REST client for Verifalia.
8
+ class Client
9
+ # The version of the Verifalia SDK for Ruby.
10
+ VERSION = '2.0.0'
11
+
12
+ # Allows to verify email addresses and manage email verification jobs using the Verifalia service.
13
+ attr_reader :email_validations
14
+
15
+ # Manages credit packs, daily free credits and usage consumption for the Verifalia account.
16
+ attr_reader :credits
17
+
18
+ # Initializes a new HTTPS-based REST client for Verifalia with the specified options.
19
+ #
20
+ # While authenticating with your Verifalia main account credentials is possible, it is strongly advised to create
21
+ # one or more users (formerly known as sub-accounts) with just the required permissions, for improved security.
22
+ # To create a new user or manage existing ones, please visit 'https://verifalia.com/client-area#/users'
23
+ #
24
+ # @param [nil] authenticator A custom authenticator the client will use to authenticate against the Verifalia API.
25
+ # @param [nil] username The user-name used to authenticate against the Verifalia API using basic auth.
26
+ # @param [nil] password The password used to authenticate against the Verifalia API using basic auth.
27
+ # @param [nil] ssl_client_cert The X.509 client certificate used to authenticate against the Verifalia API using mutual TLS authentication. Available to premium Verifalia plans only.
28
+ # @param [nil] ssl_client_key The private key used to authenticate against the Verifalia API using mutual TLS authentication. Available to premium Verifalia plans only.
29
+ # @param [nil] base_urls Alternative base URLs to use while connecting against the Verifalia API.
30
+ # @param [nil] logger A logger where to write diagnostics messages, useful while debugging.
31
+ def initialize(authenticator: nil, username: nil, password: nil, ssl_client_cert: nil, ssl_client_key: nil, base_urls: nil, logger: nil)
32
+ @base_urls = base_urls
33
+
34
+ # Initialize the authenticator this client will use while connecting to the Verifalia API
35
+
36
+ if !authenticator.nil?
37
+ @authenticator = authenticator
38
+ elsif !username.nil?
39
+ @authenticator = Verifalia::Security::UsernamePasswordAuthenticator.new(username, password)
40
+ elsif !ssl_client_cert.nil?
41
+ @authenticator = Verifalia::Security::CertificateAuthenticator.new(ssl_client_cert, ssl_client_key)
42
+ @base_urls ||= Verifalia::Rest::BASE_CCA_URLS
43
+ else
44
+ raise ArgumentError, 'Username is nil and no other authentication method was specified: please visit https://verifalia.com/client-area to set up a new user, if you don\'t have one.'
45
+ end
46
+
47
+ @base_urls ||= Verifalia::Rest::BASE_URLS
48
+ @rest_client = Verifalia::Rest::Client.new(@authenticator,
49
+ "verifalia-rest-client/ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
50
+ @base_urls)
51
+
52
+ @rest_client.logger = logger
53
+
54
+ # Initialize the underlying resource clients
55
+
56
+ @email_validations = Verifalia::EmailValidations::Client.new(@rest_client)
57
+ @credits = Verifalia::Credits::Client.new(@rest_client)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Verifalia
4
+ module Credits
5
+ # The credits balance for the Verifalia account.
6
+ class Balance
7
+ # The number of credit packs (that is, non-expiring credits) available for the account.
8
+ attr_reader :credit_packs
9
+
10
+ # The number of free daily credits of the account, where available.
11
+ attr_reader :free_credits
12
+
13
+ # A string representing the amount of time before the daily credits expire, where available, expressed in the form +hh:mm:ss+.
14
+ attr_reader :free_credits_reset_in
15
+
16
+ def initialize(credit_packs, free_credits, free_credits_reset_in)
17
+ @credit_packs = credit_packs
18
+ @free_credits = free_credits
19
+ @free_credits_reset_in = free_credits_reset_in
20
+ end
21
+
22
+ # Parse a Balance from a JSON string.
23
+ def self.from_json(data)
24
+ Balance.new data['creditPacks'],
25
+ data['freeCredits'],
26
+ data['freeCreditsResetIn']
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'balance'
4
+
5
+ module Verifalia
6
+ module Credits
7
+ # Manages credit packs, daily free credits and usage consumption for the Verifalia account.
8
+ class Client
9
+ def initialize(rest_client)
10
+ @rest_client = rest_client
11
+ end
12
+
13
+ # Returns the current credits balance for the Verifalia account.
14
+ # @return [Verifalia::Credits::Balance] The account balance.
15
+ def get_balance
16
+ response = @rest_client.invoke 'get',
17
+ 'credits/balance'
18
+
19
+ return Balance.from_json(JSON.parse(response.body)) if response.status == 200
20
+
21
+ raise "Unexpected HTTP response: #{response.status} #{response.body}"
22
+ end
23
+ end
24
+ end
25
+ end