ruby-2captcha 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d43df532b2141353e6422da8e0665393eb50e141146845a1c29626588c4dd68
4
- data.tar.gz: d8ebb3b307406598dc10d828a7263f3a31d703fde4f9e2c0ed0dce362beddb8d
3
+ metadata.gz: 6e27af7b5ab7e5e7a117b7598d8eb609ca10bee60174078691eda86265e8d464
4
+ data.tar.gz: 21dcd54bfe95f730b5887e41bdbdec5baca72eb915e8b8125f1006c59821640b
5
5
  SHA512:
6
- metadata.gz: f0a5795f465569fdbede1fec84f74f1d65ba0a1cdc7adf93021b4feb11cfc22b377330c4ac7a2574e5dceffc6358106d64ed0a518375370a3a56b52a3ecbbbda
7
- data.tar.gz: a979fff1899841066c9d2898ae0c6e56bd2725221ca1542cd5b4f040f9e7b48fe491fc4c7f51dc41f61565ab041fb986260a2fda6879f6296df69d116a6cf6f7
6
+ metadata.gz: 69eeb331f6d5104521ffceaaa3268cab0c48c502e9e390d9e6d259cdfb568027f2ffbd82cbcf445797663fd6f9deaf89537a88e50e42459ca70df6b53af54a79
7
+ data.tar.gz: c25f4db3a71a56f95846964081f986765007a38a493917d496e3e21f2a6b974b2917788b35265d2c622a13f99bac620e89cefb121890b099da91fade1759fa1c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-2captcha (1.1.6)
4
+ ruby-2captcha (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -56,6 +56,7 @@ Examples of API requests for different captcha types are available on the [Ruby
56
56
  - [Alibaba](#alibaba)
57
57
  - [Yidun](#yidun)
58
58
  - [Drag & Drop Captcha](#drag--drop-captcha)
59
+ - [Imperva (Incapsula)](#imperva-incapsula)
59
60
  - [Other methods](#other-methods)
60
61
  - [send / get_result](#send--get_result)
61
62
  - [balance](#balance)
@@ -688,6 +689,29 @@ result = client.drag_drop({
688
689
  })
689
690
  ```
690
691
 
692
+ ### Imperva (Incapsula)
693
+
694
+ <sup>[API method description.](https://2captcha.com/2captcha-api#imperva)</sup>
695
+
696
+ Cookie-based method for automated solving of Imperva (Incapsula) captcha. `incapsula_script_url` and `incapsula_cookies` are generated dynamically and may differ on each page load. Optionally pass `reese84_url_endpoint` if the site uses Reese84, and `userAgent` of the browser that opens the page.
697
+
698
+ The result contains cookies for each domain in `request.domains`, which should be sent to the target site. If `request.headers.User-Agent` is returned, use the same User-Agent in requests to the site.
699
+
700
+ > [!IMPORTANT]
701
+ > To solve the Imperva captcha, you must use a proxy. It is recommended to use [residential proxies].
702
+
703
+ ```ruby
704
+ result = client.imperva({
705
+ pageurl: "https://example.com/page-with-imperva",
706
+ incapsula_script_url: "/_Incapsula_Resource?SWUDNSAI=31&xinfo=1",
707
+ incapsula_cookies: "visid_incap_123456=sample; incap_ses_123_123456=sample",
708
+ reese84_url_endpoint: "https://example.com/_Incapsula_Resource?reese84=1",
709
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
710
+ proxytype: "http",
711
+ proxy: "proxyuser:strongPassword@123.123.123.123:3128"
712
+ })
713
+ ```
714
+
691
715
  ## Other methods
692
716
 
693
717
  ### send / get_result
data/README.ru.md CHANGED
@@ -53,6 +53,7 @@
53
53
  - [Alibaba](#alibaba)
54
54
  - [Yidun](#yidun)
55
55
  - [Drag & Drop Captcha](#drag--drop-captcha)
56
+ - [Imperva (Incapsula)](#imperva-incapsula)
56
57
  - [Другие методы](#другие-методы)
57
58
  - [send / get_result](#send--get_result)
58
59
  - [Баланс](#баланс)
@@ -680,6 +681,29 @@ result = client.drag_drop({
680
681
  })
681
682
  ```
682
683
 
684
+ ### Imperva (Incapsula)
685
+
686
+ <sup>[Описание метода API](https://2captcha.com/2captcha-api#imperva)</sup>
687
+
688
+ Основанный на cookies метод автоматизированного решения капчи Imperva (Incapsula). Параметры `incapsula_script_url` и `incapsula_cookies` генерируются динамически и могут отличаться при каждой загрузке страницы. Необязательно можно передать `reese84_url_endpoint`, если он нужен на конкретном сайте, и `userAgent` браузера, с которым открывается страница.
689
+
690
+ В ответе приходят cookies для каждого домена в `request.domains` — их нужно передать на целевой сайт. Если в ответе пришёл `request.headers.User-Agent`, используйте тот же User-Agent в запросах к сайту.
691
+
692
+ > [!IMPORTANT]
693
+ > Для решения Imperva captcha необходимо использовать прокси. Рекомендуется использовать [резидентные прокси].
694
+
695
+ ```ruby
696
+ result = client.imperva({
697
+ pageurl: "https://example.com/page-with-imperva",
698
+ incapsula_script_url: "/_Incapsula_Resource?SWUDNSAI=31&xinfo=1",
699
+ incapsula_cookies: "visid_incap_123456=sample; incap_ses_123_123456=sample",
700
+ reese84_url_endpoint: "https://example.com/_Incapsula_Resource?reese84=1",
701
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
702
+ proxytype: "http",
703
+ proxy: "proxyuser:strongPassword@123.123.123.123:3128"
704
+ })
705
+ ```
706
+
683
707
  ## Другие методы
684
708
 
685
709
  ### send / get_result
@@ -0,0 +1,20 @@
1
+
2
+ require_relative '../lib/api_2captcha'
3
+
4
+ client = Api2Captcha.new(ARGV[0])
5
+
6
+ begin
7
+ result = client.imperva({
8
+ pageurl: "https://example.com/page-with-imperva",
9
+ incapsula_script_url: "/_Incapsula_Resource?SWUDNSAI=31&xinfo=1",
10
+ incapsula_cookies: "visid_incap_123456=sample; incap_ses_123_123456=sample",
11
+ reese84_url_endpoint: "https://example.com/_Incapsula_Resource?reese84=1",
12
+ userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
13
+ proxytype: "http",
14
+ proxy: "proxyuser:strongPassword@123.123.123.123:3128"
15
+ })
16
+ rescue StandardError => e
17
+ puts(e)
18
+ end
19
+
20
+ puts "Result: #{result.inspect}"
@@ -1,10 +1,23 @@
1
- require 'api_2captcha'
1
+ require "api_2captcha"
2
2
 
3
- client = Api2Captcha.new("YOUR_API_KEY")
3
+ client = Api2Captcha.new(ARGV[0])
4
4
 
5
- result = client.text({
6
- textcaptcha:'If tomorrow is Saturday, what day is today?',
7
- lang: "en"
8
- })
9
-
10
- puts "Result: #{result.inspect}"
5
+ begin
6
+ result = client.text({
7
+ textcaptcha: "If tomorrow is Saturday, what day is today?",
8
+ lang: "en"
9
+ })
10
+ puts "Result: #{result.inspect}"
11
+ rescue Api2Captcha::ValidationException => e
12
+ # invalid parameters passed
13
+ puts(e)
14
+ rescue Api2Captcha::NetworkException => e
15
+ # network error occurred
16
+ puts(e)
17
+ rescue Api2Captcha::ApiException => e
18
+ # api respond with error
19
+ puts(e)
20
+ rescue Api2Captcha::TimeoutException => e
21
+ # captcha is not solved so far
22
+ puts(e)
23
+ end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
- require 'net/http'
3
- require 'uri'
4
- require 'json'
5
- require 'base64'
6
- require 'open-uri'
2
+
3
+ require "net/http"
4
+ require "uri"
5
+ require "json"
6
+ require "base64"
7
+ require "open-uri"
7
8
 
8
9
  module Api2Captcha
9
10
  class Client
@@ -42,12 +43,15 @@ module Api2Captcha
42
43
  complete_params = get_params(params)
43
44
  captcha_id = send_request(complete_params)
44
45
  return captcha_id if return_id
46
+
45
47
  get_result(captcha_id)
46
48
  end
47
49
 
48
50
  def send(*args)
49
- raise ArgumentError,
50
- "Invalid arguments of the send method" unless args.size == 1
51
+ unless args.size == 1
52
+ raise ArgumentError,
53
+ "Invalid arguments of the send method"
54
+ end
51
55
 
52
56
  arg = args.first
53
57
  if arg.is_a?(String)
@@ -94,7 +98,7 @@ module Api2Captcha
94
98
 
95
99
  def get_balance
96
100
  response = make_res_request({ "action" => "getbalance" }, "getbalance")
97
- return response["request"].to_f
101
+ response["request"].to_f
98
102
  end
99
103
 
100
104
  def normal(params)
@@ -265,6 +269,10 @@ module Api2Captcha
265
269
  solve("drag_drop", **params)
266
270
  end
267
271
 
272
+ def imperva(params)
273
+ solve("incapsula", **params)
274
+ end
275
+
268
276
  private
269
277
 
270
278
  def base_url
@@ -274,7 +282,7 @@ module Api2Captcha
274
282
  def send_request(params)
275
283
  uri = URI("#{base_url}/in.php")
276
284
  req = Net::HTTP::Post.new(uri)
277
- req.content_type = 'application/json'
285
+ req.content_type = "application/json"
278
286
  req.body = params.to_json
279
287
  captcha_id = get_captcha_id(make_request(uri, req))
280
288
  end
@@ -288,14 +296,14 @@ module Api2Captcha
288
296
  hint_image = params.delete("hint_image")
289
297
 
290
298
  image_content = if base64_encoded?(image)
291
- image
292
- else
293
- Base64.strict_encode64(get_image_content(image))
294
- end
299
+ image
300
+ else
301
+ Base64.strict_encode64(get_image_content(image))
302
+ end
295
303
 
296
304
  hint_image_content = if hint_image
297
- base64_encoded?(hint_image) ? hint_image : Base64.strict_encode64(get_image_content(hint_image))
298
- end
305
+ base64_encoded?(hint_image) ? hint_image : Base64.strict_encode64(get_image_content(hint_image))
306
+ end
299
307
 
300
308
  result_params = {
301
309
  "method" => "base64",
@@ -309,20 +317,20 @@ module Api2Captcha
309
317
  end
310
318
 
311
319
  def get_image_content(image)
312
- return download_image(image) if image.start_with?('http')
320
+ return download_image(image) if image.start_with?("http")
313
321
  return File.binread(image) if File.file?(image)
322
+
314
323
  image
315
324
  end
316
325
 
317
326
  def base64_encoded?(string)
318
- string.is_a?(String) && string.match(/\A[A-Za-z0-9+\/=]+\z/) && (string.length % 4).zero?
327
+ string.is_a?(String) && string.match(%r{\A[A-Za-z0-9+/=]+\z}) && (string.length % 4).zero?
319
328
  end
320
329
 
321
330
  def download_image(url)
322
331
  response = URI.open(url)
323
- if response.status[0] != '200'
324
- raise StandardError, "File could not be downloaded from url: #{url}"
325
- end
332
+ raise StandardError, "File could not be downloaded from url: #{url}" if response.status[0] != "200"
333
+
326
334
  response.read
327
335
  end
328
336
 
@@ -336,11 +344,10 @@ module Api2Captcha
336
344
  case response
337
345
  when Net::HTTPSuccess
338
346
  response_json = JSON.parse(response.body.strip)
339
- if response_json["status"] == 1
340
- response_json["request"]
341
- else
342
- raise ApiException, "API Error: #{response_json["request"]}"
343
- end
347
+ raise ApiException, "API Error: #{response_json["request"]}" unless response_json["status"] == 1
348
+
349
+ response_json["request"]
350
+
344
351
  else
345
352
  raise NetworkException, "Network Error: #{response.code.to_i}"
346
353
  end
@@ -361,19 +368,17 @@ module Api2Captcha
361
368
  def make_res_request(request, action)
362
369
  uri = URI("#{base_url}/res.php?key=#{@api_key}&action=#{action}&json=1")
363
370
  req = Net::HTTP::Post.new(uri)
364
- req.content_type = 'application/json'
371
+ req.content_type = "application/json"
365
372
  req.body = request.to_json
366
373
 
367
374
  response = make_request(uri, req)
368
375
 
369
376
  case response
370
377
  when Net::HTTPSuccess
371
- return JSON.parse(response.body)
378
+ JSON.parse(response.body)
372
379
  else
373
380
  raise Api2Captcha::NetworkException, "Network Error: #{response.code.to_i}"
374
381
  end
375
382
  end
376
383
  end
377
384
  end
378
-
379
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Api2Captcha
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-2captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 2captcha.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-09-17 00:00:00.000000000 Z
11
+ date: 2026-10-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby package for easy integration with the API of 2captcha captcha solving
14
14
  service to bypass recaptcha, funcaptcha, geetest and solve any other captchas.
@@ -52,6 +52,7 @@ files:
52
52
  - examples/grid_captcha_example.rb
53
53
  - examples/hcaptcha_example.rb
54
54
  - examples/hunt_example.rb
55
+ - examples/imperva_example.rb
55
56
  - examples/key_captcha_example.rb
56
57
  - examples/lemin_example.rb
57
58
  - examples/media/drag_drop/background.jpeg