Be a bit smarter with "notimplemented", add API impelmentation status, and basic details to the apidocs page

This commit is contained in:
james 2010-09-28 20:37:44 +00:00
parent b5ed7c174f
commit 8b2de95005
3 changed files with 78 additions and 12 deletions

21
api.php
View File

@ -380,41 +380,48 @@ switch($request[0]) {
} }
echo json_encode($ret); echo json_encode($ret);
/* APIDOC: zNOTIMPLEMENTED_school/list /* APIDOC: school/list
notimplemented
description(list schools) description(list schools)
return(schools array) return(schools array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_account/edit /* APIDOC: account/edit
notimplemented
description(edit account information) description(edit account information)
post(account array) post(account array)
return(account array) return(account array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_user/edit /* APIDOC: user/edit
notimplemented
description(edit user information for current conference) description(edit user information for current conference)
post(user array) post(user array)
return(user array) return(user array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_user/connect_teacher_to_school /* APIDOC: user/connect_teacher_to_school
notimplemented
description(connects the current users teacher role to the specified school usign the schools access code) description(connects the current users teacher role to the specified school usign the schools access code)
post(schools_id integer, accesscode varchar(16)) post(schools_id integer, accesscode varchar(16))
return(school array) return(school array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_role/list /* APIDOC: role/list
notimplemented
description(list roles and their corresponding registration types) description(list roles and their corresponding registration types)
return(roles array) return(roles array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_role/add /* APIDOC: role/add
notimplemented
post(role_id integer, password varchar(64) optional) post(role_id integer, password varchar(64) optional)
description(add a role for the user to the current conference. Depending on the registraiton type, an optional password (singlepassword, schoolpassword, etc) can be specified) description(add a role for the user to the current conference. Depending on the registraiton type, an optional password (singlepassword, schoolpassword, etc) can be specified)
return(role array) return(role array)
*/ */
/* APIDOC: zNOTIMPLEMENTED_role/remove /* APIDOC: role/remove
notimplemented
post(role_id integer) post(role_id integer)
description(remove a role from the user for the current conference) description(remove a role from the user for the current conference)
return(role array) return(role array)

View File

@ -3,11 +3,15 @@ body {
color: #666666; color: #666666;
} }
h1 { h1 {
font-size: 1.5em;
font-weight: bold;
}
h2 {
font-size: 1.2em; font-size: 1.2em;
font-weight: bold; font-weight: bold;
color: black; color: black;
} }
h2 { h3 {
font-size: 1.0em; font-size: 1.0em;
font-weight: bold; font-weight: bold;
margin-bottom: 0px; margin-bottom: 0px;

View File

@ -6,6 +6,8 @@
</head> </head>
<body> <body>
<? <?
$commands=array();
$nicommands=array();
//lets get sneaky here, and have the file parse itself! //lets get sneaky here, and have the file parse itself!
$lines=file("api.php"); $lines=file("api.php");
foreach($lines AS $line) { foreach($lines AS $line) {
@ -18,6 +20,8 @@
$cmd['description']=array(); $cmd['description']=array();
$cmd['post']=array(); $cmd['post']=array();
$cmd['return']=array(); $cmd['return']=array();
//assume its implemented unless we say otherwise
$cmd['implemented']=true;
$incmd=true; $incmd=true;
} }
if($incmd==true && preg_match("/description\((.*)\)/",$line,$matches)) { if($incmd==true && preg_match("/description\((.*)\)/",$line,$matches)) {
@ -31,20 +35,40 @@
$returns=explode(",",$matches[1]); $returns=explode(",",$matches[1]);
$cmd['return']=$returns; $cmd['return']=$returns;
} }
if($incmd==true && $line=="notimplemented") {
$cmd['implemented']=false;
}
if($incmd==true && $line=="*/") { if($incmd==true && $line=="*/") {
$incmd=false; $incmd=false;
$commands[$cmd['command']]=$cmd; if($cmd['implemented'])
$commands[$cmd['command']]=$cmd;
else
$nicommands[$cmd['command']]=$cmd;
unset($cmd); unset($cmd);
} }
} }
echo "<h1>Status</h1>\n";
$numi=count($commands);
$numni=count($nicommands);
$total=$numi+$numni;
$percent=round($numi/$total*100);
echo "$numi of $total implemented ($percent%) <br />\n";
echo "<h1>Basics</h1>\n";
echo "All API commands return \"status\", which is either \"ok\" or \"error\" <br />\n";
echo "If status is \"error\", then the return also contains \"error\" which contains the error message <br />\n";
echo "<h1>Implemented API</h1>\n";
ksort($commands); ksort($commands);
foreach($commands AS $c=>$com) { foreach($commands AS $c=>$com) {
echo "<h1>".htmlspecialchars($c)."</h1>"; echo "<h2>".htmlspecialchars($c)."</h2>";
echo "<div class=\"apidoc\">\n"; echo "<div class=\"apidoc\">\n";
echo $com['description']; echo $com['description'];
echo "<br />"; echo "<br />";
if(count($com['post'])) { if(count($com['post'])) {
echo "<h2>Post</h2>\n"; echo "<h3>Post</h3>\n";
echo "<ul>"; echo "<ul>";
foreach($com['post'] AS $p) { foreach($com['post'] AS $p) {
echo "<li>$p</li>\n"; echo "<li>$p</li>\n";
@ -52,7 +76,7 @@ foreach($commands AS $c=>$com) {
echo "</ul>"; echo "</ul>";
} }
if(count($com['return'])) { if(count($com['return'])) {
echo "<h2>Return</h2>\n"; echo "<h3>Return</h3>\n";
echo "<ul>"; echo "<ul>";
foreach($com['return'] AS $p) { foreach($com['return'] AS $p) {
echo "<li>$p</li>\n"; echo "<li>$p</li>\n";
@ -62,6 +86,37 @@ foreach($commands AS $c=>$com) {
echo "<br />"; echo "<br />";
echo "</div>"; echo "</div>";
} }
echo "<h1>Not Implemented API</h1>\n";
ksort($nicommands);
foreach($nicommands AS $c=>$com) {
echo "<h2>".htmlspecialchars($c)."</h2>";
echo "<div class=\"apidoc\">\n";
echo $com['description'];
echo "<br />";
if(count($com['post'])) {
echo "<h3>Post</h3>\n";
echo "<ul>";
foreach($com['post'] AS $p) {
echo "<li>$p</li>\n";
}
echo "</ul>";
}
if(count($com['return'])) {
echo "<h3>Return</h3>\n";
echo "<ul>";
foreach($com['return'] AS $p) {
echo "<li>$p</li>\n";
}
echo "</ul>";
}
echo "<br />";
echo "</div>";
}
?> ?>
</body> </body>
</html> </html>