Class: Rage::ParamsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/params_parser.rb

Class Method Summary collapse

Class Method Details

.json_parse(json) ⇒ Object



37
38
39
# File 'lib/rage/params_parser.rb', line 37

def self.json_parse(json)
  FastJsonparser.parse(json, symbolize_keys: true)
end

.prepare(env, url_params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rage/params_parser.rb', line 4

def self.prepare(env, url_params)
  has_body, query_string, content_type = env["IODINE_HAS_BODY"], env["QUERY_STRING"], env["CONTENT_TYPE"]

  query_params = Iodine::Rack::Utils.parse_nested_query(query_string) if query_string != ""
  unless has_body
    if query_params
      return query_params.merge!(url_params)
    else
      return url_params
    end
  end

  request_params = if content_type.start_with?("application/json")
    json_parse(env["rack.input"].read)
  elsif content_type.start_with?("application/x-www-form-urlencoded")
    Iodine::Rack::Utils.parse_urlencoded_nested_query(env["rack.input"].read)
  else
    Iodine::Rack::Utils.parse_multipart(env["rack.input"], content_type)
  end

  if request_params && !query_params
    request_params.merge!(url_params)
  elsif request_params && query_params
    request_params.merge!(query_params, url_params)
  else
    url_params
  end

rescue
  raise Rage::Errors::BadRequest
end