class Rad::Captcha attr_accessor :public_key, :private_key, :timeout, :enabled, :verify_url attr_required :private_key, :public_key def enabled?; !!enabled end def verify request, params recaptcha = nil Timeout::timeout(timeout || 3) do recaptcha = Net::HTTP.post_form URI.parse(verify_url), { 'privatekey' => private_key, 'remoteip' => request.ip, 'challenge' => params.recaptcha_challenge_field, 'response' => params.recaptcha_response_field } end result = recaptcha.body.split.map { |s| s.chomp } answer, error = result answer == 'true' end end rad.register :captcha, depends_on: [:template, :controller] do Rad::Captcha.new end