class MediaInformationGatherer::HTTP

Public Instance Methods

merge_params_from_body(_params = params) click to toggle source

Will try to convert a body to parameters and merge them into the params hash Params will override the body parameters

@params [Hash] _params (params) The parameters parsed from the query and form fields

# 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