:headers => {'Content-Type' => 'application/json'},
:body_object => training
)
+
+ return [
+ 200,
+ [["Content-Type", "application/json"]],
+ ::JSON.generate({"status": "success"})
+ ]
end
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
: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"]
json["response"] = ::JSON.parse(result.body)
json["status"] = "success"
end
- return [
- 200,
- [["Content-Type", "application/json"]],
- ::JSON.generate(json)
- ]
+ return ::JSON.generate(json)
end