class Api::V2::ExamsController

See examples here: gist.github.com/danielefrisanco/737471a124bfd67cd1711a953364d965

Public Instance Methods

add_student() click to toggle source
POST /api/exams/:id/add_student

Adds a student to an exam

  • Args :

    • individual_info -> information that is displayed to this student at the beginning of the exam

    • id -> the exam id

    • name -> the name of the student

    • email -> the email of the student

    • attempt -> the attempt number of the student (0 by default). This must be unique per each student (bound to email). To create an additional attempt, create a new student session with the same email and increment the highest existing attempt number for a student by one.

    • use_duration -> whether duration is used or not (boolean), 0 or false to not use it

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • open_time -> epoch time in seconds of opening time for the student(must be in exam's boundaries), can be omitted

    • close_time -> epoch time in seconds of closing time for the student(must be in exam's boundaries), can be omitted

    • individual_info -> information that will only be shown to this specific student

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • a json cointaining the students that was added:

      • student_session:

        • individual_info -> information that is displayed to this student at the beginning of the exam

        • student_id -> the id of the student

        • name -> the name of the student

        • email -> the email of the student

        • attempt -> the attempt number of the student

        • exam_id -> the id of the exam

        • status -> the status of the student

        • open_time -> epoch time in seconds of opening time for the student

        • close_time -> epoch time in seconds of closing time for the student

        • start_time -> epoch time in seconds of start time for the student

        • end_time -> epoch time in seconds of end time for the student

        • token -> the token to be used in order to create the link to the exam room

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 244
def add_student
  @student_session = StudentSession.new(build_student_attributes)
  if @student_session.save
    save_request
    render json: { student_session: (build_student_session_json_response @student_session) }, status: :ok and return
  else
    render json: { errors: @student_session.errors }, status: :bad_request and return
  end
end
create() click to toggle source
POST /api/exams

Creates an exam

  • Args :

    • name -> the name of the exam

    • duration -> the duration of the exam in minutes

    • mobile_cam -> true if mobile recording is required

    • type -> the type of the exam:

      1. demo
      2. classroom
      3. record_review
      4. live_proctoring
      
    • start_time -> the first start time of the exam in epoch format

    • end_time -> the last end time of the exam in epoch format, can be omitted

    • for_reviewing -> true if you want to send the student videos to reviewers, can be omitted

    • use_duration -> wether the exam uses duration, true by default

    • upload_exam -> true if student has to upload one or more document at the end of the exam through proctorexam platform

    • restrictions -> the instructions for the reviewer, formatted in html, can be omitted

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash using tf the query string build with all the other parameters in the format “name=value” joined by “?” and in alphabetical order

  • Returns :

    • a json:

      • id -> the id of the exam

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 36
def create
  if @json['duration'] && @json['type'] && @json['name']
    @exam = Exam.new
    @exam.assign_attributes(build_exam_attributes)
    if @exam.save
      save_request
      render json: {id: @exam.id}, status: :created and return
    end
  end
  render nothing: true, status: :bad_request and return
end
delete_student() click to toggle source
DELETE /api/exams/:id/delete_student

Deletes a student session from an exam

  • Args :

    • id -> the exam id

    • student_session_id -> the student_session id

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 267
def delete_student
  if @student_session.end_time ? @student_session.archive : @student_session.destroy
    save_request
    render nothing: true, status: :ok and return
  else
    render nothing: true, status: :not_found and return
  end
end
destroy() click to toggle source
DELETE /api/exams/:id

Deletes the exam

  • Args :

    • id -> the exam id

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 96
def destroy
  if @exam.destroy
    save_request
    render nothing: true, status: :ok and return
  else
    render nothing: true, status: :bad_request and return
  end
end
index() click to toggle source
GET /api/exams

Index the exams that belongs to the user

  • Args :

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • a json cointaining the exams:

      • exams:

        • exam_id -> the id of the exam

        • name -> the name of the exam

        • start_time -> the start time of the exam

        • end_time -> the end time of the exam

        • duration -> the duration time of the exam

        • upload_exam -> true if the student has to upload one or more document through proctorexam platform

        • restrictions -> the instructions for the reviewer, formatted in html

        • type -> the type of the exam:

          1. demo
          2. classroom
          3. record_review
          4. live_proctoring
          
        • mobile_cam -> true if mobile recording is required

        • user_id -> the id of the user who created the exam

        • institute_id -> the id of the institute

        • for_reviewing -> true if user wants exams to be reviewed

        • use_duration -> whether the exam uses duration

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 79
def index
  save_request
  render json: { exams: Exam.where(user: @user).map{ |exam| build_exam_json_response exam } }, status: :ok and return
end
send_emails() click to toggle source
POST /api/exams/:id/send_emails

Sends the check requirement email to registered students that haven't received it yet and returns the list of this students

  • Args :

    • id -> the exam id

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • a json cointaining the students to whom the email has been sent:

      • student_sessions:

        • student_id -> the id of the student

        • name -> the name of the student

        • email -> the email of the student

        • exam_id -> the id of the exam

        • status -> the status of the student

        • individual_info -> information that is displayed to this student at the beginning of the exam

        • attempt -> the attempt number of the student.

        • use_duration -> whether duration is used or not (boolean), 0 or false to not use it

        • open_time -> epoch time in seconds of opening time for the student

        • close_time -> epoch time in seconds of closing time for the student

        • start_time -> epoch time in seconds of start time for the student

        • end_time -> epoch time in seconds of end time for the student

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 204
def send_emails
  save_request
  render json: { student_sessions: ( @exam.mass_email_sending.map{|student_session| build_student_session_json_response OpenStruct.new(student_session)}) }, status: :ok and return
end
show() click to toggle source
GET /api/exams/:id

Show the exam

  • Args :

    • id -> the exam id

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • a json cointaining the exam:

      • exam:

        • exam_id -> the id of the exam

        • name -> the name of the exam

        • start_time -> the start time in seconds of the exam

        • end_time -> the end time of in seconds the exam

        • duration -> the duration time of the exam

        • upload_exam -> true if the student has to upload one or more document through proctorexam platform

        • restrictions -> the instructions for the reviewer, formatted in html

        • type -> the type of the exam:

          1. demo
          2. classroom
          3. record_review
          4. live_proctoring
          
        • mobile_cam -> true if mobile recording is required

        • user_id -> the id of the user who created the exam

        • institute_id -> the id of the institute

        • for_reviewing -> true if user wants exams to be reviewed

        • use_duration -> whether the exam uses duration

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 171
def show
  save_request
  render json: { exam: (build_exam_json_response @exam) }, status: :ok and return
end
show_students() click to toggle source
GET /api/exams/:id/show_students

Returns the list of the students registered to an exam

  • Args :

    • id -> the exam id

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • a json cointaining the students registered:

      • student_sessions:

        • student_id -> the id of the student

        • name -> the name of the student

        • email -> the email of the student

        • exam_id -> the id of the exam

        • status -> the status of the student

        • individual_info -> information that is displayed to this student at the beginning of the exam

        • attempt -> the attempt number of the student

        • open_time -> epoch time in seconds of opening time for the student

        • close_time -> epoch time in seconds of closing time for the student

        • start_time -> epoch time in seconds of start time for the student

        • end_time -> epoch time in seconds of end time for the student

        • token -> token for accessing student_session information

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 303
def show_students
  save_request
  render json: { student_session: ( @exam.student_sessions.map{|student_session| build_student_session_json_response student_session}) }, status: :ok and return
end
update() click to toggle source
POST /api/exams/:id

Updates an exam

  • Args :

    • id -> the exam id

    • name -> the new name of the exam, can be omitted

    • duration -> the new duration of the exam, can be omitted

    • mobile_cam -> the new value for mobile camera, true if mobile recording is required, can be omitted

    • type -> the new type of the exam, can be omitted:

      1. demo
      2. classroom
      3. record_review
      4. live_proctoring
      
    • start_time -> the new start time of the exam in epoch format, can be omitted

    • end_time -> the new end time of the exam in epoch format, can be omitted

    • use_duration -> wether the exam uses duration, true by default

    • for_reviewing -> true if user wants exams to be reviewed

    • upload_exam -> the new value for upload exam, true if student has to upload one or more document at the end of the exam through proctorexam platform, can be omitted

    • restrictions -> the instructions for the reviewer, formatted in html, can be omitted

    • timestamp -> epoch time in milliseconds

    • nonce -> random number unique between the api calls made in the previous 24 hours

    • api_token -> the user api_token

    • signature -> HMAC sha256 hex encoded hash, using the user secret_key as key, of the query string build with all the other parameters in the format “name=value” joined by “?” and ordered alphabethically by name. Do not use encoding scheme on the values you use to calculate the string

  • Returns :

    • http status 200

# File app/controllers/api/v2/exams_controller.rb, line 131
def update
  if @exam.update_attributes( build_exam_update_attributes )
    save_request
    render nothing: true, status: :ok and return
  else
    render nothing: true, status: :bad_request and return
  end
end