Class: DeathByCaptcha::Client
- Inherits:
-
Object
- Object
- DeathByCaptcha::Client
- Defined in:
- lib/deathbycaptcha/client.rb
Overview
DeathByCaptcha::Client is a common interface inherited by DBC clients like DeathByCaptcha::Client::HTTP and DeathByCaptcha::Client::Socket.
Defined Under Namespace
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#polling ⇒ Object
Returns the value of attribute polling.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.create(username, password, connection = :http, options = {}) ⇒ DeathByCaptcha::Client
Create a DeathByCaptcha API client.
Instance Method Summary collapse
-
#captcha(captcha_id) ⇒ DeathByCaptcha::Captcha
Retrieve information from an uploaded captcha.
-
#decode(options = {}) ⇒ DeathByCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
-
#decode!(options = {}) ⇒ DeathByCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
- #decode_fun_captcha(options = {}) ⇒ Object
- #decode_fun_captcha!(options = {}) ⇒ Object
- #decode_h_captcha(options = {}) ⇒ Object
- #decode_h_captcha!(options = {}) ⇒ Object
- #decode_image(options = {}) ⇒ Object
- #decode_image!(options = {}) ⇒ Object
- #decode_recaptcha_v2(options = {}) ⇒ Object
- #decode_recaptcha_v2!(options = {}) ⇒ Object
- #decode_recaptcha_v3(options = {}) ⇒ Object
- #decode_recaptcha_v3!(options = {}) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ DeathByCaptcha::Client
constructor
Create a DeathByCaptcha client.
-
#report!(captcha_id) ⇒ DeathByCaptcha::Captcha
Report incorrectly solved captcha for refund.
-
#status ⇒ DeathByCaptcha::ServerStatus
Retrieve DeathByCaptcha server status.
-
#upload(raw64) ⇒ DeathByCaptcha::Captcha
Upload a captcha to DeathByCaptcha.
-
#user ⇒ DeathByCaptcha::User
Retrieve your user information (which has the current credit balance).
Constructor Details
#initialize(username, password, options = {}) ⇒ DeathByCaptcha::Client
Create a DeathByCaptcha client.
50 51 52 53 54 55 56 |
# File 'lib/deathbycaptcha/client.rb', line 50 def initialize(username, password, = {}) self.username = username self.password = password self.timeout = [:timeout] || 60 self.polling = [:polling] || 5 self.hostname = [:hostname] || 'api.dbcapi.me' end |
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
15 16 17 |
# File 'lib/deathbycaptcha/client.rb', line 15 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password.
15 16 17 |
# File 'lib/deathbycaptcha/client.rb', line 15 def password @password end |
#polling ⇒ Object
Returns the value of attribute polling.
15 16 17 |
# File 'lib/deathbycaptcha/client.rb', line 15 def polling @polling end |
#timeout ⇒ Object
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/deathbycaptcha/client.rb', line 15 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
15 16 17 |
# File 'lib/deathbycaptcha/client.rb', line 15 def username @username end |
Class Method Details
.create(username, password, connection = :http, options = {}) ⇒ DeathByCaptcha::Client
Create a DeathByCaptcha API client
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deathbycaptcha/client.rb', line 28 def self.create(username, password, connection = :http, = {}) case connection when :socket DeathByCaptcha::Client::Socket.new(username, password, ) when :http DeathByCaptcha::Client::HTTP.new(username, password, ) else raise DeathByCaptcha::InvalidClientConnection end end |
Instance Method Details
#captcha(captcha_id) ⇒ DeathByCaptcha::Captcha
Retrieve information from an uploaded captcha.
185 186 187 |
# File 'lib/deathbycaptcha/client.rb', line 185 def captcha(captcha_id) raise NotImplementedError end |
#decode(options = {}) ⇒ DeathByCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
69 70 71 72 73 |
# File 'lib/deathbycaptcha/client.rb', line 69 def decode( = {}) decode!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode!(options = {}) ⇒ DeathByCaptcha::Captcha
Decode the text from an image (i.e. solve a captcha).
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/deathbycaptcha/client.rb', line 88 def decode!( = {}) started_at = Time.now # Do not load image data for CAPTCHA types other than "image". raw64 = nil if ![4, 5, 6, 7].include?([:type]) raw64 = load_captcha() raise DeathByCaptcha::InvalidCaptcha if raw64.to_s.empty? end decoded_captcha = self.upload(.merge(raw64: raw64)) while decoded_captcha.text.to_s.empty? sleep(self.polling) decoded_captcha = self.captcha(decoded_captcha.id) raise DeathByCaptcha::Timeout if (Time.now - started_at) > self.timeout end raise DeathByCaptcha::IncorrectSolution if !decoded_captcha.is_correct decoded_captcha end |
#decode_fun_captcha(options = {}) ⇒ Object
165 166 167 168 169 |
# File 'lib/deathbycaptcha/client.rb', line 165 def decode_fun_captcha( = {}) decode_fun_captcha!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode_fun_captcha!(options = {}) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/deathbycaptcha/client.rb', line 171 def decode_fun_captcha!( = {}) = { type: 6, # FunCaptcha funcaptcha_params: .slice(:publickey, :pageurl, :proxy, :proxytype), } decode!() end |
#decode_h_captcha(options = {}) ⇒ Object
151 152 153 154 155 |
# File 'lib/deathbycaptcha/client.rb', line 151 def decode_h_captcha( = {}) decode_recaptcha_h_captcha!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode_h_captcha!(options = {}) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/deathbycaptcha/client.rb', line 157 def decode_h_captcha!( = {}) = { type: 7, # hCaptcha hcaptcha_params: .slice(:sitekey, :pageurl, :proxy, :proxytype), } decode!() end |
#decode_image(options = {}) ⇒ Object
111 112 113 114 115 |
# File 'lib/deathbycaptcha/client.rb', line 111 def decode_image( = {}) decode!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode_image!(options = {}) ⇒ Object
117 118 119 |
# File 'lib/deathbycaptcha/client.rb', line 117 def decode_image!( = {}) decode!(.slice(:url, :path, :file, :raw, :raw64)) end |
#decode_recaptcha_v2(options = {}) ⇒ Object
121 122 123 124 125 |
# File 'lib/deathbycaptcha/client.rb', line 121 def decode_recaptcha_v2( = {}) decode_recaptcha_v2!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode_recaptcha_v2!(options = {}) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/deathbycaptcha/client.rb', line 127 def decode_recaptcha_v2!( = {}) = { type: 4, # reCAPTCHA v2 token_params: .slice(:googlekey, :pageurl, :proxy, :proxytype), } decode!() end |
#decode_recaptcha_v3(options = {}) ⇒ Object
135 136 137 138 139 |
# File 'lib/deathbycaptcha/client.rb', line 135 def decode_recaptcha_v3( = {}) decode_recaptcha_v3!() rescue DeathByCaptcha::Error DeathByCaptcha::Captcha.new end |
#decode_recaptcha_v3!(options = {}) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/deathbycaptcha/client.rb', line 141 def decode_recaptcha_v3!( = {}) = { type: 5, # reCAPTCHA v3 token_params: { min_score: 0.3, }.merge(.slice(:googlekey, :pageurl, :action, :min_score, :proxy, :proxytype)), } decode!() end |
#report!(captcha_id) ⇒ DeathByCaptcha::Captcha
Report incorrectly solved captcha for refund.
195 196 197 |
# File 'lib/deathbycaptcha/client.rb', line 195 def report!(captcha_id) raise NotImplementedError end |
#status ⇒ DeathByCaptcha::ServerStatus
Retrieve DeathByCaptcha server status.
211 212 213 |
# File 'lib/deathbycaptcha/client.rb', line 211 def status raise NotImplementedError end |
#upload(raw64) ⇒ 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.
222 223 224 |
# File 'lib/deathbycaptcha/client.rb', line 222 def upload(raw64) raise NotImplementedError end |
#user ⇒ DeathByCaptcha::User
Retrieve your user information (which has the current credit balance).
203 204 205 |
# File 'lib/deathbycaptcha/client.rb', line 203 def user raise NotImplementedError end |