From 1e9fb1f8ecd176f64bf6eb597908e8526750dd1f Mon Sep 17 00:00:00 2001 From: PBadicean Date: Thu, 15 Jun 2023 18:59:06 +0300 Subject: [PATCH] yandex method --- .rspec_status | 12 ++++++---- Gemfile.lock | 2 +- README.md | 48 +++++++++++++++++++++++++++++++------- lib/api_2captcha/client.rb | 14 +++++++---- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.rspec_status b/.rspec_status index bfc0b86..5744313 100644 --- a/.rspec_status +++ b/.rspec_status @@ -1,5 +1,7 @@ -example_id | status | run_time | ----------------------------------- | ------ | --------------- | -./spec/api_2captcha_spec.rb[1:1] | passed | 0.00937 seconds | -./spec/api_2captcha_spec.rb[1:2:1] | passed | 0.00111 seconds | -./spec/api_2captcha_spec.rb[1:3:1] | passed | 7.1 seconds | +example_id | status | run_time | +---------------------------------- | ------ | --------------------- | +./spec/api_2captcha_spec.rb[1:1] | passed | 0.04326 seconds | +./spec/api_2captcha_spec.rb[1:2:1] | passed | 0.00121 seconds | +./spec/api_2captcha_spec.rb[1:3:1] | passed | 3.15 seconds | +./spec/api_2captcha_spec.rb[1:4:1] | passed | 2 minutes 0.2 seconds | +./spec/api_2captcha_spec.rb[1:5:1] | passed | 0.26142 seconds | diff --git a/Gemfile.lock b/Gemfile.lock index 2df2cbd..7481461 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ruby-2captcha (0.1.0) + ruby-2captcha (1.0.2) GEM remote: https://rubygems.org/ diff --git a/README.md b/README.md index fa9d973..c7a279a 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,9 @@ A Ruby client for the 2Captcha API. - [Solve captcha](#solve-captcha) - [Normal Captcha](#normal-captcha) - [Text](#text-captcha) - - [ReCaptcha v2](#recaptcha-v2) - - [ReCaptcha v3](#recaptcha-v3) + - [reCAPTCHA v2](#recaptcha-v2) + - [reCAPTCHA v3](#recaptcha-v3) + - [reCAPTCHA Enterprise](#recaptcha-enterprise) - [GeeTest](#geetest) - [hCaptcha](#hcaptcha) - [KeyCaptcha](#keycaptcha) @@ -71,7 +72,7 @@ client.api_key = "YOUR_API_KEY" |---|---|---| |soft_id|-|your software ID obtained after publishing in [2captcha sofware catalog]| |callback|-|URL of your web-sever that receives the captcha recognition result. The URl should be first registered in [pingback settings] of your account| -|default_timeout|120|Timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from `res.php` API endpoint| +|default_timeout|120|Timeout in seconds for all captcha types except reCAPTCHA. Defines how long the module tries to get the answer from `res.php` API endpoint| |polling_interval|10|Interval in seconds between requests to `res.php` API endpoint, setting values less than 5 seconds is not recommended| > **IMPORTANT:** once `callback` is defined for `Client` instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. @@ -115,8 +116,8 @@ result = client.text({ }) ``` -### ReCaptcha v2 -Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection. +### reCAPTCHA v2 +Use this method to solve reCAPTCHA V2 and obtain a token to bypass the protection. ```ruby result = client.recaptcha_v2({ googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', @@ -125,8 +126,8 @@ result = client.recaptcha_v2({ }) ``` -### ReCaptcha v3 -This method provides ReCaptcha V3 solver and returns a token. +### reCAPTCHA v3 +This method provides reCAPTCHA V3 solver and returns a token. ```ruby result = client.recaptcha_v3({ googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', @@ -135,6 +136,28 @@ result = client.recaptcha_v3({ score: 0.3, action: 'verify' }) +`` + +### reCAPTCHA Enterprise +reCAPTCHA Enterprise can be used as reCAPTCHA V2 and reCAPTCHA V3. Below is a usage example for both versions. + +```ruby +# reCAPTCHA V2 +result = client.recaptcha_v2({ + googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + pageurl: 'https://mysite.com/page/with/recaptcha_v2_enterprise', + enterprise: 1 +}) + +# reCAPTCHA V3 +result = client.recaptcha_v3({ + googlekey: '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', + pageurl: 'https://mysite.com/page/with/recaptcha_v3_enterprise', + version: 'v3', + score: 0.3, + action: 'verify', + enterprise: 1, +}) ``` ### FunCaptcha @@ -190,7 +213,7 @@ result = client.capy({ ``` ### Grid -Grid method is originally called Old ReCaptcha V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes. +Grid method is originally called Old reCAPTCHA V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes. ```ruby result = client.grid({ image: 'path/to/captcha.jpg', @@ -289,6 +312,15 @@ result = client.audio({ }) ``` +### Yandex +Use this method to solve Yandex and obtain a token to bypass the protection. +```ruby +result = client.yandex({ + sitekey: 'Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV', + url: "https://rutube.ru" +}) +``` + ## Other methods ### send / get_result diff --git a/lib/api_2captcha/client.rb b/lib/api_2captcha/client.rb index 746a4b0..c2b6c2a 100644 --- a/lib/api_2captcha/client.rb +++ b/lib/api_2captcha/client.rb @@ -31,16 +31,16 @@ def solve(method, params = {}, file_path = nil, return_id: false) params["key"] = @api_key params["soft_id"] = @soft_id params["json"] = 1 + if @callback params["pingback"] = @callback return_id = true - else - return_id end + complete_params = get_params(params) captcha_id = send_request(complete_params) - - return_id ? captcha_id : get_result(captcha_id) + return captcha_id if return_id + get_result(captcha_id) end def send(*args) @@ -132,7 +132,7 @@ def capy(params) def grid(params) params["recaptcha"] = 1 - solve("capy", params) + solve("post", params) end def canvas(params) @@ -178,6 +178,10 @@ def audio(params) solve("audio", params) end + def yandex(params) + solve("yandex", params) + end + private def base_url