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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59c78a3d0fc1086113ee19839c34915f2ee25dfd
4
- data.tar.gz: 93324acc8b929a1ce9afd091854fb613a65b1880
3
+ metadata.gz: 020a0e50cda97516940c1b430cff1432dad0ce34
4
+ data.tar.gz: 030416788dfa9f339cc9645e1ed0d2428767da01
5
5
  SHA512:
6
- metadata.gz: 1bbb44cd113201bc56e8f1a29bc3f933a5a0e2e9f5fc90eb69c33c381768ca8b3822ac1175a64289e52e8bbe6bb2d3a525587704388c57865fb6582460de7288
7
- data.tar.gz: 4cd54178eefe7b37bf5a21451bf35cbd8d03a03056bb8c9783756198f6e8591820ceba41b7a373e902415a51801685212040dbafe586a27eda428dff9fa7325d
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 identify website in which the captcha is found.
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 at https://2captcha.com/newapi-recaptcha-en for
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 response will be a code that validates the form, like the following:
123
+ The solution (`captcha.text`) will be a code that validates the form, like the
124
+ following:
121
125
 
122
126
  ```ruby
123
- "03AHJ_VuuHAqJKxcTH6sbTsqw-L1Sm4gD57PTeaEr9-MaETG1vfu2H5zlcw0u2KqgjHPiXWwlulOw0Ef82tH6SOSbXdelgkvdDl8HreKFug05zfadw2n-A2HoTgYteVA53Q46VatEcZofa5eKfaWgvrPS-IP1DpV4bnUEG69-VbWAx7fJ-p4rHSxq-ZYesBkk9yYFrAiT_70uSz8lg3iqRImfRW91RIkEq8A5UBn4vABUQvlDV4eoKpeNUKDmHOABHkdsV8_1KEgCbabIwsIuIkN1_hw-Mkg0NRdWuXgNtOWen0Zv65yl6D31yhyLV2s0h3ygQwrpxJpBWs7o_rG2TaVfi0y9S5cYr-YlMTHszvMQCVllf5WAiNAgV28JuAnFH5WqRHqT56Tz6ZVNigIToEzq1tnfuewgmJuyyP_woy_MGRoZoHxx6V9yUDw8Ig-hYD8kakmSnnjNQd50w_Y_tI3aDLp-s_7ZmhH6pcaoWWsid5hdtMXyvrP9DscDuCLBf7etLle8caPWSaYCpAq9DOTtj5NpSg6-OeCJdGdgIPT9Xdbo_dm4pLGZ0CNd5WQcjil_kZN_uErRssv9r8j5SC6tsIPBneQLqqqsg8Hyt9kjIh0N10d6-sFeV3QWw-OuzCrPSNYc-_AxvwaB0GUAOmHDDbj8kKz1oqfdBwJienRm246cbstqdc7uAHHuLWLpt1A5W-56PEbb3Zs-HNo3kcjvlJcfrOVJKW68-G3S635EJ9SBm9GFKzFojEu4-TF9CvYNJKaXY9dDev_TVbBaWpWN2Ctx5hHKRbtD1_g2LsGUTDkpo7wrf4pbAyP34zeMRBI1wrrV12PBKnuafaMjy2KIFLt0LM91uWiBzEC61AiSKKEwP2nydRIyIFGwbLFUMeGeqmje87wSajcjmdjl_w4XZBY2zy8fUH6XoAGZ6AeCTulIljBQDObQynKDd-rutPvKNxZw3sra3yRt9ziDVKKDk-LbhTfw508g1lu9io6jnvm3kbAdnkfZ0x0PkGiUMHU7hnuoW6bXo2Yn_Zt5tDWL7N7wFtY6B0k7cTy73f8er508zReOuoyz2NqL8smDCmcJu05kr5R6OVHfeUszn5OiYeVh8Q_gTMsEf4wdaOsQWGZhWQIS8Vi_6IYzwQsnOtYdI6T8q4IDrQh-9eemVn0gNI6gdyknStQ7DoujdPGt20qzpURMwHaw"
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
@@ -105,30 +105,21 @@ module TwoCaptcha
105
105
 
106
106
  fail(TwoCaptcha::GoogleKey) if options[:googlekey].empty?
107
107
 
108
- payload_in = {
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
- response_in = request('in', :get, payload_in)
115
- status, captcha_id = response_in.split('|')
116
-
117
- payload_res = {
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
- JSON.load(response_res)['request']
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
 
@@ -1,4 +1,4 @@
1
1
  module TwoCaptcha
2
- VERSION = '1.3.2'
2
+ VERSION = '1.4.0'
3
3
  USER_AGENT = "TwoCaptcha/Ruby v#{VERSION}"
4
4
  end
@@ -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.3.2
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