diff --git a/README.md b/README.md index 0276022..7e1a3d9 100644 --- a/README.md +++ b/README.md @@ -49,18 +49,14 @@ BlazeVerify.verify('jarrett@blazeverify.com') #### Slow Email Server Handling -Some email servers are slow to respond. As a result the timeout may be reached +Some email servers are slow to respond. As a result, the timeout may be reached before we are able to complete the verification process. If this happens, the -verification will continue in the background on our servers. We recommend -sleeping for at least one second and trying your request again. Re-requesting -the same verification with the same options will not impact your credit -allocation within a 5 minute window. - -```ruby -{ - "message" => "Your request is taking longer than normal. Please send your request again." -} -``` +verification will continue in the background on our servers, and a +`BlazeVerify::TimeoutError` will be raised. We recommend sleeping for at least +one second and trying your request again. Re-requesting the same verification +with the same options will not impact your credit allocation within a 5 minute +window. You can test this behavior using a test key and the special +email `slow@example.com`. ### Batch Verification @@ -108,7 +104,7 @@ It'll validate the attribute only when it's present and has changed. #### Options * `smtp`, `timeout`: Passed directly to API as options. -* `states`: An array of states you'd like to be valid. +* `states`: An array of states you'd like to be considered valid. * `free`, `role`, `disposable`, `accept_all`: If you'd like any of these to be valid. ```ruby diff --git a/lib/blazeverify.rb b/lib/blazeverify.rb index e4aa4c4..520c846 100644 --- a/lib/blazeverify.rb +++ b/lib/blazeverify.rb @@ -30,7 +30,9 @@ def verify(email, smtp: nil, accept_all: nil, timeout: nil) response = client.request(:get, 'verify', opts) if response.status == 249 - response.body + raise BlazeVerify::TimeoutError.new( + code: response.status, message: response.body + ) else Verification.new(response.body) end @@ -41,4 +43,23 @@ def account response = client.request(:get, 'account') Account.new(response.body) end + + + class Error < StandardError + attr_accessor :code, :message + + def initialize(code: nil, message: nil) + @code = code + @message = message + end + end + class BadRequestError < Error; end + class UnauthorizedError < Error; end + class PaymentRequiredError < Error; end + class ForbiddenError < Error; end + class NotFoundError < Error; end + class TooManyRequestsError < Error; end + class InternalServerError < Error; end + class ServiceUnavailableError < Error; end + class TimeoutError < Error; end end diff --git a/lib/blazeverify/client.rb b/lib/blazeverify/client.rb index 07c94db..a67e5d2 100644 --- a/lib/blazeverify/client.rb +++ b/lib/blazeverify/client.rb @@ -67,21 +67,4 @@ def self.should_retry?(error, num_retries) false end end - - class Error < StandardError - attr_accessor :code, :message - - def initialize(code: nil, message: nil) - @code = code - @message = message - end - end - class BadRequestError < Error; end - class UnauthorizedError < Error; end - class PaymentRequiredError < Error; end - class ForbiddenError < Error; end - class NotFoundError < Error; end - class TooManyRequestsError < Error; end - class InternalServerError < Error; end - class ServiceUnavailableError < Error; end end diff --git a/lib/blazeverify/email_validator.rb b/lib/blazeverify/email_validator.rb index c7a2597..326e961 100644 --- a/lib/blazeverify/email_validator.rb +++ b/lib/blazeverify/email_validator.rb @@ -45,9 +45,6 @@ def validate_each(record, attribute, value) record.instance_variable_set("@#{result_accessor}", ev) end - # if response is taking too long - return unless ev.respond_to?(:state) - error ||= ev.state.to_sym unless states.include?(ev.state.to_sym) error ||= :free if ev.free? && !free error ||= :role if ev.role? && !role diff --git a/lib/blazeverify/version.rb b/lib/blazeverify/version.rb index 2e1fd79..ac8ad68 100644 --- a/lib/blazeverify/version.rb +++ b/lib/blazeverify/version.rb @@ -1,3 +1,3 @@ module BlazeVerify - VERSION = '1.3.2' + VERSION = '2.0.0' end diff --git a/test/blazeverify_test.rb b/test/blazeverify_test.rb index 7d2455c..9c9ef84 100644 --- a/test/blazeverify_test.rb +++ b/test/blazeverify_test.rb @@ -61,4 +61,10 @@ def test_name_and_gender end end + def test_slow_verification + assert_raises(BlazeVerify::TimeoutError) do + BlazeVerify.verify('slow@example.com') + end + end + end