Class: DeathByCaptcha::Client::HTTP

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

Overview

HTTP client for DeathByCaptcha API.

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:



12
13
14
15
# File 'lib/deathbycaptcha/client/http.rb', line 12

def captcha(captcha_id)
  response = perform("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:



23
24
25
26
# File 'lib/deathbycaptcha/client/http.rb', line 23

def report!(captcha_id)
  response = perform("captcha/#{captcha_id}/report", :post)
  DeathByCaptcha::Captcha.new(response)
end

#statusDeathByCaptcha::ServerStatus

Retrieve DeathByCaptcha server status.

Returns:



41
42
43
44
# File 'lib/deathbycaptcha/client/http.rb', line 41

def status
  response = perform('status')
  DeathByCaptcha::ServerStatus.new(response)
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:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/deathbycaptcha/client/http.rb', line 53

def upload(options = {})
  payload = {}
  payload[:captchafile] = "base64:#{options[:raw64]}"
  payload[:type] = options[:type] if options[:type].to_i > 0

  if options[:type].to_i == 3
    banner64 = load_captcha(options[:banner])
    raise DeathByCaptcha::InvalidCaptcha if banner64.to_s.empty?

    payload[:banner] = "base64:#{banner64}"
    payload[:banner_text] = options[:banner_text].to_s

  elsif options[:type].to_i == 4
    payload = {
      type: 4,
      token_params: options[:token_params].to_json,
    }
  end

  response = perform('captcha', :post_multipart, payload)
  DeathByCaptcha::Captcha.new(response)
end

#userDeathByCaptcha::User

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

Returns:



32
33
34
35
# File 'lib/deathbycaptcha/client/http.rb', line 32

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