Class: CAPTCHME::Captchme

Inherits:
Object
  • Object
show all
Defined in:
lib/captchme.rb

Instance Method Summary collapse

Constructor Details

#initialize(private_key, params, ip_client) ⇒ Captchme

Returns a new instance of Captchme.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/captchme.rb', line 8

def initialize(private_key, params, ip_client)
  @private_key = private_key
  @data = "private_key=" +  @private_key + "&challenge_key="+
  params["captchme_challenge_field"] + "&response=" +
  params["captchme_response_field"] + "&user_ip=" + ip_client;
  @headers = {
    "Content-Type" => "application/x-www-form-urlencoded",
    "Content-length" => @data.length.to_s,
    "Connection" => "close"
  }
  @uri = URI("http://api.captchme.net/api/verify")
  @http = Net::HTTP.new(@uri.host, @uri.port)
end

Instance Method Details

#is_valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/captchme.rb', line 26

def is_valid?
  @response[0] == 'true'
end

#requestObject



22
23
24
# File 'lib/captchme.rb', line 22

def request
  @response = @http.post(@uri.path, @data, @headers).body.split
end