Class: ZeroCaptcha::Client
- Inherits:
-
Object
- Object
- ZeroCaptcha::Client
- Defined in:
- lib/zero_captcha/client.rb
Overview
ZeroCaptcha::Client is a client that communicates with the ZeroCaptcha API: zerocaptcha.infosimples.com/.
Constant Summary collapse
- BASE_URL =
'https://zerocaptcha.infosimples.com/api/v1/captcha/:action.json'
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#decode(options = {}) ⇒ ZeroCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
-
#decode!(options = {}) ⇒ ZeroCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
-
#initialize(token, options = {}) ⇒ ZeroCaptcha::Client
constructor
Create a ZeroCaptcha API client.
-
#report_correct(id) ⇒ ZeroCaptcha::Captcha
Report correctly solved captcha for statistics.
-
#report_incorrect(id) ⇒ ZeroCaptcha::Captcha
Report incorrectly solved captcha for refund.
Constructor Details
#initialize(token, options = {}) ⇒ ZeroCaptcha::Client
Create a ZeroCaptcha API client.
19 20 21 22 |
# File 'lib/zero_captcha/client.rb', line 19 def initialize(token, = {}) self.token = token self.timeout = [:timeout] || 60 end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/zero_captcha/client.rb', line 8 def timeout @timeout end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/zero_captcha/client.rb', line 8 def token @token end |
Instance Method Details
#decode(options = {}) ⇒ ZeroCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
38 39 40 41 42 |
# File 'lib/zero_captcha/client.rb', line 38 def decode( = {}) decode!() rescue ZeroCaptcha::Error ZeroCaptcha::Captcha.new end |
#decode!(options = {}) ⇒ ZeroCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/zero_captcha/client.rb', line 58 def decode!( = {}) raw64 = load_captcha() solver = [:solver] response = request(solver, :multipart, image64: raw64) captcha = ZeroCaptcha::Captcha.new(response) fail(ZeroCaptcha::IncorrectSolution) unless captcha.correct? captcha end |
#report_correct(id) ⇒ ZeroCaptcha::Captcha
Report correctly solved captcha for statistics.
87 88 89 90 |
# File 'lib/zero_captcha/client.rb', line 87 def report_correct(id) response = request('report_correct', :post, id: id) ZeroCaptcha::Captcha.new(response) end |
#report_incorrect(id) ⇒ ZeroCaptcha::Captcha
Report incorrectly solved captcha for refund.
76 77 78 79 |
# File 'lib/zero_captcha/client.rb', line 76 def report_incorrect(id) response = request('report_incorrect', :post, id: id) ZeroCaptcha::Captcha.new(response) end |