Ruby
verisec is the official gem for Ruby 3.0 and later. It uses only the standard library. RubyGems
Install#
gem install verisecCreate a client#
require "verisec"
client = VeriSec::Client.new(api_key: ENV["VERISEC_API_KEY"]) # sk_test_…Every option falls back to the environment (VERISEC_API_KEY). Options include timeout: in seconds per attempt and max_retries: (default 2).
Make a call#
Every endpoint is a method named after its operation, in snake case: face.verify is client.face.verify, age.verifyLive is client.age.verify_live. Keyword names are exactly the API's.
result = client.face.verify(image1: "selfie.jpg", image2: "id-photo.jpg", threshold: 0.8)
puts result.match, result.similarity
doc = client.documents.read(image_front: "id-front.jpg", image_back: Pathname("id-back.jpg"))
cheque = client.cheques.read(image: "cheque.jpg")An image can be a path, a Pathname, an IO, a data: URI or base64.
Errors#
begin
client.face.verify(image1: "selfie.jpg", image2: "id-photo.jpg")
rescue VeriSec::InsufficientCreditsError
warn "Top up credits (nothing was charged)."
rescue VeriSec::InvalidRequestError => e
warn "#{e.code} #{e.param}: #{e.message}"
rescue VeriSec::RateLimitError => e
warn "Wait #{e.retry_after} s."
rescue VeriSec::APIError => e
warn "#{e.status} #{e.code} #{e.request_id}"
rescue VeriSec::APIConnectionError => e
warn e.message # says whether the call may have run
endWebhooks#
event = VeriSec::Webhook.construct_event(request.body.read, request.env, ENV["VERISEC_WEBHOOK_SECRET"])See Webhooks for a full handler.