deathbycaptcha 5.0.0 → 5.0.1

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: 85231874d833eab0bd84ac29b980d0c00bcb308d
4
- data.tar.gz: 91e8dec5412a607e32032e6f8b209a969d288ca7
3
+ metadata.gz: fd52fe97e5ea7f1e12508b4493c81ccae8325e03
4
+ data.tar.gz: 103578ff684f01a035ba01e6cebd985a05cbad24
5
5
  SHA512:
6
- metadata.gz: 2d397c364a4b95457252ddd07bdf9a52e8bc0d298932a591515812074310cb98492278cf8679e49e4c1c5b2b33b2eed9faeaff009347699856130724899f7829
7
- data.tar.gz: 9f0e76625b2565b2340866068dc10b9290259d2346ec91f8505ea70234e8ca2df09ec0b41a0d573d064b6c74a8128ebbad8dca21fdc61de91c6a102a4264ba0c
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
- deadline = Time.now + self.timeout
85
+ ::Timeout.timeout(self.timeout) do
86
+ raw64 = load_captcha(options)
87
+ raise DeathByCaptcha::InvalidCaptcha if raw64.to_s.empty?
86
88
 
87
- raw64 = load_captcha(options)
88
- raise DeathByCaptcha::InvalidCaptcha if raw64.to_s.empty?
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
- _captcha = self.upload(raw64)
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
- _captcha
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
- response = ::Socket.tcp(HOST, PORTS.sample) do |socket|
80
- socket.puts payload.to_json
81
- socket.read
82
- end
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
@@ -1,4 +1,4 @@
1
1
  module DeathByCaptcha
2
- VERSION = "5.0.0"
2
+ VERSION = "5.0.1"
3
3
  API_VERSION = "DBC/Ruby v#{VERSION}"
4
4
  end
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.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-26 00:00:00.000000000 Z
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.3
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)