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
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: 44ed994694aed8628bc1b148b0cb244a9c980a62df4ec4cc22146a0b45dd9de8
4
+ data.tar.gz: 4ad8bf1d5a27d1a9fa5dab24af73e309a31c42562f0bafa47d53ecb1883b945a
5
5
  SHA512:
6
- metadata.gz: fc7beb23842a872e087cfc3e44af72cef66e67fbc4f36a303610fe39185cc13afbc0bad27370fb65fdb5abaf3e274b18d4b2c7364615f2c33c0f6b5fdd32d633
7
- data.tar.gz: 7676bc471f56549a75b4e7303341500c69b86f091567b0edfa7f7a6dcca4ab0443e5aba2ac5273c3a6c2bd60ab72d5433ddc2ece045aa5e8ea50cf3b2ba1a6bf
6
+ metadata.gz: bef360e74489bda543cc8120a043ac3d573d2e868da611217e094fe1be9ce23ce9c973017bc2dd0d03f0484ff7999814a8bf6d50d83a9c940412997d4e36ce0a
7
+ data.tar.gz: efc315ccf5a5c98f4144597c3307f594b79740d7e0aed16f3566d62ba90b46a5161158e43be89742700b5da45042aee17ababfa27433a472cc7b65b417655a76
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-2024 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,454 @@
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.5-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 API - 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
+ This SDK library integrates with Verifalia and allows to [verify email addresses](https://verifalia.com/) in **Ruby 2.6.0 or higher**.
13
7
 
14
- ## Installation
8
+ [Verifalia](https://verifalia.com/) is an online service that provides email verification and mailing list cleaning; it helps businesses reduce
9
+ their bounce rate, protect their sender reputation, and ensure their email campaigns reach the intended recipients.
10
+ Verifalia can [verify email addresses](https://verifalia.com/) in real-time or in bulk, using its API or client area; it also
11
+ offers various features and settings to customize the verification process according to the user’s needs.
15
12
 
16
- Add this line to your application's Gemfile:
13
+ Verifalia's email verification process consists of several steps, each taking fractions of a second: it checks the **formatting
14
+ and syntax** (RFC 1123, RFC 2821, RFC 2822, RFC 3490, RFC 3696, RFC 4291, RFC 5321, RFC 5322, and RFC 5336) of each email address,
15
+ the **domain and DNS records**, the **mail exchangers**, and the **mailbox existence**, with support for internationalized domains
16
+ and mailboxes. It also detects risky email types, such as **catch-all**, **disposable**, or **spam traps** / **honeypots**.
17
17
 
18
- gem 'verifalia'
18
+ Verifalia provides detailed and **accurate reports** for each email verification: it categorizes each email address as `Deliverable`,
19
+ `Undeliverable`, `Risky`, or `Unknown`, and assigns one of its exclusive set of over 40 [status codes](https://verifalia.com/developers#email-validations-status-codes).
20
+ It also explains the undeliverability reason and provides **comprehensive verification details**. The service allows the user to choose the desired
21
+ quality level, the waiting timeout, the deduplication preferences, the data retention settings, and the callback preferences
22
+ for each verification.
19
23
 
20
- And then execute:
24
+ Of course, Verifalia never sends emails to the contacts or shares the user's data with anyone.
21
25
 
22
- $ bundle
26
+ To learn more about Verifalia please see [https://verifalia.com](https://verifalia.com/)
23
27
 
24
- Or install it yourself as:
28
+ ## Table of contents
25
29
 
26
- $ gem install verifalia
30
+ * [Adding Verifalia to your Ruby app](#adding-verifalia-to-your-ruby-app)
31
+ * [Authentication](#authentication)
32
+ * [Authenticating via Basic Auth](#authenticating-via-basic-auth)
33
+ * [Authenticating via X.509 client certificate (TLS mutual authentication)](#authenticating-via-x509-client-certificate-tls-mutual-authentication)
34
+ * [Verifying email addresses](#verifying-email-addresses)
35
+ * [How to verify an email address](#how-to-verify-an-email-address)
36
+ * [How to verify a list of email addresses](#how-to-verify-a-list-of-email-addresses)
37
+ * [Processing options](#processing-options)
38
+ * [Quality level](#quality-level)
39
+ * [Deduplication mode](#deduplication-mode)
40
+ * [Data retention](#data-retention)
41
+ * [Wait options](#wait-options)
42
+ * [Avoid waiting](#avoid-waiting)
43
+ * [Progress tracking](#progress-tracking)
44
+ * [Completion callbacks](#completion-callbacks)
45
+ * [Retrieving jobs](#retrieving-jobs)
46
+ * [Exporting email verification results in different output formats](#exporting-email-verification-results-in-different-output-formats)
47
+ * [Don't forget to clean up, when you are done](#dont-forget-to-clean-up-when-you-are-done)
48
+ * [Managing credits](#managing-credits)
49
+ * [Getting the credits balance](#getting-the-credits-balance)
50
+ * [Changelog / What's new](#changelog--whats-new)
51
+ * [v2.1](#v21)
52
+ * [v2.0](#v20)
27
53
 
28
- ## Getting Started With REST ##
54
+ ## Adding Verifalia to your Ruby app
29
55
 
30
- ### Setup Work ###
56
+ Easily include Verifalia in your Ruby application using [Bundler](https://bundler.io/); just add the following line to your Gemfile to get the latest version:
57
+
58
+ ```ruby
59
+ gem 'verifalia'
60
+ ```
61
+
62
+ To manually install `verifalia` via Rubygems simply run `gem install`:
63
+
64
+ ```ruby
65
+ gem install verifalia
66
+ ```
67
+
68
+ ### Authentication
69
+
70
+ First things first: authentication to the Verifalia API is performed by way of either the credentials
71
+ of your root Verifalia account or of one of its users (previously known as sub-accounts): if you don't
72
+ have a Verifalia account, just [register for a free one](https://verifalia.com/sign-up/free).
73
+ For security reasons, it is always advisable to [create and use a dedicated user](https://verifalia.com/client-area#/users/new)
74
+ for accessing the API, as doing so will allow to assign only the specific needed permissions to it.
75
+
76
+ Learn more about authenticating to the Verifalia API at [https://verifalia.com/developers#authentication](https://verifalia.com/developers#authentication)
77
+
78
+ #### Authenticating via Basic Auth
79
+
80
+ The most straightforward method for authenticating against the Verifalia API involves using a username and password pair.
81
+ These credentials can be applied during the creation of a new instance of the `Verifalia::Client` class, serving as the
82
+ initial step for all interactions with the Verifalia API: the provided username and password will be automatically
83
+ transmitted to the API using the HTTP Basic Auth method.
31
84
 
32
85
  ```ruby
33
86
  require 'verifalia'
34
87
 
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'
88
+ # ...
38
89
 
39
- # set up a client to talk to the Verifalia REST API
40
- @client = Verifalia::REST::Client.new account_sid, auth_token
90
+ verifalia = Verifalia::Client.new username: 'your-username', password: 'your-password'
91
+ ```
41
92
 
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
93
+ #### Authenticating via X.509 client certificate (TLS mutual authentication)
47
94
 
48
- # and then you can create a new client without parameters
49
- @client = Verifalia::REST::Client.new
95
+ In addition to the HTTP Basic Auth method, this SDK also supports using a cryptographic X.509 client
96
+ certificate to authenticate against the Verifalia API, through the TLS protocol. This method, also
97
+ called mutual TLS authentication (mTLS) or two-way authentication, offers the highest degree of
98
+ security, as only a cryptographically-derived key (and not the actual credentials) is sent over
99
+ the wire on each request.
100
+
101
+ ```ruby
102
+ # my-cert.pem contains both the private and public (certificate) key, but
103
+ # you may specify different files if needed.
50
104
 
105
+ verifalia = Verifalia::Client.new ssl_client_cert: './my-cert.pem',
106
+ ssl_client_key: './my-cert.pem'
51
107
  ```
52
108
 
53
- ### Email Validations ###
109
+ 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)
110
+ on the Verifalia website, for more information on creating your own certificates for the Verifalia API.
111
+
112
+ ## Verifying email addresses
113
+
114
+ Every operation related to verifying / validating email addresses is performed through the
115
+ `email_validations` attribute exposed by the `Verifalia::Client` instance you created above, which
116
+ exposes some useful methods: in the next few paragraphs we are looking at the most used ones, so
117
+ it is strongly advisable to explore the library and look at the embedded help for other opportunities.
118
+
119
+ **The library automatically waits for the completion of email verification jobs**: if needed, it is possible
120
+ to adjust the wait options and have more control over the entire underlying polling process. Please refer to
121
+ the [Wait options](#wait-options) section below for additional details.
122
+
123
+ ### How to verify an email address
124
+
125
+ To validate an email address from a Ruby application you can invoke the `submit()` method: it
126
+ accepts one or more email addresses and any eventual verification options you wish to pass to Verifalia,
127
+ including the expected results quality, deduplication preferences, processing priority.
128
+
129
+ In the following example, we check an email address with this library, using the default options:
130
+
131
+ ```ruby
132
+ # verifalia = Verifalia::Client.new ...
133
+ job = verifalia.email_validations.submit 'batman@gmail.com'
134
+
135
+ # At this point the address has been validated: let's print its validation
136
+ # result to the console.
137
+
138
+ entry = job.entries[0]
139
+ puts "Classification: #{entry.classification} (status: #{entry.status})"
140
+
141
+ # Classification: Deliverable (status: Success)
142
+ ```
143
+
144
+ As you may expect, each entry may include various additional details about the verified email address:
145
+
146
+ | Attribute | Description |
147
+ |-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
148
+ | `ascii_email_address_domain_part` | Gets the domain part of the email address, converted to ASCII if needed and with comments and folding white spaces stripped off. |
149
+ | `classification` | A string with the classification for this entry; see `Verifalia::EmailValidations::EntryClassification` for a list of the values supported at the time this SDK has been released. |
150
+ | `completed_on` | The date this entry has been completed, if available. |
151
+ | `custom` | A custom, optional string which is passed back upon completing the validation. To pass back and forth a custom value, use the `custom` attribute of `Verifalia::EmailValidations::RequestEntry`. |
152
+ | `duplicate_of` | The zero-based index of the first occurrence of this email address in the parent `Job`, in the event the `status` for this entry is `Duplicate`; duplicated items do not expose any result detail apart from this and the eventual `custom` values. |
153
+ | `index` | The index of this entry within its `Job` container; this property is mostly useful in the event the API returns a filtered view of the items. |
154
+ | `input_data` | The input string being validated. |
155
+ | `email_address` | Gets the email address, without any eventual comment or folding white space. Returns null if the input data is not a syntactically invalid e-mail address. |
156
+ | `email_address_domain_part` | Gets the domain part of the email address, without comments and folding white spaces. |
157
+ | `email_address_local_part` | Gets the local part of the email address, without comments and folding white spaces. |
158
+ | `has_international_domain_name` | If true, the email address has an international domain name. |
159
+ | `has_international_mailbox_name` | If true, the email address has an international mailbox name. |
160
+ | `is_disposable_email_address` | If true, the email address comes from a disposable email address (DEA) provider. <a href="https://verifalia.com/help/email-validations/what-is-a-disposable-email-address-dea">What is a disposable email address?</a> |
161
+ | `is_free_email_address` | If true, the email address comes from a free email address provider (e.g. gmail, yahoo, outlook / hotmail, ...). |
162
+ | `is_role_account` | If true, the local part of the email address is a well-known role account. |
163
+ | `status` | The status for this entry; see `Verifalia::EmailValidations::EntryStatus` for a list of the values supported at the time this SDK has been released. |
164
+ | `suggestions` | The potential corrections for the input data, in the event Verifalia identified potential typos during the verification process. |
165
+ | `syntax_failure_index` | The position of the character in the email address that eventually caused the syntax validation to fail. |
166
+
167
+ Here is another example, showing some of the additional result details provided by Verifalia:
54
168
 
55
169
  ```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
170
+ # verifalia = Verifalia::Client.new ...
171
+ job = verifalia.email_validations.submit 'bat[man@gmal.com'
172
+
173
+ entry = job.entries[0]
174
+ puts "Classification: #{entry.classification}"
175
+ puts "Status: #{entry.status}"
176
+ puts "Syntax failure index: #{entry.syntax_failure_index}"
177
+
178
+ puts "Suggestions:"
179
+
180
+ entry.suggestions.each do |suggestion|
181
+ puts "- #{suggestion}"
65
182
  end
66
183
 
67
- ##with additional email data
68
- 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
184
+ # Classification: Undeliverable
185
+ # Status: InvalidCharacterInSequence
186
+ # Syntax failure index: 3
187
+ # Suggestions:
188
+ # - batman@gmail.com
189
+ ```
190
+
191
+ ### How to verify a list of email addresses
192
+
193
+ To check a list of email addresses - instead of a single address - it is possible to pass an array of strings with the
194
+ emails to verify to the `submit()` method; here is an example showing how to validate an array with some
195
+ email addresses:
196
+
197
+ ```ruby
198
+ # verifalia = Verifalia::Client.new ...
199
+ job = verifalia.email_validations.submit ['batman@gmail.com', 'samantha42@yahoo.it']
200
+
201
+ job.entries.each do |entry|
202
+ puts "#{entry.input_data} => #{entry.classification} (#{entry.status})"
79
203
  end
80
204
 
81
- ##with additional options data
205
+ # batman@gmail.com => Deliverable (Success)
206
+ # samantha42@yahoo.it => Deliverable (Success)
207
+ ```
208
+
209
+ ### Processing options
210
+
211
+ While submitting one or more email addresses for verification, it is possible to specify several
212
+ options which affect the behavior of the Verifalia processing engine as well as the verification flow
213
+ from the API consumer standpoint.
214
+
215
+ #### Quality level
216
+
217
+ Verifalia offers three distinct quality levels - namely, _Standard_, _High_ and _Extreme_ - which rule out how the email verification engine should
218
+ deal with temporary undeliverability issues, with slower mail exchangers and other potentially transient
219
+ problems which can affect the quality of the verification results. The `submit()` method accepts a `quality` keyword
220
+ argument which allows
221
+ to specify the desired quality level; here is an example showing how to verify an email address using
222
+ the _High_ quality level:
223
+
224
+ ```ruby
225
+ # verifalia = Verifalia::Client.new ...
226
+ job = verifalia.email_validations.submit 'batman@gmail.com', quality: 'High'
227
+ ```
228
+
229
+ #### Deduplication mode
230
+
231
+ While accepting multiple email addresses at once, the `submit()` method allows to specify how to
232
+ deal with duplicated entries pertaining to the same input set; Verifalia supports a _Safe_ deduplication
233
+ mode, which strongly adheres to the old IETF standards, and a _Relaxed_ mode which is more in line with
234
+ what can be found in the majority of today's mail exchangers configurations.
235
+
236
+ In the next example, we show how to import and verify a list of email addresses and mark duplicated
237
+ entries using the _Relaxed_ deduplication mode:
238
+
239
+ ```ruby
82
240
  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
241
+ 'batman@gmail.com',
242
+ 'steve.vai@best.music',
243
+ 'samantha42@yahoo.it'
244
+ ]
245
+
246
+ # verifalia = Verifalia::Client.new ...
247
+ job = verifalia.email_validations.submit entries, deduplication: 'Relaxed'
248
+ ```
249
+
250
+ #### Data retention
251
+
252
+ Verifalia automatically deletes completed email verification jobs according to the data retention
253
+ policy defined at the account level, which can be eventually overridden at the user level: one can
254
+ use the [Verifalia clients area](https://verifalia.com/client-area) to configure these settings.
255
+
256
+ It is also possible to specify a per-job data retention policy which govern the time to live of a submitted
257
+ email verification job; to do that, provide the `submit()` method with the keyword argument `retention`
258
+ set according to the `dd.hh:MM:ss` format, with the `dd.` part being optional.
259
+
260
+ Here is how, for instance, one can set a data retention policy of 10 minutes while verifying
261
+ an email address:
262
+
263
+ ```ruby
264
+ # verifalia = Verifalia::Client.new ...
265
+ job = verifalia.email_validations.submit 'batman@gmail.com', retention: '0:10:0'
266
+ ```
267
+
268
+ ### Wait options
269
+
270
+ By default, the `submit()` method submits an email verification job to Verifalia and waits
271
+ for its completion; the entire process may require some time to complete depending on the plan of the
272
+ Verifalia account, the number of email addresses the submission contains, the specified quality level
273
+ and other network factors including the latency of the mail exchangers under test.
274
+
275
+ In waiting for the completion of a given email verification job, the library automatically polls the
276
+ underlying Verifalia API until the results are ready; by default, it tries to take advantage of the long
277
+ polling mode introduced with the Verifalia API v2.4, which allows to minimize the number of requests
278
+ and get the verification results faster.
279
+
280
+ #### Avoid waiting
281
+
282
+ In certain scenarios (in a microservice architecture, for example), however, it may preferable to avoid
283
+ waiting for a job completion and ask the Verifalia API, instead, to just queue it: in that case, the library
284
+ would just return the job overview (and not its verification results) and it will be necessary to retrieve
285
+ the verification results using the `get()` method.
286
+
287
+ To do that, it is possible to specify the `Verifalia::EmailValidations::WaitOptions.no_wait` as the value
288
+ for the `wait_options` keyword argument of the `submit()` method, as shown in the next example:
289
+
290
+ ```ruby
291
+ wait_options = Verifalia::EmailValidations::WaitOptions.no_wait
292
+
293
+ # verifalia = Verifalia::Client.new ...
294
+ job = verifalia.email_validations.submit 'elon.musk@tesla.com', wait_options: wait_options
295
+
296
+ puts "Status: #{job.overview.status}"
297
+ # Status: InProgress
298
+ ```
299
+
300
+ #### Progress tracking
301
+
302
+ For jobs with a large number of email addresses, it could be useful to track progress as they are processed
303
+ by the Verifalia email verification engine; to do that, it is possible to create an instance of the
304
+ `Verifalia::EmailValidations::WaitOptions` class and provide a lambda which eventually receives progress notifications through the
305
+ `progress` attribute.
306
+
307
+ Here is how to define a progress notification handler which displays the progress percentage of a submitted
308
+ job to the console window:
309
+
310
+ ```ruby
311
+ progress = ->(overview) do
312
+ puts "Progress: #{(overview.progress&.percentage || 0) * 100}%..."
99
313
  end
100
314
 
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)
315
+ wait_options = Verifalia::EmailValidations::WaitOptions.new 30 * 1000, 30 * 1000,
316
+ progress: progress
317
+
318
+ emails = [
319
+ 'alice@example.com',
320
+ 'bob@example.net',
321
+ 'charlie@example.org'
322
+ ]
323
+
324
+ # verifalia = Verifalia::Client.new ...
325
+ job = verifalia.email_validations.submit emails, wait_options: wait_options
326
+ ```
327
+
328
+ ### Completion callbacks
329
+
330
+ Along with each email validation job, it is possible to specify an URL which
331
+ Verifalia will invoke (POST) once the job completes: this URL must use the HTTPS or HTTP
332
+ scheme and be publicly accessible over the Internet.
333
+ To learn more about completion callbacks, please see https://verifalia.com/developers#email-validations-completion-callback
334
+
335
+ To specify a completion callback URL, specify the `completion_callback` keyword argument while
336
+ invoking the `submit()` method, as shown in the example below:
337
+
338
+ ```ruby
339
+ # verifalia = Verifalia::Client.new ...
340
+ verifalia.email_validations.submit 'batman@gmail.com',
341
+ completion_callback: {
342
+ 'url' => 'https://your-website-here/foo/bar'
343
+ }
344
+ ```
345
+
346
+ Note that completion callbacks are invoked asynchronously and it could take up to
347
+ several seconds for your callback URL to get invoked.
348
+
349
+ ### Retrieving jobs
103
350
 
351
+ It is possible to retrieve a job through the `get()` method, which
352
+ returns, respectively, a `Verifalia::EmailValidations::Job` instance for the desired
353
+ email verification job. While doing that, the library automatically waits for the completion of
354
+ the job, and it is possible to adjust this behavior by passing to the aforementioned method
355
+ a `wait_options` keyword argument, in the exactly same fashion as described for the `submit()` method;
356
+ please see the [Wait options](#wait-options) section for additional details.
104
357
 
105
- ##with previous unique id
106
- unique_id = "example-example"
358
+ Here is an example showing how to retrieve a job, given its identifier:
107
359
 
108
- #query job
109
- response = @client.email_validations(unique_id: unique_id).query
360
+ ```ruby
361
+ # verifalia = Verifalia::Client.new ...
362
+ job = verifalia.email_validations.get 'ec415ecd-0d0b-49c4-a5f0-f35c182e40ea'
363
+ ```
364
+
365
+ ### Exporting email verification results in different output formats
366
+
367
+ This library also allows to export the entries of a completed email validation
368
+ job in different output formats through the `export()` method, with the goal of
369
+ generating a human-readable representation of the verification results.
110
370
 
111
- #delete job
112
- @client.email_validations(unique_id: unique_id).destroy
371
+ > **WARNING**: While the output schema (columns / labels / data format) is fairly
372
+ > complete, you should always consider it as subject to change: use the `get()`
373
+ > method instead if you need to rely on a stable output schema.
113
374
 
114
- # checking job status
115
- if @client.email_validations(unique_id: unique_id).completed?
116
- response = @client.email_validations(unique_id: unique_id).query
375
+ Here is an example showing how to export a given email verification job as an
376
+ Excel (.xslx) file:
377
+
378
+ ```ruby
379
+ # verifalia = Verifalia::Client.new ...
380
+ data = verifalia.email_validations.export 'ec415ecd-0d0b-49c4-a5f0-f35c182e40ea',
381
+ Verifalia::EmailValidations::ExportedEntriesFormat::EXCEL_XLSX
382
+
383
+ File.open('./export.xlsx', 'wb') do |fp|
384
+ fp.write(data)
117
385
  end
386
+ ```
387
+
388
+ ### Don't forget to clean up, when you are done
389
+
390
+ Verifalia automatically deletes completed jobs after a configurable
391
+ data-retention policy (see the related section) but it is strongly advisable that
392
+ you delete your completed jobs as soon as possible, for privacy and security reasons.
393
+ To do that, you can invoke the `delete()` method passing the job Id you wish to get rid of:
394
+
395
+ ```ruby
396
+ # verifalia = Verifalia::Client.new ...
397
+ verifalia.email_validations.delete 'ec415ecd-0d0b-49c4-a5f0-f35c182e40ea'
398
+ ```
399
+
400
+ Once deleted, a job is gone and there is no way to retrieve its email validation results.
401
+
402
+ ## Managing credits
118
403
 
119
- #checking account_balance. Remember to enable this feature in Verifalia dashboard or you get a :forbidden error
120
- @client.account_balance.balance
404
+ To manage the Verifalia credits for your account you can use the `credits` attribute exposed
405
+ by the `Verifalia::Client` instance created above. Like for the previous topic, in the next
406
+ few paragraphs we are looking at the most used operations, so it is strongly advisable to
407
+ explore the library and look at the embedded documentation for other opportunities.
408
+
409
+ ### Getting the credits balance
410
+
411
+ One of the most common tasks you may need to perform on your account is retrieving the available
412
+ number of free daily credits and credit packs. To do that, you can use the `get_balance()` method,
413
+ which returns a `Verifalia::Credits::Balance` object, as shown in the next example:
414
+
415
+ ```ruby
416
+ # verifalia = Verifalia::Client.new ...
417
+ balance = verifalia.credits.get_balance
418
+
419
+ puts "Credit packs: #{balance.credit_packs}"
420
+ puts "Free daily credits: #{balance.free_credits} (will reset in #{balance.free_credits_reset_in})"
421
+
422
+ # Credit packs: 956.332
423
+ # Free daily credits: 128.66 (will reset in 09:08:23)
121
424
  ```
425
+
426
+ To add credit packs to your Verifalia account visit [https://verifalia.com/client-area#/credits/add](https://verifalia.com/client-area#/credits/add).
427
+
428
+ ## Changelog / What's new
429
+
430
+ This section lists the changelog for the current major version of the library: for older versions,
431
+ please see the [project releases](https://github.com/verifalia/verifalia-ruby-sdk/releases).
432
+
433
+ ### v2.1
434
+
435
+ Released on January 18<sup>th</sup>, 2024
436
+
437
+ - Added support for API v2.5
438
+ - Added support for [classification overrides](https://verifalia.com/help/email-validations/what-are-classification-overrides)
439
+ - Added support for AI-powered suggestions
440
+ - Added `EntryClassification`, `EntryStatus`, `ExportedEntriesFormat` and `JobStatus` module constants
441
+ - Improved documentation
442
+
443
+ ### v2.0
444
+
445
+ Released on March 12<sup>th</sup>, 2023
446
+
447
+ - Added support for API v2.4
448
+ - Added support for new completion callback options
449
+ - Added support for specifying a custom wait time while submitting and retrieving email verification jobs
450
+ - Added support for exporting completed email verification jobs in different output formats (CSV, Excel, Excel 97-2003)
451
+ - Breaking change: the default job submission and retrieval behavior is now to wait for the completion
452
+ of jobs (but it is possible to change that through the new `WaitOptions` class)
453
+ - Bumped dependencies
454
+ - 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"