Skip to content

API Docs

Vlad Stoica edited this page Mar 3, 2017 · 28 revisions

USR API Documentation

Quiz

Creating a quiz (Authenticated resource)

POST request to https://project-run.herokuapp.com/quizzes.

Request:

{
      "quiz": {
        "title": "My quiz",
        "questions_attributes": [
          {
            "question": "Question 1",
            "type": "single_choice",
            "answers_attributes": [
              {
                "answer": "Answer 1",
                "is_correct": false
              },
              {
                "answer": "Answer 2",
                "is_correct": true
              }
            ]
          },
          {
            "question": "Question 2",
            "type": "match",
            "pairs_attributes": [
              {
                "left_choice": "left 1",
                "right_choice": "right 1"
              },
              {
                "left_choice": "left 2",
                "right_choice": "right 2"
              }
            ]
          },
          {
            "question": "Question 3",
            "type": "multiple_choice",
            "answers_attributes": [
              {
                "answer": "Answer 1",
                "is_correct": false
              },
              {
                "answer": "Answer 2",
                "is_correct": true
              },
              {
                "answer": "Answer 3",
                "is_correct": true
              },
              {
                "answer": "Answer 4",
                "is_correct": false
              },
              {
                "answer": "Answer 5",
                "is_correct": false
              }
            ]
          },
          {
            "question": "Question 4",
            "type": "mix",
            "sentences_attributes": [
              {
                "text": "main sentence is here",
                "is_main": true
              },
              {
                "text": "sentence main here is",
                "is_main": false
              },
              {
                "text": "main sentence here is",
                "is_main": false
              }
            ]
          },
          {
            "question": "Question 5",
            "type": "cloze",
            "cloze_sentence_attributes": {
              "text": "test {1} before {2} after {3}"
            },
            "gaps_attributes": [
              {
                "gap_text": "text 1",
                "hint_attributes":
                  {
                    "hint_text": "hint 1"
                  }
              },
              {
                "gap_text": "text 2"
              },
              {
                "gap_text": "text 3"
              }
            ]
          }
        ]
      }
    }

Response:

{
  "id": 18,
  "title": "My quiz",
  "questions": [
    {
      "id": 36,
      "question": "Question 1",
      "type": "single_choice",
      "answers": [
        {
          "id": 60,
          "answer": "Answer 1"
        },
        {
          "id": 61,
          "answer": "Answer 2"
        }
      ]
    },
    {
      "id": 37,
      "question": "Question 2",
      "left": [
        {
          "id": "vV90HjE",
          "answer": "left 2"
        },
        {
          "id": "jgmDXvE",
          "answer": "left 1"
        }
      ],
      "right": [
        {
          "id": "KLDiI40",
          "answer": "right 1"
        },
        {
          "id": "MGZfc9k",
          "answer": "right 2"
        }
      ],
      "type": "match"
    },
    {
      "id": 38,
      "question": "Question 3",
      "type": "multiple_choice",
      "answers": [
        {
          "id": 62,
          "answer": "Answer 1"
        },
        {
          "id": 63,
          "answer": "Answer 2"
        },
        {
          "id": 64,
          "answer": "Answer 3"
        },
        {
          "id": 65,
          "answer": "Answer 4"
        },
        {
          "id": 66,
          "answer": "Answer 5"
        }
      ]
    },
    {
      "id": 39,
      "question": "Question 4",
      "type": "mix",
      "words": [
        "main",
        "sentence",
        "is",
        "here"
      ]
    },
    {
      "id": 40,
      "question": "Question 5",
      "type": "Questions::Cloze",
      "sentence": "test {1} before {2} after {3}"
    }
  ]
}

Getting all quizzes

GET request to https://project-run.herokuapp.com/quizzes

Getting a specific quiz

GET request to https://project-run.herokuapp.com/quizzes/:id

Checking the answers of a quiz

POST request to https://project-run.herokuapp.com/quiz/:id/check

Sample JSON request
{
	"questions":[
		{
			"id": 36,
			"answer_id": 61
		},
		{
			"id": 37,
			"pairs":[
            {
               "left_choice_id": "vV90HjE",
               "right_choice_id": "MGZfc9k"
            },
            {
               "left_choice_id": "jgmDXvE",
               "right_choice_id": "KLDiI40"
            }
         ]
		},
		{
			"id": 38,
			"answer_ids": [
				63,
				64
				]
		},
		{
			"id": 39,
			"answer": [
	              "main",
	              "sentence",
	              "here",
	              "is"
	            ]
		},
		{
			"id": 40,
			"answer_gaps": [
				"text 1",
				"text 2",
				"text 3"]
		}
		]
}

And a sample response:

[
  {
    "id": 36,
    "correct": true,
    "correct_answer": 61
  },
  {
    "id": 37,
    "correct": true,
    "correct_pairs": [
      {
        "left_choice_id": "vV90HjE",
        "right_choice_id": "MGZfc9k"
      },
      {
        "left_choice_id": "jgmDXvE",
        "right_choice_id": "KLDiI40"
      }
    ]
  },
  {
    "id": 38,
    "correct": true,
    "correct_answers": [
      63,
      64
    ]
  },
  {
    "id": 39,
    "correct": true,
    "correct_sentences": [
      "main sentence here is",
      "sentence main here is",
      "main sentence is here"
    ]
  },
  {
    "id": 40,
    "correct": false,
    "correct_gaps": [
      "text 3",
      "text 2",
      "text 1"
    ]
  }
]
Clone this wiki locally