Class: IPinfoMiddleware
- Inherits:
-
Object
- Object
- IPinfoMiddleware
- Defined in:
- lib/ipinfo-rails.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, cache_options = {}) ⇒ IPinfoMiddleware
constructor
A new instance of IPinfoMiddleware.
Constructor Details
#initialize(app, cache_options = {}) ⇒ IPinfoMiddleware
Returns a new instance of IPinfoMiddleware.
7 8 9 10 11 12 |
# File 'lib/ipinfo-rails.rb', line 7 def initialize(app, = {}) @app = app @token = .fetch(:token, nil) @ipinfo = IPinfo.create(@token, ) @filter = .fetch(:filter, nil) end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ipinfo-rails.rb', line 14 def call(env) env['called'] = 'yes' request = Rack::Request.new(env) filtered = if @filter.nil? is_bot(request) else @filter.call(request) end if filtered env['ipinfo'] = nil else ip = request.ip env['ipinfo'] = @ipinfo.details(ip) end @app.call(env) end |