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!, #decode_fun_captcha, #decode_fun_captcha!, #decode_h_captcha, #decode_h_captcha!, #decode_image, #decode_image!, #decode_recaptcha_v2, #decode_recaptcha_v2!, #decode_recaptcha_v3, #decode_recaptcha_v3!, #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.



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.



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.



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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

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

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

  when 4, 5
    payload = {
      type:         options[:type].to_i,
      token_params: options[:token_params].to_json,
    }

  when 6
    payload = {
      type:              options[:type].to_i,
      funcaptcha_params: options[:funcaptcha_params].to_json,
    }

  when 7
    payload = {
      type:            options[:type].to_i,
      hcaptcha_params: options[:hcaptcha_params].to_json,
    }
  end

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

#userDeathByCaptcha::User

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



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

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