class ApiScoringController < ApiController respond_to :json before_filter :api_signed_in_user def work # clientid; returns another clientid clientid = params[:clientid] if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end conn = Connection.where(client_id: clientid).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 # todo this method is a stub #puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}" result_client_id = JamRuby::GetWork.get_work(conn.locidispid) #result_client_id = clientid+'peer' render :json => {:clientid => result_client_id}, :status => 200 end def worklist # clientid; returns a list of clientid clientid = params[:clientid] if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end conn = Connection.where(client_id: clientid).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 # todo this method is a stub result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid) #result_client_ids = [clientid+'peer1', clientid+'peer2'] render :json => {:clientids => result_client_ids}, :status => 200 end def record # aclientid, aAddr, bclientid, bAddr, score returns nothing #puts "================= record #{params.inspect}" aclientid = params[:aclientid] aip_address = params[:aAddr] bclientid = params[:bclientid] bip_address = params[:bAddr] score = params[:score] if aclientid.nil? then render :json => {message: 'aclientid not specified'}, :status => 400; return end if aip_address.nil? then render :json => {message: 'aAddr not specified'}, :status => 400; return end if bclientid.nil? then render :json => {message: 'bclientid not specified'}, :status => 400; return end if bip_address.nil? then render :json => {message: 'bAddr not specified'}, :status => 400; return end # no score means the test was run but failed, details should still be recorded for later consideration if score.nil? then render :json => {message: 'score not specified'}, :status => 400; return end aAddr = JamRuby::JamIsp.ip_to_num(aip_address) if aAddr.nil? then render :json => {message: 'aAddr not valid ip_address'}, :status => 400; return end bAddr = JamRuby::JamIsp.ip_to_num(bip_address) if bAddr.nil? then render :json => {message: 'bAddr not valid ip_address'}, :status => 400; return end if aAddr == bAddr then render :json => {message: 'aAddr and bAddr are the same'}, :status => 403; return end if !score.is_a? Numeric then render :json => {message: 'score not valid numeric'}, :status => 400; return end aconn = Connection.where(client_id: aclientid).first if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not owned by user'}, :status => 403; return end bconn = Connection.where(client_id: bclientid).first if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end if bAddr != bconn.addr then render :json => {message: 'b\'s session addr does not match bAddr'}, :status => 403; return end if score < 0 or score > 999 then render :json => {message: 'score < 0 or score > 999'}, :status => 403; return end aloc = JamRuby::GeoIpBlocks.lookup(aAddr) aisp = JamRuby::JamIsp.lookup(aAddr) if aisp.nil? or aloc.nil? then render :json => {message: 'a\'s location or isp not found'}, :status => 404; return end alocidispid = aloc.locid*1000000+aisp.coid; bloc = JamRuby::GeoIpBlocks.lookup(bAddr) bisp = JamRuby::JamIsp.lookup(bAddr) if bisp.nil? or bloc.nil? then render :json => {message: 'b\'s location or isp not found'}, :status => 404; return end blocidispid = bloc.locid*1000000+bisp.coid JamRuby::Score.createx(alocidispid, aclientid, aAddr, blocidispid, bclientid, bAddr, score.ceil, nil) render :json => {}, :status => 200 end end