Class: AntigateRb::Client
- Inherits:
-
Object
- Object
- AntigateRb::Client
- Defined in:
- lib/antigate_rb/client.rb
Instance Method Summary collapse
- #check ⇒ Object
- #decode(image) ⇒ Object
- #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/antigate_rb/client.rb', line 8 def initialize( = {}) @retries_count = .delete(:retries_count) || 10 @sleep = .delete(:sleep) || 5 @options = AntigateRb.configuration..merge() end |
Instance Method Details
#check ⇒ Object
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_balance ⇒ Object
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_bad ⇒ Object
38 39 40 41 |
# File 'lib/antigate_rb/client.rb', line 38 def report_bad return if @captcha_id.blank? request_report_bad end |