class Api::V2::DocumentsController
Public Instance Methods
POST /api/documents/:id/add_attachment
Attaches a file to the instructions for students
-
Args :
-
file-> the file to attach to the instructions using multipart upload feature(not to be included in the signature calculation) -
id-> the document 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 except for file 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 attachment that was added:
-
attachment:-
attachment_id-> the id of the attachment -
placeholder-> the placeholder that can be added to the instruction text to download the file -
url-> the url to download the file valid for one minute -
exam_id-> the id of the exam -
document_id-> the id of the document
-
-
-
http status 200
-
# File app/controllers/api/v2/documents_controller.rb, line 156 def add_attachment if @json['file'] @exam = @document.exam @attachment = Attachment.new(build_attachment_attributes) if @attachment.save save_request render json: { attachment: (build_json_attachment_response @attachment) }, status: :ok and return end end render nothing: true, status: :bad_request and return end
GET /api/documents/:id/attachments_list
Lists all the attachments for the document
-
Args :
-
id-> the document 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 attachments of the document:
-
attachments:-
attachment_id-> the id of the attachment -
placeholder-> the placeholder that can be added to the instruction text to download the file -
url-> the url to download the file valid for one minute -
exam_id-> the id of the exam -
document_id-> the id of the document
-
-
-
http status 200
-
# File app/controllers/api/v2/documents_controller.rb, line 189 def attachments_list if @document.exam.attachments save_request render json: { attachments: @document.exam.attachments.map{ |attachment| build_json_attachment_response attachment }}, status: :ok and return else render nothing: true, status: :bad_request and return end end
POST /api/documents
Creates the document that contains the instructions for the student
-
Args :
-
exam_id-> the id of the exam -
document_text-> the text of the document, formatted in html -
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 with the id of the created document:
-
id-> the id of the document
-
-
http status 200
-
# File app/controllers/api/v2/documents_controller.rb, line 24 def create if @json['exam_id'] && @json['document_text'] if @exam.document render nothing: true, status: :forbidden and return else @document = Document.new @document.assign_attributes(build_document_attributes) if @document.save save_request render json: {id: @document.id}, status: :created and return end end end render nothing: true, status: :bad_request and return end
DELETE /api/documents/:id
Deletes the instructions for students
-
Args :
-
id-> the document 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/documents_controller.rb, line 106 def destroy if @document.destroy save_request render nothing: true, status: :ok and return end render nothing: true, status: :bad_request and return end
DELETE /api/documents/:id/destroy_attachment
Deletes the attachment and remove the placeholders from the instruction text
-
Args :
-
id-> the document id -
attachment_id-> the attachment 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/documents_controller.rb, line 211 def destroy_attachment @document = @attachment.exam.document exam_content = @document.exam_content exam_content.gsub!(@attachment.get_placeholder, '') if @attachment.destroy save_request @document.update(exam_content: exam_content) render nothing: true, status: :ok and return end render nothing: true, status: :bad_request and return end
GET /api/documents
Indexes the documents that belong 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 containing the documents:
-
documents:-
document_id-> the id of the document -
exam_id-> the id of the exam -
document_text-> the text instruction for the students, formatted in html -
has_attachments-> true if there are files attached to the document -
user_id-> the id of the user who created the exam -
institute_id-> the id of the institute
-
-
-
http status 200
-
# File app/controllers/api/v2/documents_controller.rb, line 60 def index @documents = @exams.map{ |exam| Document.find_by(exam: exam)}.compact if @documents.count > 0 save_request render json: { documents: @documents.map{ |document| build_document_json_response document }}, status: :ok and return end render nothing: true, status: :bad_request and return end
GET /api/documents/:id
Shows the instruction for students
-
Args :
-
id-> the document 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 document:
-
document:-
document_id-> the id of the document -
exam_id-> the id of the exam -
document_text-> the text instruction for the students, formatted in html -
has_attachments-> true if there are files attached to the document -
user_id-> the id of the user who created the exam -
institute_id-> the id of the institute
-
-
-
http status 200
-
# File app/controllers/api/v2/documents_controller.rb, line 90 def show save_request render json: { document: (build_document_json_response @document) }, status: :ok and return end
POST /api/documents/:id
Updates the instructions for students
-
Args :
-
id-> the document id -
document_text-> the new text instruction for the students, formatted in html -
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/documents_controller.rb, line 127 def update if @document.update_attributes(build_document_attributes.except(:exam)) save_request render nothing: true, status: :ok and return end render nothing: true, status: :bad_request and return end