two_captcha 1.0.1 → 1.1.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
  SHA1:
3
- metadata.gz: f01f12561a53cdfd920b3e70a91f090d939c3ac7
4
- data.tar.gz: 3adb06109188455e97090a63b969304fc91d0d33
3
+ metadata.gz: 055315d1b7cfb0bafcb2542dcdf1996ed273753d
4
+ data.tar.gz: 62bba1e3f36d178aa38f7a860f50124740d938a7
5
5
  SHA512:
6
- metadata.gz: f87d4828f1727afd418bbf2d5c9986fa4449bfe785c5617a0cef33d50b5216f1649b2d6c99837daf702b180035fa6c761a9b0b3e80f6851c2bb7037f34c77586
7
- data.tar.gz: 4fb90567f9a014e3b63a14aac518c632fee79ac03c68966ef27601f183e56951e2e3c4b8c1ef33bfd16ef76195f059b10ea7b78f765612d332701659b11a7f42
6
+ metadata.gz: 0023a248fbba3ed1af6a714256b3e61ad91616145d2b5db1d5edea2e7da87cebe8c6d88f7e706425c411b3b0e92c4b362207237d04f8312bc79401e3dc6466c6
7
+ data.tar.gz: 3c161aa8ef5031a56d33873da65c27f474aa6a07999a530e3f39982158841f381baa479e8cf2c32dbe41822f58ecf6ea6ce8312218f11c405eb9ce46d24dbc76
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- Developed by [Infosimples](https://infosimples.com), a brazilian company that
2
- offers [data extraction solutions](https://infosimples.com/en/data-engineering)
3
- and [Ruby on Rails development](https://infosimples.com/en/software-development).
1
+ Developed by [Infosimples](https://infosimples.com), a [big data company](https://infosimples.com/en/data-engineering).
4
2
 
5
3
  # TwoCaptcha
6
4
 
@@ -98,17 +96,17 @@ Or install it yourself as:
98
96
  # return an XML string with the current service load.
99
97
  ```
100
98
 
101
- ## New ReCaptcha
99
+ ## Clickable CAPTCHAs (e.g. "No CAPTCHA reCAPTCHA")
102
100
 
103
101
  To solve captchas similar to
104
102
  [reCAPTCHA v2](https://support.google.com/recaptcha/?hl=en#6262736), you can add
105
- the param 'id_constructor: 23' to your request.
103
+ the param `coordinatescaptcha: 1` to your request.
106
104
 
107
- Please read the oficial documentation at https://2captcha.com/support/faq/30/ for
105
+ Please read the oficial documentation at https://2captcha.com/en-api-recaptcha for
108
106
  more information.
109
107
 
110
108
  ```ruby
111
- client.decode(url: 'http://bit.ly/1xXZcKo', id_constructor: 23)
109
+ client.decode(url: 'http://bit.ly/clickcaptcha', coordinatescaptcha: 1)
112
110
  ```
113
111
 
114
112
  **Captcha (screenshot)**
@@ -117,13 +115,12 @@ more information.
117
115
 
118
116
  ![Example of a captcha based on image clicks](captchas/2.jpg)
119
117
 
120
- The response will be an array containing the indexes for each image that should
121
- be clicked counting from left to right. For the captcha above it should look
122
- something like:
118
+ The response will be an array containing coordinates where the captcha should be
119
+ clicked. For the captcha above it should look something like:
123
120
 
124
121
  ```ruby
125
- # captcha.indexes
126
- [1, 9]
122
+ # captcha.coordinates
123
+ [[234, 330], [48, 137]]
127
124
  ```
128
125
 
129
126
  ## Notes
data/lib/two_captcha.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'base64'
2
2
  require 'json'
3
3
  require 'net/http'
4
+ require 'openssl'
4
5
 
5
6
  # The module TwoCaptcha contains all the code for the two_captcha gem.
6
7
  # It acts as a safely namespace that isolates logic from TwoCaptcha from any
@@ -55,6 +55,7 @@ module TwoCaptcha
55
55
  # @option options [Integer] :language (0) https://2captcha.com/setting
56
56
  # @option options [Integer] :header_acao (0) https://2captcha.com/setting
57
57
  # @option options [Integer] :id_constructor (0) 23 if new reCAPTCHA.
58
+ # @option options [Integer] coordinatescaptcha (0) 1 if clickable captcha.
58
59
  #
59
60
  # @return [TwoCaptcha::Captcha] The captcha (with solution) if an error is
60
61
  # not raised.
@@ -88,7 +89,7 @@ module TwoCaptcha
88
89
  args[:body] = options[:raw64]
89
90
  args[:method] = 'base64'
90
91
  [:phrase, :regsense, :numeric, :calc, :min_len, :max_len, :language,
91
- :header_acao, :id_constructor].each do |key|
92
+ :header_acao, :id_constructor, :coordinatescaptcha].each do |key|
92
93
  args[key] = options[key] if options[key]
93
94
  end
94
95
  response = request('in', :multipart, args)
@@ -7,5 +7,9 @@ module TwoCaptcha
7
7
  def indexes
8
8
  text.gsub('click:', '').split(/[^0-9]/).map(&:to_i)
9
9
  end
10
+
11
+ def coordinates
12
+ text.scan(/x=([0-9]+),y=([0-9]+)/).map { |x, y| [x.to_i, y.to_i] }
13
+ end
10
14
  end
11
15
  end
@@ -1,4 +1,4 @@
1
1
  module TwoCaptcha
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  USER_AGENT = "TwoCaptcha/Ruby v#{VERSION}"
4
4
  end
@@ -4,7 +4,7 @@ key = CREDENTIALS['key']
4
4
  captcha_id = CREDENTIALS['captcha_id']
5
5
  captcha_solution = CREDENTIALS['solution']
6
6
  image64 = Base64.encode64(File.open('captchas/1.png', 'rb').read)
7
- recaptcha64 = Base64.encode64(File.open('captchas/2.jpg', 'rb').read)
7
+ clickable64 = Base64.encode64(File.open('captchas/2.jpg', 'rb').read)
8
8
 
9
9
  describe TwoCaptcha::Client do
10
10
  describe 'create' do
@@ -58,15 +58,23 @@ describe TwoCaptcha::Client do
58
58
  end
59
59
  end
60
60
 
61
- context 'new reCAPTCHA' do
61
+ context 'clickable CAPTCHA' do
62
62
  before(:all) { @client = TwoCaptcha.new(key) }
63
63
 
64
64
  describe '#decode!' do
65
- before(:all) { @captcha = @client.decode!(raw64: recaptcha64, id_constructor: 23) }
65
+ before(:all) do
66
+ @captcha = @client.decode!(raw64: clickable64, coordinatescaptcha: 1)
67
+ @xy1, @xy2 = @captcha.coordinates.sort_by { |e| e[0] }
68
+ end
66
69
 
67
70
  it { expect(@captcha).to be_a(TwoCaptcha::Captcha) }
68
- it { expect(@captcha.indexes).to eq([1, 9]) }
69
71
  it { expect(@captcha.id).to match(/[0-9]{9}/) }
72
+
73
+ it { expect(@captcha.coordinates.size).to eq(2) }
74
+ it { expect(@xy1[0]).to be_between(9, 99).inclusive }
75
+ it { expect(@xy1[1]).to be_between(97, 187).inclusive }
76
+ it { expect(@xy2[0]).to be_between(187, 279).inclusive }
77
+ it { expect(@xy2[1]).to be_between(276, 366).inclusive }
70
78
  end
71
79
  end
72
80
  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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Mita
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-15 00:00:00.000000000 Z
12
+ date: 2016-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler