Class: Routemaster::Middleware::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/routemaster/middleware/parse.rb

Overview

Receives a JSON payload of Routemaster events and parses it.

It also ignores anything but POST with application/json MIMEs.

Lower middlewares (or the app) can access the parsed payload as a hash in +env['routemaster.payload']+

Instance Method Summary collapse

Constructor Details

#initialize(app, _options = {}) ⇒ Parse

Returns a new instance of Parse.



13
14
15
# File 'lib/routemaster/middleware/parse.rb', line 13

def initialize(app, _options = {})
  @app  = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/routemaster/middleware/parse.rb', line 17

def call(env)
  if (env['CONTENT_TYPE'] != 'application/json')
    return [415, {}, []]
  end
  if (payload = _extract_payload(env))
    env['routemaster.payload'] = payload
  else
    return [400, {}, []]
  end
  @app.call(env)
end