Skip to content

Commit

Permalink
Updated readme, changed slow requests to return a BlazeVerify::Timeou…
Browse files Browse the repository at this point in the history
…t error.
  • Loading branch information
jclusso committed Nov 13, 2020
1 parent 878557c commit df8a5b1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 34 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,14 @@ BlazeVerify.verify('[email protected]')

#### 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 `[email protected]`.

### Batch Verification

Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion lib/blazeverify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 0 additions & 17 deletions lib/blazeverify/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions lib/blazeverify/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/blazeverify/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlazeVerify
VERSION = '1.3.2'
VERSION = '2.0.0'
end
6 changes: 6 additions & 0 deletions test/blazeverify_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ def test_name_and_gender
end
end

def test_slow_verification
assert_raises(BlazeVerify::TimeoutError) do
BlazeVerify.verify('[email protected]')
end
end

end

0 comments on commit df8a5b1

Please sign in to comment.