deathbycaptcha 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deathbycaptcha/client.rb +13 -12
- data/lib/deathbycaptcha/client/socket.rb +26 -4
- data/lib/deathbycaptcha/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd52fe97e5ea7f1e12508b4493c81ccae8325e03
|
4
|
+
data.tar.gz: 103578ff684f01a035ba01e6cebd985a05cbad24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5abe419b602a8e27cec06d5ff934f567c4dbe9e3a93132a852cf4bb2a6bfac6b55ace0c7f575cac69332089d72b7d91c6f434a7508e17bfa2d6154e9eff90004
|
7
|
+
data.tar.gz: e41f0460ac71a5ca5c482346d227f824a862c06209786aecfa027aa52c27a1955944910e652bbd4c84c24b37beebc854a11bf33978a51a574443664be91695d7
|
@@ -82,21 +82,22 @@ module DeathByCaptcha
|
|
82
82
|
# @return [DeathByCaptcha::Captcha] The captcha (with solution if an error is not raised).
|
83
83
|
#
|
84
84
|
def decode!(options = {})
|
85
|
-
|
85
|
+
::Timeout.timeout(self.timeout) do
|
86
|
+
raw64 = load_captcha(options)
|
87
|
+
raise DeathByCaptcha::InvalidCaptcha if raw64.to_s.empty?
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
+
_captcha = self.upload(raw64)
|
90
|
+
while _captcha.text.to_s.empty?
|
91
|
+
sleep(self.polling)
|
92
|
+
_captcha = self.captcha(_captcha.id)
|
93
|
+
end
|
89
94
|
|
90
|
-
|
91
|
-
while _captcha.text.to_s.empty? && deadline > Time.now
|
92
|
-
sleep(self.polling)
|
93
|
-
_captcha = self.captcha(_captcha.id)
|
94
|
-
end
|
95
|
-
|
96
|
-
raise DeathByCaptcha::IncorrectSolution if !_captcha.is_correct
|
97
|
-
raise DeathByCaptcha::Timeout if _captcha.text.to_s.empty?
|
95
|
+
raise DeathByCaptcha::IncorrectSolution if !_captcha.is_correct
|
98
96
|
|
99
|
-
|
97
|
+
_captcha
|
98
|
+
end
|
99
|
+
rescue ::Timeout::Error
|
100
|
+
raise DeathByCaptcha::Timeout
|
100
101
|
end
|
101
102
|
|
102
103
|
# Retrieve information from an uploaded captcha.
|
@@ -76,10 +76,10 @@ module DeathByCaptcha
|
|
76
76
|
password: self.password
|
77
77
|
)
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
socket = create_socket()
|
80
|
+
socket.puts(payload.to_json)
|
81
|
+
response = socket.read()
|
82
|
+
socket.close()
|
83
83
|
|
84
84
|
begin
|
85
85
|
response = JSON.parse(response)
|
@@ -103,6 +103,28 @@ module DeathByCaptcha
|
|
103
103
|
response
|
104
104
|
end
|
105
105
|
|
106
|
+
# Create a new socket connection with DeathByCaptcha API.
|
107
|
+
# This method is necessary because Ruby 1.9.7 doesn't support connection
|
108
|
+
# timeout and only Ruby 2.2.0 fixes a bug with unsafe sockets threads.
|
109
|
+
#
|
110
|
+
# In Ruby >= 2.2.0, this could be implemented as simply as:
|
111
|
+
# ::Socket.tcp(HOST, PORTS.sample, connect_timeout: 0)
|
112
|
+
#
|
113
|
+
def create_socket
|
114
|
+
socket = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, 0)
|
115
|
+
sockaddr = ::Socket.sockaddr_in(PORTS.sample, HOST)
|
116
|
+
begin # emulate blocking connect
|
117
|
+
socket.connect_nonblock(sockaddr)
|
118
|
+
rescue IO::WaitWritable
|
119
|
+
IO.select(nil, [socket]) # wait 3-way handshake completion
|
120
|
+
begin
|
121
|
+
socket.connect_nonblock(sockaddr) # check connection failure
|
122
|
+
rescue Errno::EISCONN
|
123
|
+
end
|
124
|
+
end
|
125
|
+
socket
|
126
|
+
end
|
127
|
+
|
106
128
|
# Return a cached http client for methods that doesn't work with sockets.
|
107
129
|
#
|
108
130
|
def http_client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deathbycaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Débora Setton Fernandes, Rafael Barbolo, Rafael Ivan Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
104
|
+
rubygems_version: 2.4.5
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Ruby API for DeathByCaptcha (Captcha Solver as a Service)
|