Created
September 19, 2013 13:03
-
-
Save ajslaghu/6623168 to your computer and use it in GitHub Desktop.
Demo code for re using Nationale nieuwsquiz data from: http://tools.ncrv.nl/nnqapi/doc/#get-questions. A database which contains popquizzes with pictures on dutch topics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Written by AJ SLAGHUIS in 2013 | |
$limit = 10000; // lets get 'm all at 10.000 | |
$page = 0; | |
/* | |
* Retrieving Quiz Id's | |
*/ | |
$uri = "http://tools.ncrv.nl/nnqapi/index.php/quizzes/$limit/$page"; | |
$file = file_get_contents($uri); | |
$json = json_decode($file); //print_r($json); | |
//print("error $json->error \t " . "total $json->total \t " | |
// . "total_pages $json->total_pages \t " . "page $json->page \t " | |
// . "limit $json->limit \n"); | |
echo "Records " . count($json->result) . "\n"; | |
for ($i = 0; $i < count($json->result); $i += 1) { | |
// $quiz = $json->result[$i]; | |
// print("id $quiz->id \t" . "widgetid $quiz->widget_id \t" | |
// ."name $quiz->name \t" . "date $quiz->date \t" | |
// ."published $quiz->published \t" ); | |
// $quiz->question array is always empty, because ??? | |
} | |
// let's just pick a random quiz | |
$n = rand(0, count($json->result)); | |
echo "Random Pick Quiz " . $n . "\n"; | |
$quiz = $json->result[$n]; | |
print("id $quiz->id \t" . "widgetid $quiz->widget_id \t" | |
. "name $quiz->name \t" . "date $quiz->date \t" | |
. "published $quiz->published \t"); | |
/* | |
* Retrieving a Quiz by using an quiz ID | |
*/ | |
$jsonq = json_decode(file_get_contents("http://tools.ncrv.nl/nnqapi/index.php/quiz/$quiz->id")); | |
//print_r($jsonq); | |
print( "error " . $jsonq->error . "\n"); | |
echo "Records " . count($jsonq->result->questions) . "\n"; | |
for ($i = 0; $i < count($jsonq->result->questions); $i += 1) { | |
// $question = $jsonq->result->questions[$i]; | |
// print("id $question->id \t" . "quizid $question->quiz_id \t" | |
// . "title $question->title \n" . "text $question->text \t" | |
// . "type $question->type \n" | |
// . "answer_a $question->answer_a \t" | |
// . "answer_b $question->answer_b \t" | |
// . "answer_c $question->answer_c \t" | |
// . "answer_d $question->answer_d \n" | |
// . "correct_answer $question->correct_answer \t" | |
// . "seconds $question->seconds \t" | |
// . "points $question->points \n\n"); | |
} | |
// let's just pick a random quiz | |
$n = rand(0, count($jsonq->result->questions)); | |
echo "Random Pick Question" . $n . "\n"; | |
$question = $jsonq->result->questions[$n]; | |
print("id $question->id \t" . "quizid $question->quiz_id \t" | |
. "title $question->title \n" . "text $question->text \t" | |
. "type $question->type \n" | |
. "answer_a $question->answer_a \t" | |
. "answer_b $question->answer_b \t" | |
. "answer_c $question->answer_c \t" | |
. "answer_d $question->answer_d \n" | |
. "correct_answer $question->correct_answer \t" | |
. "seconds $question->seconds \t" | |
. "points $question->points \n\n"); | |
/* | |
* Retrieving Questions | |
* get contents of: http://tools.ncrv.nl/nnqapi/index.php/questions/:limit/:page | |
* with for example: http://tools.ncrv.nl/nnqapi/index.php/questions/10000/0 | |
* Questions also list the field mediafile which contains content like: | |
* http:\/\/www.nationalenieuwsquiz.nl\/data\/media\/c9a433f29e70246add40c70b23e557e5.jpg | |
*/ | |
/* | |
* Retrieving a Question by using an question ID | |
* get contents of: http://tools.ncrv.nl/nnqapi/index.php/question/:id | |
* with: http://tools.ncrv.nl/nnqapi/index.php/question/1223 | |
* Questions also list the field mediafile which contains content like: | |
* http:\/\/www.nationalenieuwsquiz.nl\/data\/media\/c9a433f29e70246add40c70b23e557e5.jpg | |
*/ | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment