two_captcha 1.7.0 → 1.8.0

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: 9d9f28e64ed32b2c3bb8973f14bea2dbb15828550806d0306e6bdbdf07815562
4
- data.tar.gz: eaa46657370a298929c7e5f49104abb3f696a74cddeddb8f1052a1f3c2140b8d
3
+ metadata.gz: c6657c4e05fd2c0a00072c9070954b73b1a5573ab9a6896301b2836098aeea66
4
+ data.tar.gz: ea035f063342b484e83272b2a75838fa4ce1b4b02b2c25a3a49e53b666ecb0d4
5
5
  SHA512:
6
- metadata.gz: cc567f2ecf5c0771e1b1ca7cade9c44a33abe2a224256132d2d8326798b998f5b8750fdbb489995c320a705f68ed7d9bb685450c87174c71389d987eb06258a0
7
- data.tar.gz: dac73380663bc6471b233db9b30a6d2be296b27fa92131a3beaf54f7a155d503658c7ad53accf1e500eb50704413bd9af931793f6ccc200251dce157f5dbe1f3
6
+ metadata.gz: ab1e833fbf80a57058f7e78a4b6399473fd56606247c34081212cbd9205ba7f9d6ab6a091a415a9db48d7b55ffe736ec2267c48a76adfa02764d3a4373c5d6f5
7
+ data.tar.gz: 525b2cd2321e4e2ac9f35ec56a5f05c3ebc0d95ab7d0564e7c31d0c0a38f9a656e6fb7536224452174d3be10c33d5922d2b4d099e76ee78a678f22a1dfb5d6b1
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- Developed by [Infosimples](https://infosimples.com).
2
-
3
1
  # TwoCaptcha
4
2
 
5
- TwoCaptcha is a Ruby API for 2Captcha - [2Captcha.com](http://2captcha.com/?from=1025109).
3
+ TwoCaptcha is a Ruby API for 2Captcha - [2Captcha.com](http://2captcha.com/?from=1025109)
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,264 +15,197 @@ gem 'two_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 two_captcha
24
+ ```bash
25
+ $ gem install two_captcha
26
+ ````
22
27
 
23
28
  ## Usage
24
29
 
25
- 1. **Create a client**
26
-
27
- ```ruby
28
- # Create a client
29
- client = TwoCaptcha.new('my_captcha_key')
30
- ```
31
-
32
- 2. **Solve a captcha**
33
-
34
- There are two methods available: **decode** and **decode!**
35
- * **decode** doesn't raise exceptions.
36
- * **decode!** may raise a *TwoCaptcha::Error* if something goes wrong.
37
-
38
- If the solution is not available, an empty captcha object will be returned.
39
-
40
- ```ruby
41
- captcha = client.decode!(url: 'http://bit.ly/1xXZcKo')
42
- captcha.text # Solution of the captcha
43
- captcha.id # Numeric ID of the captcha solved by TwoCaptcha
44
- ```
45
-
46
- You can also specify *path*, *file*, *raw* and *raw64* when decoding an image.
47
-
48
- ```ruby
49
- client.decode(path: 'path/to/my/captcha/file')
50
-
51
- client.decode(file: File.open('path/to/my/captcha/file', 'rb'))
52
-
53
- client.decode(raw: File.open('path/to/my/captcha/file', 'rb').read)
54
-
55
- client.decode(raw64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
56
- ```
57
-
58
- > Internally, the gem will always convert the image to raw64 (binary base64 encoded).
59
-
60
- You may also specify any POST parameters specified at
61
- https://2captcha.com/setting.
62
-
63
- 3. **Retrieve a previously solved captcha**
64
-
65
- ```ruby
66
- captcha = client.captcha('130920620') # with 130920620 as the captcha id
67
- ```
68
-
69
- 4. **Report incorrectly (for refund) or correctly (useful for reCAPTCHA v3) solved captcha**
30
+ ### 1. Create a client
70
31
 
71
- ```ruby
72
- client.report!('130920620', 'reportbad') # with 130920620 as the captcha id
73
- # return true if successfully reported
74
-
75
- client.report!('256892751', 'reportgood') # with 256892751 as the captcha id
76
- # return true if successfully reported
77
- ```
78
-
79
- > ***Warning:*** *do not abuse on this method, otherwise you may get banned*
80
-
81
- 5. **Get your balance on 2Captcha**
82
-
83
- ```ruby
84
- client.balance
85
- # return a Float balance in USD.
86
- ```
32
+ ```ruby
33
+ client = TwoCaptcha.new('my_key')
34
+ ```
87
35
 
88
- 6. **Get usage statistics for a specific date**
36
+ ### 2. Solve a CAPTCHA
89
37
 
90
- ```ruby
91
- client.stats('2015-08-05')
92
- # return an XML string with your usage statistics.
93
- ```
38
+ There are two types of methods available: `decode` and `decode!`:
94
39
 
95
- 7. **Get current 2Captcha load**
40
+ - `decode` does not raise exceptions.
41
+ - `decode!` may raise a `TwoCaptcha::Error` if something goes wrong.
96
42
 
97
- ```ruby
98
- client.load
99
- # return an XML string with the current service load.
100
- ```
43
+ If the solution is not available, an empty solution object will be returned.
101
44
 
102
- ## reCAPTCHA v2 (e.g. "No CAPTCHA reCAPTCHA")
45
+ ```ruby
46
+ captcha = client.decode_image!(url: 'http://bit.ly/1xXZcKo')
47
+ captcha.text # CAPTCHA solution
48
+ captcha.id # CAPTCHA numeric id
49
+ ```
103
50
 
104
- There are two ways of solving captchas similar to
105
- [reCAPTCHA v2](https://support.google.com/recaptcha/?hl=en#6262736).
51
+ #### Image CAPTCHA
106
52
 
107
- ### (Prefered) Sending the `googlekey` and `pageurl` parameters
53
+ You can specify `file`, `path`, `raw`, `raw64` and `url` when decoding an image.
108
54
 
109
- This method requires no browser emulation. You can send two parameters that
110
- identify the website in which the captcha is found.
55
+ ```ruby
56
+ client.decode_image!(file: File.open('path/to/my/captcha/file', 'rb'))
57
+ client.decode_image!(path: 'path/to/my/captcha/file')
58
+ client.decode_image!(raw: File.open('path/to/my/captcha/file', 'rb').read)
59
+ client.decode_image!(raw64: Base64.encode64(File.open('path/to/my/captcha/file', 'rb').read))
60
+ client.decode_image!(url: 'http://bit.ly/1xXZcKo')
61
+ ```
111
62
 
112
- Please read the [oficial documentation](https://2captcha.com/newapi-recaptcha-en)
113
- for more information.
63
+ You may also specify any POST parameters specified at https://2captcha.com/setting.
114
64
 
115
- ```ruby
116
- options = {
117
- googlekey: 'xyz',
118
- pageurl: 'http://example.com/example=1'
119
- }
65
+ #### reCAPTCHA v2
120
66
 
121
- captcha = client.decode_recaptcha_v2(options)
122
- captcha.text # Solution of the captcha
123
- captcha.id # Numeric ID of the captcha solved by TwoCaptcha
124
- ```
67
+ ```ruby
68
+ captcha = client.decode_recaptcha_v2!(
69
+ googlekey: 'xyz',
70
+ pageurl: 'http://example.com/example=1',
71
+ )
125
72
 
126
- The solution (`captcha.text`) will be a code that validates the form, like the
127
- following:
73
+ # The response will be a text (token), which you can access with the `text` method.
128
74
 
129
- ```ruby
130
- "1JJHJ_VuuHAqJKxcaasbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcwkjsRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdkjsakFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZasDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05ajkPGt20qzpURMwHaw"
131
- ```
75
+ captcha.text
76
+ "03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
77
+ ```
132
78
 
133
- ### Sending the challenge image
79
+ *Parameters:*
134
80
 
135
- You can add the param `coordinatescaptcha: 1` to your request.
81
+ - `googlekey`: the Google key for the reCAPTCHA.
82
+ - `pageurl`: the URL of the page with the reCAPTCHA challenge.
136
83
 
137
- Please read the oficial documentation at https://2captcha.com/en-api-recaptcha for
138
- more information.
139
84
 
140
- ```ruby
141
- client.decode(url: 'http://bit.ly/clickcaptcha', coordinatescaptcha: 1)
142
- ```
85
+ #### reCAPTCHA v3
143
86
 
144
- **Captcha (screenshot)**
87
+ ```ruby
88
+ captcha = client.decode_recaptcha_v3!(
89
+ googlekey: 'xyz',
90
+ pageurl: 'http://example.com/example=1',
91
+ action: 'verify',
92
+ min_score: 0.3, # OPTIONAL
93
+ )
145
94
 
146
- > the argument is passed as *url*, *path*, *file*, *raw* or *raw64*
95
+ # The response will be a text (token), which you can access with the `text` method.
147
96
 
148
- ![Example of a captcha based on image clicks](captchas/2.jpg)
97
+ captcha.text
98
+ "03AOPBWq_RPO2vLzyk0h8gH0cA2X4v3tpYCPZR6Y4yxKy1s3Eo7CHZRQntxrd..."
99
+ ```
149
100
 
150
- The response will be an array containing coordinates where the captcha should be
151
- clicked. For the captcha above it should look something like:
101
+ *Parameters:*
152
102
 
153
- ```ruby
154
- # captcha.text
155
- "coordinates:x=50.66999816894531,y=130.3300018310547;x=236.66998291015625,y=328.3299865722656"
156
- ```
103
+ - `googlekey`: the Google key for the reCAPTCHA.
104
+ - `pageurl`: the URL of the page with the reCAPTCHA challenge.
105
+ - `action`: the action name used by the CAPTCHA.
106
+ - `min_score`: optional parameter. The minimal score needed for the CAPTCHA resolution. Defaults to `0.3`.
157
107
 
158
- ## Audio reCAPTCHA v2
108
+ > About the `action` parameter: in order to find out what this is, you need to inspect the JavaScript
109
+ > code of the website looking for a call to the `grecaptcha.execute` function.
110
+ >
111
+ > ```javascript
112
+ > // Example
113
+ > grecaptcha.execute('6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f', { action: "examples/v3scores" })
114
+ > ````
159
115
 
160
- ```ruby
161
- client.decode(url: 'http://bit.ly/audiorecaptchav2', recaptchavoice: 1)
162
- ```
116
+ > About the `min_score` parameter: it's strongly recommended to use a minimum score of `0.3` as higher
117
+ > scores are rare.
163
118
 
164
- The response will be a simple text:
119
+ #### hCaptcha
165
120
 
166
121
  ```ruby
167
- # captcha.text
168
- '61267'
122
+ captcha = client.decode_hcaptcha!(
123
+ sitekey: 'xyz',
124
+ pageurl: 'http://example.com/example=1',
125
+ )
126
+
127
+ captcha.text
128
+ "P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNza2V5IjoiNnpWV..."
169
129
  ```
170
130
 
171
- ## reCAPTCHA v3
131
+ *Parameters:*
172
132
 
173
- This method requires no browser emulation. You can send four parameters that
174
- identify the website in which the CAPTCHA is found and the minimum score
175
- (0.3, 0.5 or 0.7) you desire.
133
+ - `website_key`: the site key for the hCatpcha.
134
+ - `website_url`: the URL of the page with the hCaptcha challenge.
176
135
 
177
- **It's strongly recommended to use a minimum score of 0.3 as higher scores are extremely rare.**
136
+ ### 3. Using proxy or other custom options
178
137
 
179
- Please read the [oficial documentation](https://2captcha.com/2captcha-api#solving_recaptchav3)
180
- for more information.
138
+ You are allowed to use custom options like `proxy`, `proxytype` or `userAgent` whenever the
139
+ 2Captcha API supports it. Example:
181
140
 
182
141
  ```ruby
183
142
  options = {
184
- googlekey: 'xyz',
143
+ sitekey: 'xyz',
185
144
  pageurl: 'http://example.com/example=1',
186
- action: 'verify',
187
- min_score: 0.3
145
+ proxy: 'login:password@123.123.123.123:3128',
146
+ userAgent: 'user agent',
188
147
  }
189
148
 
190
- captcha = client.decode_recaptcha_v3(options)
191
- captcha.text # Solution of the captcha
192
- captcha.id # Numeric ID of the captcha solved by TwoCaptcha
193
- ```
194
-
195
- The solution (`captcha.text`) will be a code that validates the form, like the
196
- following:
197
-
198
- ```ruby
199
- "1JJHJ_VuuHAqJKxcaasbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcwkjsRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdkjsakFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZasDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05ajkPGt20qzpURMwHaw"
149
+ captcha = client.decode_hcaptcha!(options)
200
150
  ```
201
151
 
202
- ## hCaptcha
203
-
204
- This method allows you to solve hCaptcha.
152
+ ### 4. Retrieve a previously solved CAPTCHA
205
153
 
206
- There are two methods available:
207
-
208
- - `decode_hcaptcha`: solves hCaptcha CAPTCHAs. It doesn't raise exceptions.
209
- - `decode_hcaptcha!`: solves hCaptcha CAPTCHAs. It may raise an error if something goes wrong.
210
-
211
- **Send the `sitekey` and `pageurl` parameters**
154
+ ```ruby
155
+ captcha = client.captcha('130920620') # with 130920620 being the CAPTCHA id
156
+ ```
212
157
 
213
- This method requires no browser emulation. You can send two parameters that
214
- identify the website in which the CAPTCHA is found.
158
+ ### 5. Report an incorrectly solved CAPTCHA for a refund
215
159
 
216
- ```ruby
217
- options = {
218
- sitekey: 'xyz',
219
- pageurl: 'http://example.com/example=1'
220
- }
160
+ ```ruby
161
+ client.report!('130920620', 'reportbad') # with 130920620 being the CAPTCHA id
162
+ # returns `true` if successfully reported
221
163
 
222
- captcha = client.decode_hcaptcha!(options)
223
- captcha.text # Solution of the captcha
224
- ```
164
+ client.report!('256892751', 'reportgood') # with 256892751 being the CAPTCHA id
165
+ # returns `true` if successfully reported
166
+ ```
225
167
 
226
- ## Using proxy or other custom options
168
+ ### 6. Get your account balance
227
169
 
228
- You are allowed to use custom options like `proxy`, `proxytype` or `userAgent` whenever the 2Captcha API supports it. Example:
170
+ ```ruby
171
+ client.balance
172
+ # returns a Float balance in USD.
173
+ ```
229
174
 
230
- ```ruby
231
- options = {
232
- sitekey: 'xyz',
233
- pageurl: 'http://example.com/example=1',
234
- proxy: 'login:password@123.123.123.123:3128',
235
- userAgent: 'user agent'
236
- }
175
+ ### 7. Get usage statistics for a specific date
237
176
 
238
- captcha = client.decode_hcaptcha!(options)
239
- ```
177
+ ```ruby
178
+ client.stats(Date.new(2022, 10, 7))
179
+ # returns an XML string with your usage statistics.
180
+ ```
240
181
 
241
182
  ## Notes
242
183
 
243
- #### Thread-safety
184
+ ### Thread-safety
244
185
 
245
186
  The API is thread-safe, which means it is perfectly fine to share a client
246
187
  instance between multiple threads.
247
188
 
248
- #### Ruby dependencies
189
+ ### Ruby dependencies
249
190
 
250
191
  TwoCaptcha don't require specific dependencies. That saves you memory and
251
192
  avoid conflicts with other gems.
252
193
 
253
- #### Input image format
194
+ ### Input image format
254
195
 
255
- Any format you use in the decode method (url, file, path, raw, raw64) will
256
- always be converted to a raw64, which is a binary base64 encoded string. So, if
257
- you already have this format available on your side, there's no need to do
258
- convertions before calling the API.
196
+ Any format you use in the `decode_image!` method (`url`, `file`, `path`, `raw` or `raw64`)
197
+ will always be converted to a `raw64`, which is a base64-encoded binary string.
198
+ So, if you already have this format on your end, there is no need for convertions
199
+ before calling the API.
259
200
 
260
201
  > Our recomendation is to never convert your image format, unless needed. Let
261
202
  > the gem convert internally. It may save you resources (CPU, memory and IO).
262
203
 
263
- #### Versioning
204
+ ### Versioning
264
205
 
265
206
  TwoCaptcha gem uses [Semantic Versioning](http://semver.org/).
266
207
 
267
- #### Tested Ruby versions
268
-
269
- * MRI 2.2.2
270
- * MRI 2.2.0
271
- * MRI 2.1.4
272
- * MRI 2.0.0
273
-
274
- ## Contributing
208
+ ### Contributing
275
209
 
276
210
  1. Fork it ( https://github.com/infosimples/two_captcha/fork )
277
211
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -287,4 +221,4 @@ https://github.com/infosimples/two_captcha/graphs/contributors
287
221
 
288
222
  # License
289
223
 
290
- MIT License. Copyright (C) 2011-2015 Infosimples. https://infosimples.com/
224
+ MIT License. Copyright (C) 2011-2022 Infosimples. https://infosimples.com/
@@ -30,11 +30,12 @@ module TwoCaptcha
30
30
  # @return [TwoCaptcha::Captcha] The captcha (with solution) or an empty
31
31
  # captcha instance if something goes wrong.
32
32
  #
33
- def decode(options = {})
34
- decode!(options)
33
+ def decode_image(options = {})
34
+ decode_image!(options)
35
35
  rescue TwoCaptcha::Error => ex
36
36
  TwoCaptcha::Captcha.new
37
37
  end
38
+ alias :decode :decode_image
38
39
 
39
40
  # Decode the text from an image (i.e. solve a captcha).
40
41
  #
@@ -60,7 +61,7 @@ module TwoCaptcha
60
61
  # @return [TwoCaptcha::Captcha] The captcha (with solution) if an error is
61
62
  # not raised.
62
63
  #
63
- def decode!(options = {})
64
+ def decode_image!(options = {})
64
65
  started_at = Time.now
65
66
 
66
67
  raw64 = load_captcha(options)
@@ -77,6 +78,7 @@ module TwoCaptcha
77
78
 
78
79
  decoded_captcha
79
80
  end
81
+ alias :decode! :decode_image!
80
82
 
81
83
  #
82
84
  # Solve reCAPTCHA v2.
@@ -1,4 +1,4 @@
1
1
  module TwoCaptcha
2
- VERSION = '1.7.0'
2
+ VERSION = '1.8.0'
3
3
  USER_AGENT = "TwoCaptcha/Ruby v#{VERSION}"
4
4
  end
data/two_captcha.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.8"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "bundler", ">= 2.2.33"
26
+ spec.add_development_dependency "rake", ">= 12.3.3"
27
27
  spec.add_development_dependency "rspec", "~> 3.1"
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: two_captcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Barbolo
@@ -9,36 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-11-08 00:00:00.000000000 Z
12
+ date: 2022-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.8'
20
+ version: 2.2.33
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.8'
27
+ version: 2.2.33
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: 12.3.3
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '10.0'
41
+ version: 12.3.3
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement