Class: IPinfoMiddleware
- Inherits:
-
Object
- Object
- IPinfoMiddleware
- Defined in:
- lib/ipinfo-rails.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ IPinfoMiddleware
constructor
A new instance of IPinfoMiddleware.
Constructor Details
#initialize(app, options = {}) ⇒ IPinfoMiddleware
Returns a new instance of IPinfoMiddleware.
20 21 22 23 24 25 26 |
# File 'lib/ipinfo-rails.rb', line 20 def initialize(app, = {}) @app = app @token = .fetch(:token, nil) @ipinfo = IPinfo.create(@token, ) @filter = .fetch(:filter, nil) @ip_selector = .fetch(:ip_selector, DefaultIPSelector) end |
Instance Method Details
#call(env) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ipinfo-rails.rb', line 28 def call(env) env['called'] = 'yes' request = Rack::Request.new(env) ip_selector = @ip_selector.new(request) filtered = if @filter.nil? is_bot(request) else @filter.call(request) end if filtered env['ipinfo'] = nil else ip = ip_selector.get_ip() env['ipinfo'] = @ipinfo.details(ip) end @app.call(env) end |