Class: ClassyResources::PostBodyParams
- Inherits:
-
Object
- Object
- ClassyResources::PostBodyParams
- Defined in:
- lib/classy_resources/post_body_params.rb,
lib/classy_resources/post_body_param_parsing.rb
Overview
A Rack middleware for parsing POST/PUT body data when Content-Type is not one of the standard supported types, like application/json
.
TODO: Find a better name.
Constant Summary collapse
- CONTENT_TYPE =
Constants
'CONTENT_TYPE'.freeze
- POST_BODY =
'rack.input'.freeze
- FORM_INPUT =
'rack.request.form_input'.freeze
- FORM_HASH =
'rack.request.form_hash'.freeze
- APPLICATION_JSON =
Supported Content-Types
'application/json'.freeze
- APPLICATION_XML =
'application/xml'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ PostBodyParams
constructor
A new instance of PostBodyParams.
Constructor Details
#initialize(app) ⇒ PostBodyParams
Returns a new instance of PostBodyParams.
25 26 27 |
# File 'lib/classy_resources/post_body_params.rb', line 25 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/classy_resources/post_body_params.rb', line 29 def call(env) case env[CONTENT_TYPE] when APPLICATION_JSON env.update(FORM_HASH => JSON.parse(env[POST_BODY].read), FORM_INPUT => env[POST_BODY]) when APPLICATION_XML env.update(FORM_HASH => Hash.from_xml(env[POST_BODY].read), FORM_INPUT => env[POST_BODY]) end @app.call(env) end |