Class: Clients::Recaptcha::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/clients/recaptcha/solver.rb

Constant Summary collapse

INIT_URL =
Addressable::URI.parse("http://2captcha.com/in.php").freeze
SOLVE_STATUS_URL =
Addressable::URI.parse("http://2captcha.com/res.php").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, captcha_key: ENV["CAPTCHA_SOLVER_KEY"], sleep_duration: 5) ⇒ Solver

Returns a new instance of Solver.



12
13
14
15
16
# File 'lib/clients/recaptcha/solver.rb', line 12

def initialize(client, captcha_key: ENV["CAPTCHA_SOLVER_KEY"], sleep_duration: 5)
  @client = client
  @captcha_key = captcha_key
  @sleep_duration = sleep_duration
end

Instance Attribute Details

#captcha_keyObject (readonly)

Returns the value of attribute captcha_key.



10
11
12
# File 'lib/clients/recaptcha/solver.rb', line 10

def captcha_key
  @captcha_key
end

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/clients/recaptcha/solver.rb', line 10

def client
  @client
end

#sleep_durationObject (readonly)

Returns the value of attribute sleep_duration.



10
11
12
# File 'lib/clients/recaptcha/solver.rb', line 10

def sleep_duration
  @sleep_duration
end

Instance Method Details

#solve(banned_url, response) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/clients/recaptcha/solver.rb', line 18

def solve(banned_url, response)
  site_key = find_site_key(response)
  solved_path = find_solve_url(response)

  id = init_solver banned_url, site_key
  token = get_solution id

  solved_response = solve_captcha banned_url, solved_path, token
  solved_response.cookies
end