Skip to content

Commit

Permalink
Updates for sandbox API mode
Browse files Browse the repository at this point in the history
  • Loading branch information
twa-team committed Jul 16, 2018
1 parent 4c4d73c commit 25d7de9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ require "quickemailverification"

client = QuickEmailVerification::Client.new('Your_API_Key_Here')
quickemailverification = client.quickemailverification()

# PRODUCTION MODE
response = quickemailverification.verify("[email protected]")

# SANDBOX MODE
# response = quickemailverification.sandbox("[email protected]")

puts response.body
```

Expand Down Expand Up @@ -92,6 +98,11 @@ QuickEmailVerification API also returns following HTTP status codes to indicate
- `404` - Requested API can not be found on server.
- `429` - Too many requests. Rate limit exceeded.

## Sandbox Mode
QuickEmailVerification single email verification API sandbox mode helps developers to test their integration against simulated results. Requesting against sandbox endpoint is totally free and no credits will be deducted from actual credit quota.

Please refer our [knowledge base](http://docs.quickemailverification.com/email-verification-api/sandbox-mode) to learn more about sandbox mode.

## License
MIT

Expand Down
13 changes: 13 additions & 0 deletions lib/quickemailverification/api/quickemailverification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def verify(email, options = {})
@client.get("/verify?email=#{email}", body, options)
end

# Return predefined response for predefined email address
#
# '/verify/sandbox?email=:email' GET
#
# email - send email address in query parameter
def sandbox(email, options = {})
body = options.fetch("query", {})

email = CGI::escape(email)

@client.get("/verify/sandbox?email=#{email}", body, options)
end

end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/quickemailverification/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(auth = {}, options = {})
@options = {
:base => "http://api.quickemailverification.com",
:api_version => "v1",
:user_agent => "quickemailverification-ruby/1.0.1 (https://github.com/quickemailverification/quickemailverification-ruby)"
:user_agent => "quickemailverification-ruby/1.0.2 (https://github.com/quickemailverification/quickemailverification-ruby)"
}

@options.update(options)
Expand Down
40 changes: 21 additions & 19 deletions lib/quickemailverification/http_client/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@ def call(env)
when 400...499
body = QuickEmailVerification::HttpClient::ResponseHandler.get_body(env)
message = ""

# If HTML, whole body is taken
if body.is_a?(String)
message = body
end

# If JSON, a particular field is taken and used
if type.include?("json") and body.is_a?(Hash)
if body.has_key?("message")
message = body["message"]
else
message = "Unable to select error message from json returned by request responsible for error"
end
arrErrCode = [400, 401, 402, 403, 404, 429]
if !arrErrCode.include?(code)
# If HTML, whole body is taken
if body.is_a?(String)
message = body
end

# If JSON, a particular field is taken and used
if type.include?("json") and body.is_a?(Hash)
if body.has_key?("message")
message = body["message"]
else
message = "Unable to select error message from json returned by request responsible for error"
end
end

if message == ""
message = "Unable to understand the content type of response returned by request responsible for error"
end

raise QuickEmailVerification::Error::ClientError.new message, code
end

if message == ""
message = "Unable to understand the content type of response returned by request responsible for error"
end

raise QuickEmailVerification::Error::ClientError.new message, code
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion quickemailverification.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |gem|
gem.name = "quickemailverification"
gem.version = "1.0.1"
gem.version = "1.0.2"
gem.description = "Official QuickEmailVerification API library client for ruby."
gem.summary = "Official QuickEmailVerification API library client for ruby"

Expand Down

0 comments on commit 25d7de9

Please sign in to comment.