Class: CaptchaSolver::Base
- Inherits:
-
Object
- Object
- CaptchaSolver::Base
- Defined in:
- lib/captcha_solver/base.rb
Direct Known Subclasses
Defined Under Namespace
Classes: FailedError, NotSolvedError, NotStartedError
Constant Summary collapse
- TIMEOUTS_BETWEEN_ATTEMPTS =
[40, 40, 40, 40, 40]
Instance Attribute Summary collapse
-
#complete_response ⇒ Object
readonly
Returns the value of attribute complete_response.
-
#proxy_address ⇒ Object
readonly
Returns the value of attribute proxy_address.
-
#rucaptcha_api_key ⇒ Object
readonly
Returns the value of attribute rucaptcha_api_key.
-
#start_response ⇒ Object
readonly
Returns the value of attribute start_response.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
-
#solve ⇒ Object
1.
-
#solved_captcha ⇒ Object
Returns solved captcha.
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
15 16 17 18 |
# File 'lib/captcha_solver/base.rb', line 15 def initialize(args = {}) @rucaptcha_api_key = ENV['rucaptcha_api_key'] @proxy_address = args[:proxy_address] end |
Instance Attribute Details
#complete_response ⇒ Object (readonly)
Returns the value of attribute complete_response.
12 13 14 |
# File 'lib/captcha_solver/base.rb', line 12 def complete_response @complete_response end |
#proxy_address ⇒ Object (readonly)
Returns the value of attribute proxy_address.
12 13 14 |
# File 'lib/captcha_solver/base.rb', line 12 def proxy_address @proxy_address end |
#rucaptcha_api_key ⇒ Object (readonly)
Returns the value of attribute rucaptcha_api_key.
12 13 14 |
# File 'lib/captcha_solver/base.rb', line 12 def rucaptcha_api_key @rucaptcha_api_key end |
#start_response ⇒ Object (readonly)
Returns the value of attribute start_response.
12 13 14 |
# File 'lib/captcha_solver/base.rb', line 12 def start_response @start_response end |
Instance Method Details
#solve ⇒ Object
-
Makes a in.php request in order to get the rucaptcha id.
-
Waits for 40 seconds, so the captcha can be solved by that time.
-
Makes a res.php request in order to get the solved captcha.
-
If captcha is not solved, it tries to do the same 4 more times.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/captcha_solver/base.rb', line 24 def solve start raise NotStartedError.new(start_response&.body) unless started? TIMEOUTS_BETWEEN_ATTEMPTS.each do |seconds| wait_for(seconds) complete raise FailedError.new(complete_response&.body) if failed? return solved_captcha if solved? end raise NotSolvedError.new(complete_response&.body) end |
#solved_captcha ⇒ Object
Returns solved captcha.
41 42 43 44 |
# File 'lib/captcha_solver/base.rb', line 41 def solved_captcha return nil unless solved? captcha_value end |