module Pliny::Helpers::Params
Public Instance Methods
body_params()
click to toggle source
# File lib/pliny/helpers/params.rb, line 3 def body_params @body_params ||= parse_body_params end
Private Instance Methods
indifferent_params_v2(data)
click to toggle source
# File lib/pliny/helpers/params.rb, line 34 def indifferent_params_v2(data) case data when Hash Sinatra::IndifferentHash[data] when Array data.map { |item| indifferent_params_v2(item) } else data end end
load_params(data)
click to toggle source
# File lib/pliny/helpers/params.rb, line 25 def load_params(data) # Sinatra 1.x only supports the method. Sinatra 2.x only supports the class if defined?(Sinatra::IndifferentHash) indifferent_params_v2(data) else indifferent_params(data) end end
parse_body_params()
click to toggle source
# File lib/pliny/helpers/params.rb, line 9 def parse_body_params if request.media_type == "application/json" begin decoded = MultiJson.decode(request.body.read) rescue MultiJson::ParseError => e raise Pliny::Errors::BadRequest, e.message end request.body.rewind load_params(decoded) elsif request.form_data? load_params(request.POST) else {} end end