修改调用编程的接口

This commit is contained in:
sw 2015-07-16 16:15:47 +08:00
parent 17e6102005
commit 0fc3e0077a
2 changed files with 25 additions and 4 deletions

View File

@ -1,5 +1,6 @@
class HomeworkCommonController < ApplicationController
require 'net/http'
require 'json'
layout "base_courses"
before_filter :find_course, :only => [:index,:new,:create,:next_step]
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy]
@ -74,7 +75,6 @@ class HomeworkCommonController < ApplicationController
homework_detail_programing.standard_code = params[:standard_code]
question = {title:homework.name,content:homework.description}
uri = URI('http://test.gitlab.trustie.net/api/questions.json')
question[:input] = []
question[:output] = []
if params[:input] && params[:output]
@ -89,7 +89,22 @@ class HomeworkCommonController < ApplicationController
end
end
end
res = Net::HTTP.post_form(uri, question)
# uri = URI('http://test.gitlab.trustie.net/api/questions.json')
# req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
# req.body = question.to_json
# res = Net::HTTP.start(uri.hostname, uri.port) do |http|
# http.request(req)
# end
uri = URI('http://test.gitlab.trustie.net/api/questions.json')
body = question.to_json
res = Net::HTTP.new(uri.host, uri.port).start do |client|
request = Net::HTTP::Post.new(uri.path)
request.body = body
request["Content-Type"] = "application/json"
client.request(request)
end
result = JSON.parse(res.body)
homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0

View File

@ -122,13 +122,19 @@ class StudentWorkController < ApplicationController
if stundet_work.save
if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分
url = "http://test.gitlab.trustie.net/api/questions/#{@homework.homework_detail_programing.question_id}/solutions.json"
uri = URI(url)
solutions = {
stundet_work_id:stundet_work.id,
src:stundet_work.description,
language:1
}
Net::HTTP.post_form(uri, solutions)
uri = URI(url)
body = solutions.to_json
res = Net::HTTP.new(uri.host, uri.port).start do |client|
request = Net::HTTP::Post.new(uri.path)
request.body = body
request["Content-Type"] = "application/json"
client.request(request)
end
end
respond_to do |format|
format.html {