Class: SimplePusher::Middleware
- Inherits:
-
Object
- Object
- SimplePusher::Middleware
- Defined in:
- lib/simple_pusher/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/simple_pusher/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/simple_pusher/middleware.rb', line 7 def call(env) if env['PATH_INFO'] == '/simple_pusher' && env['REQUEST_METHOD'] == 'POST' # Both support param from url query string and form post data simple_pusher_params = env['rack.request.form_hash'].present? ? env['rack.request.form_hash'] : Rack::Utils.parse_nested_query(env['QUERY_STRING']) if simple_pusher_params['channel'].blank? [200, {}, 'Required channel param'] else SimplePusher.publish(simple_pusher_params['channel'], simple_pusher_params['message']) [200, {}, 'OK'] end else @app.call(env) end end |