Class: AntigateRb::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/antigate_rb/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/antigate_rb/client.rb', line 8

def initialize(options = {})
  @retries_count = options.delete(:retries_count) || 10
  @sleep = options.delete(:sleep) || 5
  @options = AntigateRb.configuration.options.merge(options)
end

Instance Method Details

#checkObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/antigate_rb/client.rb', line 26

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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/antigate_rb/client.rb', line 14

def decode(image)
  case request_image(image)
  when /OK\|(.+)/
    @captcha_id = $1
    check
  when /^ERROR_(.+)/
    raise error_class($1)
  else
    raise UnknownResponse
  end
end

#get_balanceObject



43
44
45
# File 'lib/antigate_rb/client.rb', line 43

def get_balance
  request_balance
end

#get_stats(date = Date.today) ⇒ Object



47
48
49
# File 'lib/antigate_rb/client.rb', line 47

def get_stats(date = Date.today)
  request_stats date
end

#report_badObject



38
39
40
41
# File 'lib/antigate_rb/client.rb', line 38

def report_bad
  return if @captcha_id.blank?
  request_report_bad
end