Class: PrivateCaptcha::Middleware
- Inherits:
-
Object
- Object
- PrivateCaptcha::Middleware
- Defined in:
- lib/private_captcha/middleware.rb
Overview
Middleware provides Rack middleware for automatic captcha verification
Instance Method Summary collapse
-
#call(env) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(app, api_key:, **options) ⇒ Middleware
constructor
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(app, api_key:, **options) ⇒ Middleware
rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/private_captcha/middleware.rb', line 9 def initialize(app, api_key:, **) @app = app @client = Client.new do |config| config.api_key = api_key config.domain = [:domain] if [:domain] config.form_field = [:form_field] if [:form_field] config.failed_status_code = [:failed_status_code] if [:failed_status_code] config.max_backoff_seconds = [:max_backoff_seconds] if [:max_backoff_seconds] config.attempts = [:attempts] if [:attempts] config.logger = [:logger] if [:logger] end end |
Instance Method Details
#call(env) ⇒ Object
rubocop:disable Metrics/MethodLength
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/private_captcha/middleware.rb', line 24 def call(env) request = Rack::Request.new(env) begin @client.verify_request(request) rescue Error return [ @client.config.failed_status_code, { 'Content-Type' => 'text/plain' }, [Rack::Utils::HTTP_STATUS_CODES[@client.config.failed_status_code]] ] end @app.call(env) end |