X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1c300f091f244070950cd7c849a718ba26210bbc..f59696cd8b0688b074548cf1941172e774b05b2d:/examples/prediction/prediction.rb diff --git a/examples/prediction/prediction.rb b/examples/prediction/prediction.rb index d1acb4c22e..c9d51bb6a9 100644 --- a/examples/prediction/prediction.rb +++ b/examples/prediction/prediction.rb @@ -120,6 +120,12 @@ get '/train' do :headers => {'Content-Type' => 'application/json'}, :body_object => training ) + + return [ + 200, + [["Content-Type", "application/json"]], + ::JSON.generate({"status": "success"}) + ] end get '/checkStatus' do @@ -128,25 +134,10 @@ get '/checkStatus' do :parameters => {'id' => 'language-sample'} ) - # Assemble some JSON our client-side code can work with. - json = {} - if result.status != 200 - if result.data["error"] - message = result.data["error"]["errors"].first["message"] - json["message"] = "#{message} [#{result.status}]" - else - json["message"] = "Error. [#{result.status}]" - end - json["response"] = ::JSON.parse(result.body) - json["status"] = "error" - else - json["response"] = ::JSON.parse(result.body) - json["status"] = "success" - end return [ 200, [["Content-Type", "application/json"]], - ::JSON.generate(json) + assemble_json_body(result) ] end @@ -160,6 +151,16 @@ post '/predict' do :headers => {'Content-Type' => 'application/json'}, :body_object => input ) + + return [ + 200, + [["Content-Type", "application/json"]], + assemble_json_body(result) + ] +end + +def assemble_json_body(result) + # Assemble some JSON our client-side code can work with. json = {} if result.status != 200 if result.data["error"] @@ -174,9 +175,5 @@ post '/predict' do json["response"] = ::JSON.parse(result.body) json["status"] = "success" end - return [ - 200, - [["Content-Type", "application/json"]], - ::JSON.generate(json) - ] + return ::JSON.generate(json) end