Class: MediaInformationGatherer::HTTP
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- MediaInformationGatherer::HTTP
- Defined in:
- lib/mig/http.rb
Instance Method Summary collapse
-
#merge_params_from_body(_params = params) ⇒ Object
Will try to convert a body to parameters and merge them into the params hash Params will override the body parameters.
Instance Method Details
#merge_params_from_body(_params = params) ⇒ Object
Will try to convert a body to parameters and merge them into the params hash Params will override the body parameters
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mig/http.rb', line 14 def merge_params_from_body(_params = params) _params = _params.dup if request.media_type == 'application/json' request.body.rewind body_contents = request.body.read logger.debug { "Parsing: '#{body_contents}'" } if body_contents json_params = JSON.parse(body_contents) if json_params.is_a?(Hash) _params = json_params.merge(_params) else _params['body'] = json_params end end end _params end |