Class: Rails::Captchme::Captchme
- Inherits:
-
Object
- Object
- Rails::Captchme::Captchme
- Defined in:
- lib/rails/captchme.rb
Instance Method Summary collapse
-
#initialize(private_key, params, ip_client) ⇒ Captchme
constructor
A new instance of Captchme.
- #is_valid? ⇒ Boolean
- #request ⇒ Object
Constructor Details
#initialize(private_key, params, ip_client) ⇒ Captchme
Returns a new instance of Captchme.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rails/captchme.rb', line 9 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
27 28 29 |
# File 'lib/rails/captchme.rb', line 27 def is_valid? @response[0] == 'true' end |
#request ⇒ Object
23 24 25 |
# File 'lib/rails/captchme.rb', line 23 def request @response = @http.post(@uri.path, @data, @headers).body.split end |