infosimples / two_captcha

#1
two_captcha.png

TwoCaptcha is a Ruby API for 2Captcha - 2Captcha.com.

Installation
Add this line to your application's Gemfile:
gem 'two_captcha'

And then execute:
$ bundle

Or install it yourself as:
$ gem install two_captcha

Usage
  1. Create a client
Code:
# Create a client
client = TwoCaptcha.new('my_captcha_key')
  1. Solve a captcha
There are two methods available: decode and decode! * decode doesn't raise exceptions. * decode! may raise a TwoCaptcha::Error if something goes wrong.

If the solution is not available, an empty captcha object will be returned.
Code:
captcha = client.decode!(url: 'http://bit.ly/1xXZcKo')
captcha.text        # Solution of the captcha
captcha.id          # Numeric ID of the captcha solved by TwoCaptcha
You can also specify path, file, raw and raw64 when decoding an image.
Code:
client.decode(path: 'path/to/my/captcha/file')

client.decode(file: File.open('path/to/my/captcha/file', 'rb'))

client.decode(raw: File.open('path/to/my/captcha/file', 'rb').read)

client.decode(raw64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
Internally, the gem will always convert the image to raw64 (binary base64 encoded).​
You may also specify any POST parameters specified at https://2captcha.com/setting.

  1. Retrieve a previously solved captcha
captcha = client.captcha('130920620') # with 130920620 as the captcha id
  1. Report incorrectly (for refund) or correctly (useful for reCAPTCHA v3) solved captcha
Code:
client.report!('130920620', 'reportbad') # with 130920620 as the captcha id
# return true if successfully reported

client.report!('256892751', 'reportgood') # with 256892751 as the captcha id
# return true if successfully reported
Warning: do not abuse on this method, otherwise you may get banned
  1. Get your balance on 2Captcha
Code:
client.balance
# return a Float balance in USD.
  1. Get usage statistics for a specific date
Code:
client.stats('2015-08-05')
# return an XML string with your usage statistics.
  1. Get current 2Captcha load
Code:
client.load
# return an XML string with the current service load.
Documentation https://github.com/infosimples/two_captcha