Class: Verifalia::EmailValidations::Client
- Inherits:
-
Object
- Object
- Verifalia::EmailValidations::Client
- Defined in:
- lib/verifalia/email_validation/client.rb
Overview
Allows to verify email addresses and manage email verification jobs using the Verifalia service.
Instance Method Summary collapse
-
#delete(id) ⇒ Object
Deletes an email validation job previously submitted for processing.
-
#export(id, format) ⇒ String
Exports the validated entries for a completed email validation job, using the specified output format.
-
#get(id, wait_options: nil) ⇒ Verifalia::EmailValidations::Job
Returns an email validation job previously submitted for processing.
-
#initialize(rest_client) ⇒ Client
constructor
A new instance of Client.
-
#submit(data, quality: nil, priority: nil, deduplication: nil, name: nil, retention: nil, completion_callback: nil, wait_options: nil) ⇒ Verifalia::EmailValidations::Job
Submits a new email validation for processing.
Constructor Details
#initialize(rest_client) ⇒ Client
Returns a new instance of Client.
45 46 47 |
# File 'lib/verifalia/email_validation/client.rb', line 45 def initialize(rest_client) @rest_client = rest_client end |
Instance Method Details
#delete(id) ⇒ Object
Deletes an email validation job previously submitted for processing.
227 228 229 230 231 232 233 234 |
# File 'lib/verifalia/email_validation/client.rb', line 227 def delete(id) response = @rest_client.invoke 'delete', "email-validations/#{id}" return if response.status == 200 || response.status == 410 raise "Unexpected HTTP response: #{response.status} #{response.body}" end |
#export(id, format) ⇒ String
Exports the validated entries for a completed email validation job, using the specified output format. See ExportedEntriesFormat
for a list of the values supported at the time this SDK has been released.
Supported formats:
-
Comma-Separated Values (CSV)
-
Microsoft Excel (.xlsx)
-
Microsoft Excel 97-2003 (.xls)
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/verifalia/email_validation/client.rb', line 209 def export(id, format) response = @rest_client.invoke 'get', "email-validations/#{id}/entries", { headers: { 'Accept': format } } return nil if response.status == 404 || response.status == 410 return response.body if response.status == 200 raise "Unexpected HTTP response: #{response.status} #{response.body}" end |
#get(id, wait_options: nil) ⇒ Verifalia::EmailValidations::Job
Returns an email validation job previously submitted for processing.
By default, this method waits for the completion of the email validation job: pass a WaitOptions
to request a different waiting behavior.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/verifalia/email_validation/client.rb', line 171 def get(id, wait_options: nil) = .nil? ? WaitOptions.default : loop do response = @rest_client.invoke 'get', "email-validations/#{id}?waitTime=#{.poll_wait_time}" return nil if response.status == 404 || response.status == 410 unless response.status == 202 || response.status == 200 raise "Unexpected HTTP response: #{response.status} #{response.body}" end job = Job.from_json(JSON.parse(response.body)) return job if == WaitOptions.no_wait || response.status == 200 # Fires a progress, since we are not yet completed .progress&.call(job.overview) # Wait for the next polling schedule .wait_for_next_poll(job) end end |
#submit(data, quality: nil, priority: nil, deduplication: nil, name: nil, retention: nil, completion_callback: nil, wait_options: nil) ⇒ Verifalia::EmailValidations::Job
Submits a new email validation for processing.
By default, this method waits for the completion of the email validation job: pass a WaitOptions
to request a different waiting behavior.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/verifalia/email_validation/client.rb', line 63 def submit(data, quality: nil, priority: nil, deduplication: nil, name: nil, retention: nil, completion_callback: nil, wait_options: nil) # Determine how to handle the submission, based on the type of the argument if data.nil? raise ArgumentError, 'data can\'t be nil.' elsif data.is_a?(String) data = Request.new [(RequestEntry.new data)], quality: quality elsif data.is_a? Enumerable entries = data.map do |entry| case entry when String # data is an Array[String] RequestEntry.new entry.to_s when RequestEntry # data is an Array[RequestEntry] entry when Hash # data is an Array[{ :inputData, :custom }] raise ArgumentError, 'Input hash must have an :inputData key.' unless entry.key?(:input_data) RequestEntry.new entry[:input_data], entry[:custom] else raise ArgumentError, 'Cannot map input data.' end end data = Request.new entries, quality: quality elsif data.is_a?(RequestEntry) data = Request.new data, quality: quality elsif !data.is_a?(Request) raise ArgumentError, "Unsupported data type #{data.class}" end # Completion callback if completion_callback.is_a?(Hash) completion_callback = Verifalia::EmailValidations::CompletionCallback.new(completion_callback['url'], completion_callback['version'], completion_callback['skip_server_certificate_validation']) end # Send the request to the Verifalia API = .nil? ? WaitOptions.default : payload = { entries: data.entries.map do |entry| { inputData: entry.input_data, custom: entry.custom } end, quality: quality, priority: priority, deduplication: deduplication, name: name, retention: retention, callback: ( unless completion_callback.nil? { url: completion_callback&.url, version: completion_callback&.version, skipServerCertificateValidation: completion_callback&.skip_server_certificate_validation } end ) }.compact.to_json response = @rest_client.invoke 'post', "email-validations?waitTime=#{.submission_wait_time}", { body: payload, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } } if response.status == 202 || response.status == 200 job = Job.from_json(JSON.parse(response.body)) return job if == WaitOptions.no_wait || response.status == 200 return get(job.overview.id, wait_options: ) end raise "Unexpected HTTP response: #{response.status} #{response.body}" end |