anti_captcha 2.2.2 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12cd907f440f2218170c3b2ddfe61d140c19b4da58c62f9998aa772c58a38ef8
4
- data.tar.gz: cf69837b0cbc5fc593c756a57536ccbb2b5876c2c5c380bc61f798f6c4d4be9e
3
+ metadata.gz: c007c351a8655684c2f4680ead884429b8bea0ebd1fb33568119b15b477fcc76
4
+ data.tar.gz: 38267b78fb266cbb281a3d28db9cf32633398798a270bdc9e2bbd4f87cc2d84a
5
5
  SHA512:
6
- metadata.gz: 652ff3b4be305495b84f793a2049e65fa67af2a5614d2e80c1ec69a25a9817727c83c6511c1fc762319f406fd03457f6316cb2e356d598b5bd79743717c851ce
7
- data.tar.gz: 1ab34d03b69a5964ac1cdbf73337aeb60524b303b403a1fd81542a1722c441a2ae045c9e2303b20c5c601f5e8cf15ccd7849fd0b046df3b8e23cb348e993cf18
6
+ metadata.gz: 6bd0a5e3759806d4d88285d819a2d18738a47d560d2a4a25ab6497d1a7d12b3e07a34f0e7c2d1ac5755a1b7238a975fc45b49594019076f0fd53584dee67e085
7
+ data.tar.gz: 43a55d65f865c263b0fa732984a085b92ae5936530f8d6f6cc5a7e619e261629a3c4991907a85838b76968e73827270d3e580938c9adea23280a27a52e000ab4
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- Developed by [Infosimples](https://infosimples.com).
2
-
3
1
  # AntiCaptcha
4
2
 
5
- AntiCaptcha is a Ruby API for Anti-Captcha - [Anti-Captcha.com](http://getcaptchasolution.com/ipuz16klxh).
3
+ AntiCaptcha is a Ruby API for Anti-Captcha - [Anti-Captcha.com](http://getcaptchasolution.com/ipuz16klxh)
4
+
5
+ > We suggest you to also check the recommended CAPTCHA provider DeathByCaptcha.
6
+ > The gem for this provider is available at https://github.com/infosimples/deathbycaptcha.
6
7
 
7
8
  ## Installation
8
9
 
@@ -14,185 +15,293 @@ gem 'anti_captcha'
14
15
 
15
16
  And then execute:
16
17
 
17
- $ bundle
18
+ ```bash
19
+ $ bundle
20
+ ````
18
21
 
19
22
  Or install it yourself as:
20
23
 
21
- $ gem install anti_captcha
24
+ ```bash
25
+ $ gem install anti_captcha
26
+ ````
22
27
 
23
28
  ## Usage
24
29
 
25
- 1. **Create a client**
26
-
27
- ```ruby
28
- # Create a client
29
- client = AntiCaptcha.new('my_key')
30
- ```
31
-
32
- 2. **Solve Image CAPTCHA**
30
+ ### 1. Create a client
33
31
 
34
- There are two methods available:
35
-
36
- - `decode_image`: solves image CAPTCHAs. It doesn't raise exceptions.
37
- - `decode_image!`: solves image CAPTCHAs. It may raise an `AntiCaptcha::Error` if something goes wrong.
38
-
39
- If the solution is not available, an empty solution object will be returned.
32
+ ```ruby
33
+ client = AntiCaptcha.new('my_key')
34
+ ```
40
35
 
41
- ```ruby
42
- solution = client.decode_image!(path: 'path/to/my/captcha/file')
43
- solution.text # CAPTCHA solution.
44
- solution.url # Image URL.
45
- solution.task_result.task_id # The ID of the task.
46
- ```
36
+ ### 2. Solve a CAPTCHA
47
37
 
48
- You can also specify *file*, *body* and *body64* when decoding an image.
38
+ There are two types of methods available: `decode_*` and `decode_*!`:
49
39
 
50
- ```ruby
51
- client.decode_image!(file: File.open('path/to/my/captcha/file', 'rb'))
40
+ - `decode_*` does not raise exceptions.
41
+ - `decode_*!` may raise a `AntiCaptcha::Error` if something goes wrong.
52
42
 
53
- client.decode_image!(body: File.open('path/to/my/captcha/file', 'rb').read)
43
+ If the solution is not available, an empty solution object will be returned.
54
44
 
55
- client.decode_image!(body64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
56
- ```
45
+ ```ruby
46
+ solution = client.decode_image!(path: 'path/to/my/captcha/file')
47
+ solution.text # CAPTCHA solution
48
+ solution.url # Image URL
49
+ solution.task_result.task_id # The task ID
50
+ ```
57
51
 
58
- > Internally, the gem will always convert the image to body64 (binary base64 encoded).
52
+ #### Image CAPTCHA
59
53
 
60
- 3. **Report incorrectly solved image CAPTCHA for refund**
54
+ You can specify `file`, `body` or `body64` when decoding an image.
61
55
 
62
- It is only possible to report incorrectly solved image CAPTCHAs.
56
+ ```ruby
57
+ client.decode_image!(file: File.open('path/to/my/captcha/file', 'rb'))
58
+ client.decode_image!(body: File.open('path/to/my/captcha/file', 'rb').read)
59
+ client.decode_image!(body64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
60
+ ```
63
61
 
64
- ```ruby
65
- client.report_incorrect_image_catpcha!(task_id)
66
- ```
62
+ #### reCAPTCHA v2
67
63
 
68
- 4. **Get your account balance**
64
+ ```ruby
65
+ solution = client.decode_recaptcha_v2!(
66
+ website_key: 'xyz',
67
+ website_url: 'http://example.com/example=1',
68
+ # proxy_type: 'http', # OPTIONAL
69
+ # proxy_address: '127.0.0.1', # OPTIONAL
70
+ # proxy_port: '8080', # OPTIONAL
71
+ # proxy_login: 'proxyLoginHere', # OPTIONAL
72
+ # proxy_password: 'proxyPasswordHere', # OPTIONAL
73
+ # user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
74
+ )
75
+
76
+ solution.g_recaptcha_response
77
+ "03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
78
+ ```
69
79
 
70
- ```ruby
71
- client.get_balance!
72
- ```
80
+ *Parameters:*
73
81
 
74
- 5. **Get current stats of a queue.**
82
+ - `website_key`: the Google website key for the reCAPTCHA.
83
+ - `website_url`: the URL of the page with the reCAPTCHA challenge.
84
+ - `proxy_type`: optional parameter. Proxy connection protocol.
85
+ - `proxy_address`: optional parameter. The proxy address.
86
+ - `proxy_port`: optional parameter. The proxy port.
87
+ - `proxy_login`: optional parameter. The proxy login.
88
+ - `proxy_password`: optional parameter. The proxy password.
89
+ - `user_agent`: optional parameter. The user agent.
75
90
 
76
- Queue IDs:
77
- - `1` Standart ImageToText, English language.
78
- - `2` Standart ImageToText, Russian language.
79
- - `5` Recaptcha NoCaptcha tasks.
80
- - `6` Recaptcha Proxyless task.
91
+ #### reCAPTCHA v3
81
92
 
82
- ```ruby
83
- client.get_queue_stats!(queue_id)
84
- ```
93
+ ```ruby
94
+ solution = client.decode_recaptcha_v3!(
95
+ website_key: 'xyz',
96
+ website_url: 'http://example.com/example=1',
97
+ min_score: 0.3,
98
+ page_action: 'myverify',
99
+ # is_enterprise: false, # OPTIONAL
100
+ )
101
+
102
+ solution.g_recaptcha_response
103
+ "03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
104
+ ```
85
105
 
86
- 6. **Clickable CAPTCHAs (e.g. "No CAPTCHA reCAPTCHA")**
106
+ *Parameters:*
87
107
 
88
- This method allows you to solve CAPTCHAs similar to
89
- [reCAPTCHA v2](https://support.google.com/recaptcha/?hl=en#6262736).
108
+ - `website_key`: the Google website key for the reCAPTCHA.
109
+ - `website_url`: the URL of the page with the reCAPTCHA challenge.
110
+ - `action`: the action name used by the CAPTCHA.
111
+ - `min_score`: optional parameter. The minimal score needed for the CAPTCHA resolution. Defaults to `0.3`.
112
+ - `is_enterprise`: optional parameter. Set to `true` if you are solving a reCAPTCHA v3 Enterprise. Defaults to `false`.
90
113
 
91
- There are two methods available:
114
+ > About the `action` parameter: in order to find out what this is, you need to inspect the JavaScript
115
+ > code of the website looking for a call to the `grecaptcha.execute` function.
116
+ >
117
+ > ```javascript
118
+ > // Example
119
+ > grecaptcha.execute('6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f', { action: "examples/v3scores" })
120
+ > ````
92
121
 
93
- - `decode_nocaptcha`: solves NoCaptcha CAPTCHAs. It doesn't raise exceptions.
94
- - `decode_nocaptcha!`: solves NoCaptcha CAPTCHAs. It may raise an `AntiCaptcha::Error` if something goes wrong.
122
+ > About the `min_score` parameter: it's strongly recommended to use a minimum score of `0.3` as higher
123
+ > scores are rare.
95
124
 
96
- **Send the `website_key` and `website_url` parameters**
125
+ #### hCaptcha
97
126
 
98
- This method requires no browser emulation. You can send two parameters that
99
- identify the website in which the CAPTCHA is found.
127
+ ```ruby
128
+ solution = client.decode_h_captcha!(
129
+ website_key: 'xyz',
130
+ website_url: 'http://example.com/example=1',
131
+ # proxy_type: 'http', # OPTIONAL
132
+ # proxy_address: '127.0.0.1', # OPTIONAL
133
+ # proxy_port: '8080', # OPTIONAL
134
+ # proxy_login: 'proxyLoginHere', # OPTIONAL
135
+ # proxy_password: 'proxyPasswordHere', # OPTIONAL
136
+ # user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
137
+ )
138
+
139
+ solution.token
140
+ "P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
141
+
142
+ # Or
143
+
144
+ solution.g_recaptcha_response # Deprecated
145
+ "P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
146
+ ```
100
147
 
101
- ```ruby
102
- options = {
103
- website_key: 'xyz',
104
- website_url: 'http://example.com/example=1'
105
- }
148
+ *Parameters:*
106
149
 
107
- solution = client.decode_nocaptcha!(options)
108
- solution.g_recaptcha_response # Solution of the captcha
109
- ```
150
+ - `website_key`: the site key for the hCatpcha.
151
+ - `website_url`: the URL of the page with the hCaptcha challenge.
152
+ - `proxy_type`: optional parameter. Proxy connection protocol.
153
+ - `proxy_address`: optional parameter. The proxy address.
154
+ - `proxy_port`: optional parameter. The proxy port.
155
+ - `proxy_login`: optional parameter. The proxy login.
156
+ - `proxy_password`: optional parameter. The proxy password.
157
+ - `user_agent`: optional parameter. The user agent.
110
158
 
111
- The solution (`solution.g_recaptcha_response`) will be a code that validates
112
- the form, like the following:
159
+ #### FunCaptcha
113
160
 
114
- ```ruby
115
- "1JJHJ_VuuHAqJKxcaasbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcwkjsRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdkjsakFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZasDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05ajkPGt20qzpURMwHaw"
116
- ```
161
+ ```ruby
162
+ solution = client.decode_fun_captcha!(
163
+ website_public_key: 'xyz',
164
+ website_url: 'http://example.com/example=1',
165
+ # proxy_type: 'http', # OPTIONAL
166
+ # proxy_address: '127.0.0.1', # OPTIONAL
167
+ # proxy_port: '8080', # OPTIONAL
168
+ # proxy_login: 'proxyLoginHere', # OPTIONAL
169
+ # proxy_password: 'proxyPasswordHere', # OPTIONAL
170
+ # user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
171
+ )
172
+
173
+ solution.token
174
+ "380633616d817f2b8.2351188603|r=ap-southeast-2|met..."
175
+ ```
117
176
 
118
- 7. **FunCaptcha**
177
+ *Parameters:*
119
178
 
120
- This method allows you to solve FunCaptcha.
179
+ - `website_key`: the site key for the hCatpcha.
180
+ - `website_url`: the URL of the page with the hCaptcha challenge.
181
+ - `proxy_type`: optional parameter. Proxy connection protocol.
182
+ - `proxy_address`: optional parameter. The proxy address.
183
+ - `proxy_port`: optional parameter. The proxy port.
184
+ - `proxy_login`: optional parameter. The proxy login.
185
+ - `proxy_password`: optional parameter. The proxy password.
186
+ - `user_agent`: optional parameter. The user agent.
121
187
 
122
- **Send the `website_public_key` and `website_url` parameters**
188
+ #### Geetest
123
189
 
124
- This method requires no browser emulation. You can send two parameters that
125
- identify the website in which the CAPTCHA is found.
190
+ ```ruby
191
+ solution = client.decode_geetest!(
192
+ website_url: 'http://mywebsite.com/geetest/test.php',
193
+ gt: '874703612e5cac182812a00e273aad0d',
194
+ challenge: 'a559b82bca2c500101a1c8a4f4204742',
195
+ # proxy_type: 'http', # OPTIONAL
196
+ # proxy_address: '127.0.0.1', # OPTIONAL
197
+ # proxy_port: '8080', # OPTIONAL
198
+ # proxy_login: 'proxyLoginHere', # OPTIONAL
199
+ # proxy_password: 'proxyPasswordHere', # OPTIONAL
200
+ # user_agent: 'MODERN_USER_AGENT_HERE', # OPTIONAL
201
+ )
126
202
 
127
- ```ruby
128
- options = {
129
- website_public_key: 'xyz',
130
- website_url: 'http://example.com/example=1',
131
- language_pool: '...'
132
- }
203
+ solution.v3['challenge']
204
+ "3c1c5153aa48011e92883aed820069f3hj"
133
205
 
134
- solution = client.decode_fun_captcha(options)
135
- solution.token # Solution of the captcha
136
- ```
206
+ solution.v3['validate']
207
+ "47ad5a0a6eb98a95b2bcd9e9eecc8272"
137
208
 
138
- 8. **reCAPTCHA V3**
209
+ solution.v3['seccode']
210
+ "83fa4f2d23005fc91c3a015a1613f803|jordan"
139
211
 
140
- This method allows you to solve [reCAPTCHA v3](https://developers.google.com/recaptcha/docs/v3).
212
+ # Or
141
213
 
142
- There are two methods available:
214
+ solution.v4['captcha_id']
215
+ "fcd636b4514bf7ac4143922550b3008b"
143
216
 
144
- - `decode_recaptcha_v3`: solves reCAPTCHA v3. It doesn't raise exceptions.
145
- - `decode_recaptcha_v3!`: solves reCAPTCHA v3. It may raise an `AntiCaptcha::Error` if something goes wrong.
217
+ solution.v4['lot_number']
218
+ "354ab6dd4e594fdc903074c4d8d37b24"
146
219
 
147
- **Send the `website_key`, `website_url`, `min_score` and `page_action` parameters**
220
+ solution.v4['pass_token']
221
+ "b645946a654e60218c7922b74b3b5ee8e8717e8fd3cd51..."
148
222
 
149
- This method requires no browser emulation. You can send four parameters that
150
- identify the website in which the CAPTCHA is found and the minimum score (0.3, 0.5 or 0.7) you
151
- desire.
223
+ solution.v4['gen_time']
224
+ "1649921519"
152
225
 
153
- **It's strongly recommended to use a minimum score of 0.3 as higher scores are extremely rare.**
226
+ solution.v4['captcha_output']
227
+ "cFPIALDXSop8Ri2mPABbRWzNBs86N8D4vNUTuVa7wN7E..."
228
+ ```
229
+ *Parameters:*
230
+
231
+ - `website_url`: URL of a target web page. It can be located anywhere on the web site, even in a member's area.
232
+ - `gt`: the domain's public key.
233
+ - `challenge`: changing token key. Make sure you grab a fresh one for each captcha.
234
+ - `geetest_api_server_subdomain`: optional parameter. API subdomain. May be required for some implementations.
235
+ - `geetest_get_lib`: optional parameter. Required for some implementations. Send the JSON encoded into a string. The value can be traced in the browser's developer tools. Put a breakpoint before calling the "initGeetest" function.
236
+ - `version`: optional parameter. Version number. Default version is 3. Supported versions: 3 and 4.
237
+ - `init_parameters`: optional parameter. Additional initialization parameters for version 4.
238
+ - `proxy_type`: optional parameter. Proxy connection protocol.
239
+ - `proxy_address`: optional parameter. The proxy address.
240
+ - `proxy_port`: optional parameter. The proxy port.
241
+ - `proxy_login`: optional parameter. The proxy login.
242
+ - `proxy_password`: optional parameter. The proxy password.
243
+ - `user_agent`: optional parameter. The user agent.
244
+
245
+ ### 3. Report an incorrectly solved image CAPTCHA for a refund
246
+
247
+ It is only possible to report incorrectly solved image CAPTCHAs.
154
248
 
155
- ```ruby
156
- options = {
157
- website_key: 'xyz',
158
- website_url: 'http://example.com/example=1',
159
- min_score: 0.3,
160
- page_action: 'myverify'
161
- }
249
+ ```ruby
250
+ client.report_incorrect_image_catpcha!(task_id)
251
+ ```
162
252
 
163
- solution = client.decode_recaptcha_v3!(options)
164
- solution.g_recaptcha_response # Solution of the captcha
165
- ```
253
+ ### 4. Get your account balance
166
254
 
167
- The solution (`solution.g_recaptcha_response`) will be a code that validates
168
- the form, like the following:
255
+ ```ruby
256
+ client.get_balance!
257
+ ```
169
258
 
170
- ```ruby
171
- "1JJHJ_VuuHAqJKxcaasbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcwkjsRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdkjsakFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZasDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05ajkPGt20qzpURMwHaw"
172
- ```
259
+ ### 5. Get current stats of a queue.
260
+
261
+ Queue IDs:
262
+
263
+ - `1` Standart ImageToText, English language
264
+ - `2` Standart ImageToText, Russian language
265
+ - `5` Recaptcha NoCaptcha tasks
266
+ - `6` Recaptcha Proxyless task
267
+ - `7` Funcaptcha task
268
+ - `10` Funcaptcha Proxyless task
269
+ - `12` GeeTest with proxy
270
+ - `13` GeeTest without proxy
271
+ - `18` Recaptcha V3 s0.3
272
+ - `19` Recaptcha V3 s0.7
273
+ - `20` Recaptcha V3 s0.9
274
+ - `21` hCaptcha with proxy
275
+ - `22` hCaptcha without proxy
276
+ - `23` Recaptcha Enterprise V2 with proxy
277
+ - `24` Recaptcha Enterprise V2 without proxy
278
+ - `25` AntiGateTask
173
279
 
280
+ ```ruby
281
+ client.get_queue_stats!(queue_id)
282
+ ```
174
283
 
175
284
  ## Notes
176
285
 
177
- #### Ruby dependencies
286
+ ### Ruby dependencies
178
287
 
179
288
  AntiCaptcha doesn't require specific dependencies. That saves you memory and
180
289
  avoid conflicts with other gems.
181
290
 
182
- #### Input image format
291
+ ### Input image format
183
292
 
184
- Any format you use in the decode method (file, path, body, body64) will always
185
- be converted to a body64, which is a binary base64 encoded string. So, if you
186
- already have this format available on your side, there's no need to do
187
- convertions before calling the API.
293
+ Any format you use in the `decode_image!` method (`file`, `path`, `body`, `body64`)
294
+ will always be converted to a `body64`, which is a base64-encoded binary string.
295
+ So, if you already have this format on your end, there is no need for convertions
296
+ before calling the API.
188
297
 
189
298
  > Our recomendation is to never convert your image format, unless needed. Let
190
299
  > the gem convert internally. It may save you resources (CPU, memory and IO).
191
300
 
192
- #### Versioning
301
+ ### Versioning
193
302
 
194
303
  AntiCaptcha gem uses [Semantic Versioning](http://semver.org/).
195
304
 
196
305
  # License
197
306
 
198
- MIT License. Copyright (C) 2011-2015 Infosimples. https://infosimples.com/
307
+ MIT License. Copyright (C) 2011-2022 Infosimples. https://infosimples.com/
data/anti_captcha.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "bundler", ">= 2.2.33"
25
25
  spec.add_development_dependency "rake", "~> 12.3.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  end
@@ -4,8 +4,7 @@ module AntiCaptcha
4
4
  #
5
5
  class Client
6
6
  BASE_URL = 'https://api.anti-captcha.com/:action'
7
- PROXYABLE_TASKS = %w(NoCaptchaTask FunCaptchaTask)
8
- SUPPORTED_TASKS = %w(ImageToTextTask NoCaptchaTask FunCaptchaTask)
7
+ PROXYABLE_TASKS = %w(RecaptchaV2Task FunCaptchaTask HCaptchaTask GeeTestTask)
9
8
 
10
9
  attr_accessor :client_key, :timeout, :polling
11
10
 
@@ -14,7 +13,7 @@ module AntiCaptcha
14
13
  #
15
14
  # @param [String] client_key The key of the Anti Captcha account.
16
15
  # @param [Hash] options Options hash.
17
- # @option options [Integer] :timeout (60) Seconds before giving up of a
16
+ # @option options [Integer] :timeout (120) Seconds before giving up of a
18
17
  # captcha being solved.
19
18
  # @option options [Integer] :polling (5) Seconds before checking answer
20
19
  # again.
@@ -23,7 +22,7 @@ module AntiCaptcha
23
22
  #
24
23
  def initialize(client_key, options = {})
25
24
  self.client_key = client_key
26
- self.timeout = options[:timeout] || 60
25
+ self.timeout = options[:timeout] || 120
27
26
  self.polling = options[:polling] || 5
28
27
  end
29
28
 
@@ -75,18 +74,19 @@ module AntiCaptcha
75
74
  end
76
75
 
77
76
  #
78
- # Decodes a NoCaptcha CAPTCHA.
77
+ # Decodes a reCAPTCHA v2 (NoCaptcha).
79
78
  #
80
- # @see `AntiCaptcha::Client#decode_nocaptcha!`
79
+ # @see `AntiCaptcha::Client#decode_recaptcha_v2!`
81
80
  #
82
- def decode_nocaptcha(options, proxy = nil)
83
- decode_nocaptcha!(options, proxy)
81
+ def decode_recaptcha_v2(options, proxy = nil)
82
+ decode_recaptcha_v2!(options, proxy)
84
83
  rescue
85
- AntiCaptcha::NoCaptchaSolution.new
84
+ AntiCaptcha::RecaptchaV2Solution.new
86
85
  end
86
+ alias :decode_nocaptcha :decode_recaptcha_v2
87
87
 
88
88
  #
89
- # Decodes a NoCaptcha CAPTCHA.
89
+ # Decodes a reCAPTCHA v2 (NoCaptcha).
90
90
  #
91
91
  # @param [Hash] options Options hash.
92
92
  # @option options [String] :website_url
@@ -103,16 +103,17 @@ module AntiCaptcha
103
103
  # @option proxy [String] :proxy_password
104
104
  # @option proxy [String] :user_agent
105
105
  #
106
- # @return [AntiCaptcha::NoCaptchaSolution] The solution of the NoCaptcha.
106
+ # @return [AntiCaptcha::RecaptchaV2Solution] The solution of the reCAPTCHA v2.
107
107
  #
108
- def decode_nocaptcha!(options, proxy = nil)
109
- task = create_task!('NoCaptchaTask', options, proxy)
108
+ def decode_recaptcha_v2!(options, proxy = nil)
109
+ task = create_task!('RecaptchaV2Task', options, proxy)
110
110
  task_result = get_task_result!(task['taskId'])
111
- AntiCaptcha::NoCaptchaSolution.new(task_result)
111
+ AntiCaptcha::RecaptchaV2Solution.new(task_result)
112
112
  end
113
+ alias :decode_nocaptcha! :decode_recaptcha_v2!
113
114
 
114
115
  #
115
- # Decodes a reCAPTCHA V3.
116
+ # Decodes a reCAPTCHA v3.
116
117
  #
117
118
  # @see `AntiCaptcha::Client#decode_recaptcha_v3!`
118
119
  #
@@ -123,17 +124,18 @@ module AntiCaptcha
123
124
  end
124
125
 
125
126
  #
126
- # Decodes a reCAPTCHA V3. Proxy is not supported.
127
+ # Decodes a reCAPTCHA v3. Proxy is not supported.
127
128
  #
128
129
  # @param [Hash] options Options hash.
129
130
  # @option options [String] :website_url
130
131
  # @option options [String] :website_key
131
132
  # @option options [String] :min_score (one of 0.3, 0,5 or 0.7)
132
133
  # @option options [String] :page_action
134
+ # @option options [String] :is_enterprise
133
135
  # @option options [String] :language_pool
134
136
  #
135
137
  # @return [AntiCaptcha::RecaptchaV3Solution] The solution of
136
- # the reCAPTCHA V3.
138
+ # the reCAPTCHA v3.
137
139
  #
138
140
  def decode_recaptcha_v3!(options)
139
141
  task = create_task!('RecaptchaV3TaskProxyless', options)
@@ -167,6 +169,83 @@ module AntiCaptcha
167
169
  AntiCaptcha::FunCaptchaSolution.new(task_result)
168
170
  end
169
171
 
172
+ #
173
+ # Decodes a HCaptcha CAPTCHA.
174
+ #
175
+ # @see `AntiCaptcha::Client#decode_h_captcha!`
176
+ #
177
+ def decode_h_captcha(options, proxy = nil)
178
+ decode_h_captcha!(options, proxy)
179
+ rescue
180
+ AntiCaptcha::HCaptchaSolution.new
181
+ end
182
+
183
+ #
184
+ # Decodes a HCaptcha CAPTCHA.
185
+ #
186
+ # @param [Hash] options Options hash.
187
+ # @option options [String] :website_url
188
+ # @option options [String] :website_key
189
+ #
190
+ # @param [Hash] proxy Not mandatory. A hash with configs of the proxy that
191
+ # has to be used. Defaults to `nil`.
192
+ # @option proxy [String] :proxy_type
193
+ # @option proxy [String] :proxy_address
194
+ # @option proxy [String] :proxy_port
195
+ # @option proxy [String] :proxy_login
196
+ # @option proxy [String] :proxy_login
197
+ # @option proxy [String] :proxy_password
198
+ # @option proxy [String] :user_agent
199
+ #
200
+ # @return [AntiCaptcha::HCaptchaSolution] The solution of the HCaptcha.
201
+ #
202
+ def decode_h_captcha!(options, proxy = nil)
203
+ task = create_task!('HCaptchaTask', options, proxy)
204
+ task_result = get_task_result!(task['taskId'])
205
+ AntiCaptcha::HCaptchaSolution.new(task_result)
206
+ end
207
+
208
+ #
209
+ # Decodes a Geetest CAPTCHA.
210
+ #
211
+ # @see `AntiCaptcha::Client#decode_geetest!`
212
+ #
213
+ def decode_geetest(options, proxy = nil)
214
+ decode_geetest!(options, proxy)
215
+ rescue
216
+ AntiCaptcha::GeetestSolution.new
217
+ end
218
+
219
+ #
220
+ # Decodes a Geetest CAPTCHA.
221
+ #
222
+ # @param [Hash] options Options hash.
223
+ # @option options [String] :website_url
224
+ # @option options [String] :gt
225
+ # @option options [String] :challenge
226
+ # @option options [String] :geetest_api_server_subdomain
227
+ # @option options [String] :geetest_get_lib
228
+ # @option options [String] :version
229
+ # @option options [String] :init_parameters
230
+ #
231
+ # @param [Hash] proxy Not mandatory. A hash with configs of the proxy that
232
+ # has to be used. Defaults to `nil`.
233
+ # @option proxy [String] :proxy_type
234
+ # @option proxy [String] :proxy_address
235
+ # @option proxy [String] :proxy_port
236
+ # @option proxy [String] :proxy_login
237
+ # @option proxy [String] :proxy_login
238
+ # @option proxy [String] :proxy_password
239
+ # @option proxy [String] :user_agent
240
+ #
241
+ # @return [AntiCaptcha::GeetestSolution] The solution of the Geetest.
242
+ #
243
+ def decode_geetest!(options, proxy = nil)
244
+ task = create_task!('GeeTestTask', options, proxy)
245
+ task_result = get_task_result!(task['taskId'])
246
+ AntiCaptcha::GeetestSolution.new(task_result)
247
+ end
248
+
170
249
  # Creates a task for solving the selected CAPTCHA type.
171
250
  #
172
251
  # @param [String] type The type of the CAPTCHA.
@@ -226,9 +305,9 @@ module AntiCaptcha
226
305
  comment: options[:comment],
227
306
  }
228
307
 
229
- when 'NoCaptchaTask'
308
+ when 'RecaptchaV2Task'
230
309
  args[:task] = {
231
- type: 'NoCaptchaTask',
310
+ type: 'RecaptchaV2Task',
232
311
  websiteURL: options[:website_url],
233
312
  websiteKey: options[:website_key],
234
313
  }
@@ -236,11 +315,13 @@ module AntiCaptcha
236
315
  when 'RecaptchaV3TaskProxyless'
237
316
  args[:task] = {
238
317
  type: 'RecaptchaV3TaskProxyless',
239
- websiteURL: options[:website_url],
240
- websiteKey: options[:website_key],
241
- minScore: options[:min_score].to_f,
242
- pageAction: options[:page_action],
318
+ websiteURL: options[:website_url],
319
+ websiteKey: options[:website_key],
320
+ minScore: (options[:min_score] || 0.3).to_f,
321
+ pageAction: options[:page_action],
243
322
  }
323
+ args[:isEnterprise] = options[:is_enterprise] if [true, false].include?(options[:is_enterprise])
324
+
244
325
 
245
326
  when 'FunCaptchaTask'
246
327
  args[:task] = {
@@ -249,10 +330,28 @@ module AntiCaptcha
249
330
  websitePublicKey: options[:website_public_key],
250
331
  }
251
332
 
333
+ when 'HCaptchaTask'
334
+ args[:task] = {
335
+ type: 'HCaptchaTask',
336
+ websiteURL: options[:website_url],
337
+ websiteKey: options[:website_key],
338
+ }
339
+
340
+ when 'GeeTestTask'
341
+ args[:task] = {
342
+ type: 'GeeTestTask',
343
+ websiteURL: options[:website_url],
344
+ gt: options[:gt],
345
+ challenge: options[:challenge],
346
+ }
347
+ args[:geetestApiServerSubdomain] = options[:geetest_api_server_subdomain] if !options[:geetest_api_server_subdomain].nil?
348
+ args[:geetestGetLib] = options[:geetest_get_lib] if !options[:geetest_get_lib].nil?
349
+ args[:version] = options[:version] if !options[:version].nil?
350
+ args[:initParameters] = options[:init_parameters] if !options[:init_parameters].nil?
351
+
252
352
  else
253
- message = "Invalid task type: '#{type}'. Allowed types: " +
254
- "#{SUPPORTED_TASKS.join(', ')}"
255
- raise AntiCaptcha.raise_error(message)
353
+ message = "Invalid task type: '#{type}'."
354
+ raise AntiCaptcha::ArgumentError.new(message)
256
355
  end
257
356
 
258
357
  if PROXYABLE_TASKS.include?(type)
@@ -281,7 +380,7 @@ module AntiCaptcha
281
380
  # @return [Hash] Information about the task.
282
381
  #
283
382
  def get_task_result!(task_id)
284
- raise AntiCaptcha.raise_error('taskId not received from Anti Captcha.') unless task_id
383
+ raise AntiCaptcha::Error.new('taskId not received from Anti Captcha.') unless task_id
285
384
 
286
385
  started_at = Time.now
287
386
 
@@ -317,6 +416,11 @@ module AntiCaptcha
317
416
  # 6 - Recaptcha Proxyless task.
318
417
  # 7 - Funcaptcha task.
319
418
  # 10 - Funcaptcha Proxyless task.
419
+ # 18 - Recaptcha V3 s0.3
420
+ # 19 - Recaptcha V3 s0.7
421
+ # 20 - Recaptcha V3 s0.9
422
+ # 21 - hCaptcha Proxy-On
423
+ # 22 - hCaptcha Proxyless
320
424
  #
321
425
  # @return [Hash] Information about the queue.
322
426
  #
@@ -0,0 +1,30 @@
1
+ module AntiCaptcha
2
+ class GeetestSolution < AntiCaptcha::Solution
3
+ attr_accessor :v3, :v4
4
+
5
+ def initialize(task_result = nil)
6
+ super
7
+
8
+ if task_result
9
+ solution = task_result.api_result['solution']
10
+
11
+ if solution['pass_token']
12
+ @v4 = {
13
+ 'captcha_id' => solution['captcha_id'],
14
+ 'lot_number' => solution['lot_number'],
15
+ 'pass_token' => solution['pass_token'],
16
+ 'gen_time' => solution['gen_time'],
17
+ 'captcha_output' => solution['captcha_output'],
18
+ }
19
+
20
+ else
21
+ @v3 = {
22
+ 'challenge' => solution['challenge'],
23
+ 'validate' => solution['validate'],
24
+ 'seccode' => solution['seccode'],
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module AntiCaptcha
2
+ class HCaptchaSolution < AntiCaptcha::Solution
3
+ attr_accessor :g_recaptcha_response # Deprecated
4
+ attr_accessor :token
5
+
6
+
7
+ def initialize(task_result = nil)
8
+ super
9
+
10
+ if task_result
11
+ @token = task_result.api_result['solution']['gRecaptchaResponse']
12
+ @g_recaptcha_response = token
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module AntiCaptcha
2
- class NoCaptchaSolution < AntiCaptcha::Solution
2
+ class RecaptchaV2Solution < AntiCaptcha::Solution
3
3
  attr_accessor :g_recaptcha_response, :g_recaptcha_response_md5
4
4
 
5
5
  def initialize(task_result = nil)
@@ -1,7 +1,7 @@
1
1
  module AntiCaptcha
2
2
  class TaskResult < AntiCaptcha::Model
3
3
  attr_accessor :task_id, :error_id, :error_code, :error_description, :status,
4
- :cost, :ip, :create_time, :end_time, :solve_count, :api_result
4
+ :cost, :ip, :create_time, :end_time, :solve_count, :api_result
5
5
 
6
6
  def initialize(api_result, task_id)
7
7
  @task_id = task_id
@@ -1,4 +1,4 @@
1
1
  module AntiCaptcha
2
- VERSION = "2.2.2"
2
+ VERSION = "2.4.0"
3
3
  USER_AGENT = "AntiCaptcha/Ruby v#{VERSION}"
4
4
  end
data/lib/anti_captcha.rb CHANGED
@@ -33,9 +33,11 @@ require 'anti_captcha/http'
33
33
  require 'anti_captcha/errors'
34
34
  require 'anti_captcha/models/solution'
35
35
  require 'anti_captcha/models/image_to_text_solution'
36
- require 'anti_captcha/models/no_captcha_solution'
36
+ require 'anti_captcha/models/recaptcha_v2_solution'
37
37
  require 'anti_captcha/models/recaptcha_v3_solution'
38
38
  require 'anti_captcha/models/fun_captcha_solution'
39
+ require 'anti_captcha/models/h_captcha_solution'
40
+ require 'anti_captcha/models/geetest_solution'
39
41
  require 'anti_captcha/models/task_result'
40
42
  require 'anti_captcha/client'
41
43
  require 'anti_captcha/version'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anti_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infosimples
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2022-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: 2.2.33
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: 2.2.33
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,8 +75,10 @@ files:
75
75
  - lib/anti_captcha/errors.rb
76
76
  - lib/anti_captcha/http.rb
77
77
  - lib/anti_captcha/models/fun_captcha_solution.rb
78
+ - lib/anti_captcha/models/geetest_solution.rb
79
+ - lib/anti_captcha/models/h_captcha_solution.rb
78
80
  - lib/anti_captcha/models/image_to_text_solution.rb
79
- - lib/anti_captcha/models/no_captcha_solution.rb
81
+ - lib/anti_captcha/models/recaptcha_v2_solution.rb
80
82
  - lib/anti_captcha/models/recaptcha_v3_solution.rb
81
83
  - lib/anti_captcha/models/solution.rb
82
84
  - lib/anti_captcha/models/task_result.rb
@@ -85,7 +87,7 @@ homepage: https://github.com/infosimples/anti_captcha
85
87
  licenses:
86
88
  - MIT
87
89
  metadata: {}
88
- post_install_message:
90
+ post_install_message:
89
91
  rdoc_options: []
90
92
  require_paths:
91
93
  - lib
@@ -100,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  requirements: []
103
- rubygems_version: 3.0.6
104
- signing_key:
105
+ rubygems_version: 3.1.4
106
+ signing_key:
105
107
  specification_version: 4
106
108
  summary: Ruby API for Anti Captcha (CAPTCHA Solver as a Service)
107
109
  test_files: []