forked from science-ation/science-ation
Add api documentation
This commit is contained in:
parent
54bf2201de
commit
08340544d9
14
api.php
14
api.php
@ -38,7 +38,7 @@ $ret=array();
|
|||||||
|
|
||||||
switch($request[0]) {
|
switch($request[0]) {
|
||||||
case "conferences":
|
case "conferences":
|
||||||
/* apidoc: conferences/switch
|
/* APIDOC: conferences/switch
|
||||||
description(switches the active conference)
|
description(switches the active conference)
|
||||||
post(conferences_id integer)
|
post(conferences_id integer)
|
||||||
return(conferences_id integer)
|
return(conferences_id integer)
|
||||||
@ -60,7 +60,7 @@ switch($request[0]) {
|
|||||||
$ret['error']='conferences_id (integer) is required';
|
$ret['error']='conferences_id (integer) is required';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* apidoc: conferences
|
/* APIDOC: conferences
|
||||||
description(lists all conferences)
|
description(lists all conferences)
|
||||||
return(conferences array)
|
return(conferences array)
|
||||||
*/
|
*/
|
||||||
@ -78,11 +78,11 @@ switch($request[0]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "dates":
|
case "dates":
|
||||||
/* apidoc: dates
|
/* APIDOC: dates
|
||||||
description(list dates for active conference)
|
description(list dates for active conference)
|
||||||
return(dates array)
|
return(dates array)
|
||||||
*/
|
*/
|
||||||
/* apidoc: dates/<conferences_id integer>
|
/* APIDOC: dates/<conferences_id integer>
|
||||||
description(list dates for specified conference)
|
description(list dates for specified conference)
|
||||||
return(dates array)
|
return(dates array)
|
||||||
*/
|
*/
|
||||||
@ -104,7 +104,7 @@ switch($request[0]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "account":
|
case "account":
|
||||||
/* apidoc: account/create
|
/* APIDOC: account/create
|
||||||
description(creates an account)
|
description(creates an account)
|
||||||
post(username varchar(64), password varchar(64), email varchar(64) optional)
|
post(username varchar(64), password varchar(64), email varchar(64) optional)
|
||||||
return(account array)
|
return(account array)
|
||||||
@ -143,7 +143,7 @@ switch($request[0]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "auth":
|
case "auth":
|
||||||
/* apidoc: auth/login
|
/* APIDOC: auth/login
|
||||||
description(login to an account)
|
description(login to an account)
|
||||||
post(username varchar(64), password varchar(64))
|
post(username varchar(64), password varchar(64))
|
||||||
return(account array, roles array, conferences_id integer)
|
return(account array, roles array, conferences_id integer)
|
||||||
@ -174,7 +174,7 @@ switch($request[0]) {
|
|||||||
$ret['roles']=$_SESSION['roles'];
|
$ret['roles']=$_SESSION['roles'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* apidoc: auth/logout
|
/* APIDOC: auth/logout
|
||||||
description(logs out of an account)
|
description(logs out of an account)
|
||||||
return(account array)
|
return(account array)
|
||||||
*/
|
*/
|
||||||
|
25
apidoc.css
Normal file
25
apidoc.css
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
body {
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 1.2em;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 1.0em;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
.apidoc {
|
||||||
|
margin-left: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
margin: 0px;
|
||||||
|
padding-top: 0px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin-top: 0px;
|
||||||
|
}
|
64
apidoc.php
Normal file
64
apidoc.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>API Doc</title>
|
||||||
|
<link rel="stylesheet" href="apidoc.css" type="text/css" media="all" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?
|
||||||
|
//lets get sneaky here, and have the file parse itself!
|
||||||
|
$lines=file("api.php");
|
||||||
|
foreach($lines AS $line) {
|
||||||
|
$line=trim($line);
|
||||||
|
$matches=array();
|
||||||
|
if(preg_match("/APIDOC/",$line)) {
|
||||||
|
list($b,$a)=explode(":",$line);
|
||||||
|
$cmd=array();
|
||||||
|
$cmd['command']=trim($a);
|
||||||
|
$cmd['description']=array();
|
||||||
|
$cmd['post']=array();
|
||||||
|
$cmd['return']=array();
|
||||||
|
$incmd=true;
|
||||||
|
}
|
||||||
|
if($incmd==true && preg_match("/description\((.*)\)/",$line,$matches)) {
|
||||||
|
$cmd['description']=$matches[1];
|
||||||
|
}
|
||||||
|
if($incmd==true && preg_match("/post\((.*)\)/",$line,$matches)) {
|
||||||
|
$posts=explode(",",$matches[1]);
|
||||||
|
$cmd['post']=$posts;
|
||||||
|
}
|
||||||
|
if($incmd==true && preg_match("/return\((.*)\)/",$line,$matches)) {
|
||||||
|
$returns=explode(",",$matches[1]);
|
||||||
|
$cmd['return']=$returns;
|
||||||
|
}
|
||||||
|
if($incmd==true && $line=="*/") {
|
||||||
|
$incmd=false;
|
||||||
|
$commands[$cmd['command']]=$cmd;
|
||||||
|
unset($cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($commands AS $c=>$com) {
|
||||||
|
echo "<h1>".htmlspecialchars($c)."</h1>";
|
||||||
|
echo "<div class=\"apidoc\">\n";
|
||||||
|
echo $com['description'];
|
||||||
|
echo "<br />";
|
||||||
|
if(count($com['post'])) {
|
||||||
|
echo "<h2>POST</h2>\n";
|
||||||
|
echo "<ul>";
|
||||||
|
foreach($com['post'] AS $p) {
|
||||||
|
echo "<li>$p</li>\n";
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
}
|
||||||
|
if(count($com['return'])) {
|
||||||
|
echo "<h2>RETURN</h2>\n";
|
||||||
|
echo "<ul>";
|
||||||
|
foreach($com['return'] AS $p) {
|
||||||
|
echo "<li>$p</li>\n";
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
}
|
||||||
|
echo "<br />";
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user