Class: IPinfoLiteMiddleware
- Inherits:
-
Object
- Object
- IPinfoLiteMiddleware
- Defined in:
- lib/ipinfo-rails.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ IPinfoLiteMiddleware
constructor
A new instance of IPinfoLiteMiddleware.
Constructor Details
#initialize(app, options = {}) ⇒ IPinfoLiteMiddleware
Returns a new instance of IPinfoLiteMiddleware.
50 51 52 53 54 55 56 |
# File 'lib/ipinfo-rails.rb', line 50 def initialize(app, = {}) @app = app @token = .fetch(:token, nil) @ipinfo = IPinfoLite.create(@token, ) @filter = .fetch(:filter, nil) @ip_selector = .fetch(:ip_selector, DefaultIPSelector) end |
Instance Method Details
#call(env) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ipinfo-rails.rb', line 58 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 |