Class: AntiCaptcha::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/anti-captcha/client.rb

Instance Method Summary collapse

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(options = {})
  @retries_count = options.delete(:retries_count) || 10
  @sleep = options.delete(:sleep) || 5
  @options = AntiCaptcha.configuration.options.merge(options)
end

Instance Method Details

#checkObject



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_balanceObject



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_badObject



40
41
42
43
# File 'lib/anti-captcha/client.rb', line 40

def report_bad
  return if @captcha_id.blank?
  request_report_bad
end