jam-cloud/web/app/controllers/api_scoring_controller.rb

64 lines
2.4 KiB
Ruby
Raw Permalink Normal View History

class ApiScoringController < ApiController
respond_to :json
2014-02-26 05:01:55 +00:00
before_filter :api_signed_in_user
def work # clientid; returns another clientid
clientid = params[:clientid]
if clientid.blank? then render :json => {message: 'clientid not specified'}, :status => 400; return end
2014-02-26 05:01:55 +00:00
conn = Connection.where(client_id: clientid, user_id: current_user.id).first
if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end
# if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
#puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}"
2014-09-13 03:30:51 +00:00
result_client_id = JamRuby::GetWork.get_work(conn)
#result_client_id = clientid+'peer'
2014-02-26 05:01:55 +00:00
render :json => {:clientid => result_client_id}, :status => 200
end
2014-02-26 05:01:55 +00:00
def worklist # clientid; returns a list of clientid
clientid = params[:clientid]
if clientid.blank? then render :json => {message: 'clientid not specified'}, :status => 400; return end
2014-02-26 05:01:55 +00:00
conn = Connection.where(client_id: clientid, user_id: current_user.id).first
if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end
if conn.locidispid.nil? then render :json => {message: 'no locidispid for connection'}, :status => 404; return end
# if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
2014-02-26 05:01:55 +00:00
2014-09-13 03:30:51 +00:00
result_client_ids = JamRuby::GetWork.get_work_list(conn, APP_CONFIG.getwork_result_size, APP_CONFIG.staleness_hours)
#result_client_ids = [clientid+'peer1', clientid+'peer2']
2014-02-26 05:01:55 +00:00
render :json => {:clientids => result_client_ids}, :status => 200
end
def record # aclientid, aAddr, bclientid, bAddr, score returns nothing
2014-02-26 05:01:55 +00:00
aclientid = params[:aclientid]
2014-02-26 05:01:55 +00:00
aip_address = params[:aAddr]
bclientid = params[:bclientid]
2014-02-26 05:01:55 +00:00
bip_address = params[:bAddr]
score = params[:score]
2014-09-13 03:30:51 +00:00
begin
2014-09-15 19:09:49 +00:00
udpReachable = params[:detail][:sdetail][:udpReachable]
2014-09-13 03:30:51 +00:00
rescue
udpReachable = nil
end
2014-02-26 05:01:55 +00:00
2014-09-13 03:30:51 +00:00
score_data = params.to_s
2014-02-26 05:01:55 +00:00
2014-09-13 03:30:51 +00:00
result = Score.record(current_user, aclientid, aip_address, bclientid, bip_address, score, score_data, udpReachable)
2014-09-13 03:30:51 +00:00
if result[:error]
render :json => {message: result[:message]}, :status => 422
else
2014-09-13 03:30:51 +00:00
render :json => {message: result[:message]}, :status => 200
end
end
2014-02-26 05:01:55 +00:00
end