Developers / SDKs
Ruby SDK.
Ruby 2.6+, no dependencies. One file. Give it a page address, get the token.
1. Add the client
Save the client as captora.rb next to your script and require it.
captora.rb
# captora.rb: zero-dependency Captora client for Ruby 2.6+ (standard library only).require "net/http"require "json"require "uri"class Captora class Error < StandardError; end BASE_URL = "https://api.captora.me".freeze def initialize(api_key, base_url: BASE_URL, poll_seconds: 3, timeout_seconds: 180) @api_key = api_key @base_url = base_url @poll_seconds = poll_seconds @timeout_seconds = timeout_seconds end # Returns { "balance_paise" => ... } (100 paise = Rs 1). def balance request(:get, "/v1/balance") end # The simple way: give the address of a page with a captcha. Captora recognises the captcha, solves it, and # returns its "result" hash (usually { "token" => ... }). Pass html: (the page source) for pages that add the # captcha with JavaScript or need a login. Raises Captora::Error if it can't be solved (you are not charged). def solve_url(website_url, extra = {}) wait_for(request(:post, "/v1/solve", extra.merge(websiteURL: website_url))) end # Advanced: you already know the captcha type. Waits for the task and returns its "result" hash. def solve(type, params = {}) wait_for(request(:post, "/v1/tasks", params.merge(type: type))) end private def wait_for(task) deadline = Time.now + @timeout_seconds while task["status"] == "processing" && Time.now < deadline sleep @poll_seconds task = request(:get, "/v1/tasks/#{task['taskId']}") end return task["result"] if task["status"] == "completed" raise Error, (task["status"] == "failed" ? "Could not be solved (refunded)" : "Timed out") end def request(method, path, body = nil) uri = URI(@base_url + path) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" http.read_timeout = 60 req = (method == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri) req["Authorization"] = "Bearer #{@api_key}" req["Content-Type"] = "application/json" req["User-Agent"] = "captora-ruby/1.0" req.body = JSON.generate(body) if body res = http.request(req) data = begin JSON.parse(res.body) rescue StandardError {} end raise Error, "Captora error #{res.code}: #{data['error'] || 'unknown'}" unless res.is_a?(Net::HTTPSuccess) data endend2. Solve a captcha with one call
Put your API key in the CAPTORA_API_KEY environment variable (create one in your dashboard).
example.rb
require_relative "captora"captora = Captora.new(ENV.fetch("CAPTORA_API_KEY"))# Give it the page with the captcha. Captora finds the captcha and solves it.result = captora.solve_url("https://example.com/login")puts result["token"] # submit this token with your form# Know the type already? captora.solve("recaptcha_v2", websiteURL: ..., websiteKey: ...)3. That's it. No captcha type to pick
Captora recognises the captcha on the page. For pages that add it with JavaScript or sit behind a login, pass the page's HTML as well (see the docs). If you already know the type, the client has a second method for that. Every captcha we support, and its price, is on the captchas page.
Keep in mind
- Keep your API key on your server. Never ship it in a browser or mobile app.
- Solving can take from a few seconds to a minute or more, so run it in the background of your app.
- Unsolved tasks raise an error and are refunded automatically.