module RequestParseHelper
Helper methods for web request parsing.
Public Instance Methods
check_exists(collection, data)
click to toggle source
Also for non-POST, callers ask to check the collection against known collections and 404 if asking for an unknown one
# File lib/doppelserver/routes/helpers/request_parse_helper.rb, line 20 def check_exists(collection, data) halt 404 unless data.collection?(collection) end
parse_params(params)
click to toggle source
Parses parameters and checks that collections are plural if needed.
# File lib/doppelserver/routes/helpers/request_parse_helper.rb, line 10 def parse_params(params) collection, id = params['captures'] enforce_plural(collection) id ? [collection, id] : collection end
read_post_data(body)
click to toggle source
Takes a request body and returns post data. Unless is errors out because of no data or a parse error.
# File lib/doppelserver/routes/helpers/request_parse_helper.rb, line 28 def read_post_data(body) raw_data = body.read halt 403, 'NO DATA' if raw_data.empty? begin JSON.parse(raw_data) rescue JSON::ParserError halt 403, "BAD DATA:\n#{raw_data}" end end