Class: Capsolver::Base
- Inherits:
-
Object
- Object
- Capsolver::Base
- Defined in:
- lib/capsolver/base.rb
Direct Known Subclasses
AwsWaf, Cloudflare, Control, DatadomeSlider, FriendlyCaptcha, GeeTest, ImageToText, MtCaptcha, ReCaptcha, VisionEngine, YandexCaptcha
Constant Summary collapse
- APP_ID =
"3E36E3CD-7EB5-4CAF-AA15-91011E652321"- REQUEST_URL =
"https://api.capsolver.com"- VALID_STATUS_CODES =
[200, 202, 400, 401, 405]
- CAPTCHA_UNSOLVABLE =
"ERROR_CAPTCHA_UNSOLVABLE"- CAPTCHA_UNSOLVABLE_DESCRIPTION =
"Captcha not recognized"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#captcha_type ⇒ Object
Returns the value of attribute captcha_type.
-
#request_url ⇒ Object
Returns the value of attribute request_url.
-
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
Instance Method Summary collapse
- #captcha_handler(task_payload) ⇒ Object (also: #aio_captcha_handler)
-
#initialize(api_key: nil, captcha_type:, sleep_time: nil, request_url: nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(api_key: nil, captcha_type:, sleep_time: nil, request_url: nil) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 |
# File 'lib/capsolver/base.rb', line 15 def initialize(api_key: nil, captcha_type:, sleep_time: nil, request_url: nil) @api_key = api_key || Capsolver.configuration.api_key raise ArgumentError, "api_key is required (either configure it globally via Capsolver.configure or pass it to initialize)" if @api_key.nil? @captcha_type = captcha_type @sleep_time = sleep_time || Capsolver.configuration.sleep_time @request_url = request_url || Capsolver.configuration.request_url end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/capsolver/base.rb', line 13 def api_key @api_key end |
#captcha_type ⇒ Object
Returns the value of attribute captcha_type.
13 14 15 |
# File 'lib/capsolver/base.rb', line 13 def captcha_type @captcha_type end |
#request_url ⇒ Object
Returns the value of attribute request_url.
13 14 15 |
# File 'lib/capsolver/base.rb', line 13 def request_url @request_url end |
#sleep_time ⇒ Object
Returns the value of attribute sleep_time.
13 14 15 |
# File 'lib/capsolver/base.rb', line 13 def sleep_time @sleep_time end |
Instance Method Details
#captcha_handler(task_payload) ⇒ Object Also known as: aio_captcha_handler
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capsolver/base.rb', line 24 def captcha_handler(task_payload) task = { type: @captcha_type }.merge(task_payload) create_task_payload = { clientKey: @api_key, appId: APP_ID, task: task } created_task_data = create_task(create_task_payload) if created_task_data["errorId"] == 0 if created_task_data["status"]&.downcase == "ready" created_task_data else get_result(created_task_data["taskId"]) end else created_task_data["status"] = "failed" created_task_data end end |