Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
rack-iamnotarobot / lib / rack / iamnotarobot / helpers.rb
Size: Mime:
module Rack
  class IAmNotARobot
    module Helpers
      class HumanityCheck
        attr_reader :env

        def initialize(env)
          @env = env
        end

        def pass?
          Rack::IAmNotARobot.test_mode? ? Rack::IAmNotARobot.test_mode : env['recaptcha.valid']
        end
      end

      def recaptcha_valid?
        HumanityCheck.new(request.env.dup).pass?
      end

      def recaptcha_script_tag
        html_safe_string(%{<script src="https://www.google.com/recaptcha/api.js"#{Rack::IAmNotARobot.script_tag_attributes}></script>}) unless Rack::IAmNotARobot.test_mode?
      end

      def recaptcha_embed
        html_safe_string(%{<div class="g-recaptcha" data-sitekey="#{Rack::IAmNotARobot.site_key}"></div>})
      end

      private

      def html_safe_string(str)
        str.respond_to?(:html_safe) ? str.html_safe : str
      end
    end
  end
end