Class: DeathByCaptcha::Client::Socket

Inherits:
DeathByCaptcha::Client show all
Defined in:
lib/deathbycaptcha/client/socket.rb

Overview

Socket client for DeathByCaptcha API.

Constant Summary collapse

PORTS =
(8123..8130).to_a

Instance Attribute Summary

Attributes inherited from DeathByCaptcha::Client

#hostname, #password, #polling, #timeout, #username

Instance Method Summary collapse

Methods inherited from DeathByCaptcha::Client

create, #decode, #decode!, #initialize

Constructor Details

This class inherits a constructor from DeathByCaptcha::Client

Instance Method Details

#captcha(captcha_id) ⇒ DeathByCaptcha::Captcha

Retrieve information from an uploaded captcha.

Parameters:

  • captcha_id (Integer)

    Numeric ID of the captcha.

Returns:



15
16
17
18
# File 'lib/deathbycaptcha/client/socket.rb', line 15

def captcha(captcha_id)
  response = perform('captcha', captcha: captcha_id)
  DeathByCaptcha::Captcha.new(response)
end

#report!(captcha_id) ⇒ DeathByCaptcha::Captcha

Report incorrectly solved captcha for refund.

Parameters:

  • captcha_id (Integer)

    Numeric ID of the captcha.

Returns:



26
27
28
29
# File 'lib/deathbycaptcha/client/socket.rb', line 26

def report!(captcha_id)
  response = perform('report', captcha: captcha_id)
  DeathByCaptcha::Captcha.new(response)
end

#statusDeathByCaptcha::ServerStatus

Retrieve DeathByCaptcha server status. This method won’t use a Socket connection, it will use an HTTP connection.

Returns:



45
46
47
# File 'lib/deathbycaptcha/client/socket.rb', line 45

def status
  http_client.status
end

#upload(options = {}) ⇒ DeathByCaptcha::Captcha

Upload a captcha to DeathByCaptcha.

This method will not return the solution. It’s only useful if you want to implement your own “decode” function.

Returns:



56
57
58
59
60
61
62
63
# File 'lib/deathbycaptcha/client/socket.rb', line 56

def upload(options = {})
  if options[:type] && options[:type].to_i != 1
    # Socket client implementation currently supports only text captchas.
    raise DeathByCaptcha::InvalidCaptcha
  end
  response = perform('upload', captcha: options[:raw64])
  DeathByCaptcha::Captcha.new(response)
end

#userDeathByCaptcha::User

Retrieve your user information (which has the current credit balance)

Returns:



35
36
37
38
# File 'lib/deathbycaptcha/client/socket.rb', line 35

def user
  response = perform('user')
  DeathByCaptcha::User.new(response)
end