Tasks:
 

ForumBoard
Topic: z-training API: Just in PHP for Now

admin on 1/11/10 @ 3:55 amEST

If you want to use z-training's graders for your website, you can do so.

You can download and test the APIs here:

zAPI.zip: http://www.z-training.net/api/package/zAPI.zip
zAPI.tar.gz: http://www.z-training.net/api/package/zAPI.tar.gz
zAPI.tar.bz2: http://www.z-training.net/api/package/zAPI.tar.bz2

In order to use the full functionality you will need a z-training API key. Would you like to fully use z-training's graders for your website please contact the admin to obtain the key.

Any usage (commercial and non-commercial) is allowed providing that your website clearly states that the grading is done by z-training's graders, and that the grading page has a link-back to z-training.

admin on 1/11/10 @ 4:12 amEST

How to use it (The package has more examples):

define('ZAPI_DIRECTORY', dirname(__FILE__). DIRECTORY_SEPARATOR);
include_once ZAPI_DIRECTORY . 'lib'. DIRECTORY_SEPARATOR . 'zAPI.php';

$myUsername = "testing_username" ;
$myKey      = "5866887b22b194862fce17a8ec594fe0" ;

// create a api class
$zApi = new zTrainingAPI($myUsername, $myKey);

$cSolution =
  "#include <stdio.h>\n" .
  "int main() { \n".
  "int a,b; ".
  "scanf(\"%d %d\", &a, &b); ".
  "printf(\"%d\", a + b); return 0; }";
$result = $zApi->gradeSolution("zbir", zLangs::C, $cSolution);
echo $result->passed?"Passed\n\n":"Didn't pass\n\n";

$scmSolution = "(let ((a (read)) (b (read))) (display (+ a b)))";
$result = $zApi->gradeSolution("zbir", zLangs::SCHEME, $scmSolution);
echo $result->passed?"Passed\n\n":"Didn't pass\n\n";

$pSolution =
  "import sys, string\n".
  "x = string.split(sys.stdin.readline().strip(), \" \")\n".
  "print int(x[0])+int(x[1])";
$result = $zApi->gradeSolution("zbir", zLangs::PYTHON, $pSolution);
echo $result->passed?"Passed\n\n":"Didn't pass\n\n";