Class: Rack::SnapSearch
- Inherits:
-
Object
- Object
- Rack::SnapSearch
- Defined in:
- lib/rack/snap_search.rb,
lib/rack/snap_search/config.rb
Overview
Use to enable SnapSearch detection within your web application.
Defined Under Namespace
Classes: Config
Instance Method Summary collapse
-
#call(environment) ⇒ Object
Run the middleware.
-
#initialize(app, options = {}) {|Rack::SnapSearch::Config, SnapSearch::Detector| ... } ⇒ SnapSearch
constructor
Initialize the middleware.
Constructor Details
#initialize(app, options = {}) {|Rack::SnapSearch::Config, SnapSearch::Detector| ... } ⇒ SnapSearch
Initialize the middleware.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rack/snap_search.rb', line 16 def initialize(app, ={}, &block) raise TypeError, 'app must respond to #call' unless app.respond_to?(:call) raise TypeError, 'options must be a Hash or respond to #to_h or #to_hash' unless .is_a?(Hash) || .respond_to?(:to_h) || .respond_to?(:to_hash) = .to_h rescue .to_hash @app = app setup_config() block.call(@config) if block_given? setup_client setup_detector setup_interceptor end |
Instance Method Details
#call(environment) ⇒ Object
Run the middleware.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rack/snap_search.rb', line 35 def call(environment) raise TypeError, 'environment must be a Hash or respond to #to_h or #to_hash' unless environment.is_a?(Hash) || environment.respond_to?(:to_h) || environment.respond_to?(:to_hash) environment = environment.to_h rescue environment.to_hash setup_x_forwarded_proto(environment) if @config.x_forwarded_proto setup_api_response_from_environment(environment) # Will set @api_response if one is given from the API if @api_response unless @config.response_callback.nil? @callback_response = @config.response_callback.call(*@api_response) setup_attributes_from_callback_response else setup_attributes_from_api_response end rack_response else setup_attributes_from_app(environment) end end |