Class: AntiCaptcha::Client
- Inherits:
-
Object
- Object
- AntiCaptcha::Client
- Defined in:
- lib/anti-captcha/client.rb
Instance Method Summary collapse
- #check ⇒ Object
-
#decode(image, type = :bin) ⇒ Object
type: file data (bin) type: base64 (base64).
- #get_balance ⇒ Object
- #get_stats(date = Date.today) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #report_bad ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/anti-captcha/client.rb', line 8 def initialize( = {}) @retries_count = .delete(:retries_count) || 10 @sleep = .delete(:sleep) || 5 @options = AntiCaptcha.configuration..merge() end |
Instance Method Details
#check ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/anti-captcha/client.rb', line 28 def check return if @captcha_id.blank? begin get_status rescue CaptchaNotReady => e attempt ||= @retries_count raise e if (attempt -= 1) < 0 sleep @sleep retry end end |
#decode(image, type = :bin) ⇒ Object
type: file data (bin) type: base64 (base64)
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/anti-captcha/client.rb', line 16 def decode(image, type = :bin) case request_image(image, type) when /OK\|(.+)/ @captcha_id = $1 check when /^ERROR_(.+)/ raise error_class($1) else raise UnknownResponse end end |
#get_balance ⇒ Object
45 46 47 |
# File 'lib/anti-captcha/client.rb', line 45 def get_balance request_balance end |
#get_stats(date = Date.today) ⇒ Object
49 50 51 |
# File 'lib/anti-captcha/client.rb', line 49 def get_stats(date = Date.today) request_stats date end |
#report_bad ⇒ Object
40 41 42 43 |
# File 'lib/anti-captcha/client.rb', line 40 def report_bad return if @captcha_id.blank? request_report_bad end |