Created
November 14, 2015 01:20
-
-
Save RasPhilCo/1f3437d744ec549f9806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
test = Test.new format_params(params) | |
test.normalize_data | |
if test.save | |
render json: test | |
else | |
puts test.errors.messages | |
render text: test.errors.messages | |
end | |
end | |
private | |
def format_params(params) | |
# model interface: name, stamp_name, device_id, max_ref_coord, obs_count, serialized_data | |
# api interface: test_id, stamp_id, device_id, max_x & max_y, obs_count, data OR data_string | |
f_params = {} # a.k.a formatted_params | |
f_params[:name] = CGI.unescape(params[:test_id]) if params[:test_id] | |
f_params[:stamp_name] = CGI.unescape(params[:stamp_id]) if params[:stamp_id] | |
f_params[:device_id] = params[:device_id].to_i if params[:device_id] | |
max_x, max_y = params[:max_x].to_f, params[:max_y].to_f | |
f_params[:max_ref_coord] = [max_x, max_y] if max_x and max_y | |
f_params[:obs_count] = params[:obs_count].to_i if max_x and max_y | |
if params[:data_string] | |
f_params[:serialized_data] = JSON::parse(params[:data_string]) | |
else | |
f_params[:serialized_data] = params[:data] | |
end | |
return f_params | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment