two_captcha 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +9 -0
- data/README.md +9 -5
- data/lib/two_captcha/client.rb +9 -18
- data/lib/two_captcha/version.rb +1 -1
- data/spec/lib/client_spec.rb +18 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020a0e50cda97516940c1b430cff1432dad0ce34
|
4
|
+
data.tar.gz: 030416788dfa9f339cc9645e1ed0d2428767da01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fe57791572de606158764bddc2aa86856df09649cbf82d386a1965a558c90c1f53c661e92f7d45f280aec6863a592a6ebffa324d2ba2adc26914e2052d01fd7
|
7
|
+
data.tar.gz: 4aac7b9588bef5e641922ccb405ff89ce301b022f50df2071742f89fe1b89753261d43fe9b370fc5af29831ce3ac3a29de23c2b918dea4e675617888b62bdac7
|
data/Changelog.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# TwoCaptcha Changes
|
2
|
+
|
3
|
+
### 1.4.0
|
4
|
+
|
5
|
+
* **breaking changes:**
|
6
|
+
* The method "decode_recaptcha_v2" now always return a TwoCaptcha::Captcha
|
7
|
+
object. It was returning a string when successful.
|
8
|
+
* enhancements:
|
9
|
+
* Add tests to solve RecaptchaV2 with the preferred method.
|
data/README.md
CHANGED
@@ -103,10 +103,11 @@ There are two ways of solving captchas similar to
|
|
103
103
|
|
104
104
|
### (Prefered) Sending the `googlekey` and `pageurl` parameters
|
105
105
|
|
106
|
-
This method requires no browser emulation. You can send two parameters that
|
106
|
+
This method requires no browser emulation. You can send two parameters that
|
107
|
+
identify the website in which the captcha is found.
|
107
108
|
|
108
|
-
Please read the oficial documentation
|
109
|
-
more information.
|
109
|
+
Please read the [oficial documentation](https://2captcha.com/newapi-recaptcha-en)
|
110
|
+
for more information.
|
110
111
|
|
111
112
|
```ruby
|
112
113
|
options = {
|
@@ -115,12 +116,15 @@ more information.
|
|
115
116
|
}
|
116
117
|
|
117
118
|
client.decode_recaptcha_v2(options)
|
119
|
+
captcha.text # Solution of the captcha
|
120
|
+
captcha.id # Numeric ID of the captcha solved by TwoCaptcha
|
118
121
|
```
|
119
122
|
|
120
|
-
The
|
123
|
+
The solution (`captcha.text`) will be a code that validates the form, like the
|
124
|
+
following:
|
121
125
|
|
122
126
|
```ruby
|
123
|
-
"
|
127
|
+
"1JJHJ_VuuHAqJKxcaasbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcwkjsRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdkjsakFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZasDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05ajkPGt20qzpURMwHaw"
|
124
128
|
```
|
125
129
|
|
126
130
|
### Sending the challenge image
|
data/lib/two_captcha/client.rb
CHANGED
@@ -105,30 +105,21 @@ module TwoCaptcha
|
|
105
105
|
|
106
106
|
fail(TwoCaptcha::GoogleKey) if options[:googlekey].empty?
|
107
107
|
|
108
|
-
|
108
|
+
upload_options = {
|
109
109
|
method: 'userrecaptcha',
|
110
110
|
googlekey: options[:googlekey],
|
111
111
|
pageurl: options[:pageurl]
|
112
112
|
}
|
113
|
+
decoded_captcha = upload(upload_options)
|
113
114
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
action: 'get',
|
119
|
-
json: '1',
|
120
|
-
id: captcha_id
|
121
|
-
}
|
122
|
-
|
123
|
-
response_res = request('res', :get, payload_res)
|
124
|
-
|
125
|
-
while response_res.match(/CAPTCHA_NOT_READY|CAPCHA_NOT_READY/i)
|
126
|
-
sleep(polling)
|
127
|
-
response_res = request('res', :get, payload_res)
|
115
|
+
# pool untill the answer is ready
|
116
|
+
while decoded_captcha.text.to_s.empty?
|
117
|
+
sleep([polling, 10].max) # sleep at least 10 seconds
|
118
|
+
decoded_captcha = captcha(decoded_captcha.id)
|
128
119
|
fail TwoCaptcha::Timeout if (Time.now - started_at) > timeout
|
129
120
|
end
|
130
121
|
|
131
|
-
|
122
|
+
decoded_captcha
|
132
123
|
end
|
133
124
|
|
134
125
|
# Upload a captcha to 2Captcha.
|
@@ -139,8 +130,8 @@ module TwoCaptcha
|
|
139
130
|
#
|
140
131
|
def upload(options = {})
|
141
132
|
args = {}
|
142
|
-
args[:body] = options[:raw64]
|
143
|
-
args[:method] = 'base64'
|
133
|
+
args[:body] = options[:raw64] if options[:raw64]
|
134
|
+
args[:method] = options[:method] || 'base64'
|
144
135
|
args.merge!(options)
|
145
136
|
response = request('in', :multipart, args)
|
146
137
|
|
data/lib/two_captcha/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -92,4 +92,22 @@ describe TwoCaptcha::Client do
|
|
92
92
|
it { expect(@captcha.id).to match(/[0-9]{9}/) }
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
context 'image reCAPTCHA v2' do
|
97
|
+
before(:all) { @client = TwoCaptcha.new(key) }
|
98
|
+
|
99
|
+
describe '#decode_recaptcha_v2!' do
|
100
|
+
before(:all) do
|
101
|
+
options = {
|
102
|
+
googlekey: '6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-',
|
103
|
+
pageurl: 'https://www.google.com/recaptcha/api2/demo'
|
104
|
+
}
|
105
|
+
@captcha = @client.decode_recaptcha_v2!(options)
|
106
|
+
end
|
107
|
+
|
108
|
+
it { expect(@captcha).to be_a(TwoCaptcha::Captcha) }
|
109
|
+
it { expect(@captcha.text.size).to be > 50 } # not perfect, I know
|
110
|
+
it { expect(@captcha.id).to match(/[0-9]{9}/) }
|
111
|
+
end
|
112
|
+
end
|
95
113
|
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Barbolo
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ".rspec"
|
65
65
|
- ".travis.yml"
|
66
66
|
- CODE_OF_CONDUCT.md
|
67
|
+
- Changelog.md
|
67
68
|
- Gemfile
|
68
69
|
- LICENSE.txt
|
69
70
|
- README.md
|