mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Moved usage documentation out of the class.
Fixed an issue in the handle class.
This commit is contained in:
parent
5e38e3d3d0
commit
36dd7736c9
2 changed files with 16 additions and 23 deletions
|
@ -11,8 +11,21 @@ if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
|
||||||
echo $rpc_o->handle($_GET);
|
echo $rpc_o->handle($_GET);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// dump a simple usage output for people to use.
|
||||||
|
// this could be moved to an api doc in the future, or generated from
|
||||||
|
// the AurJSON class directly with phpdoc. For now though, just putting it here.
|
||||||
echo '<html><body>';
|
echo '<html><body>';
|
||||||
echo $rpc_o->usage();
|
echo 'The methods currently allowed are: <br />';
|
||||||
|
echo '<ul>';
|
||||||
|
echo '<li>search</li>';
|
||||||
|
echo '<li>info</li>';
|
||||||
|
echo '</ul><br />';
|
||||||
|
echo 'Each method requires the following HTTP GET syntax:<br />';
|
||||||
|
echo ' type=<i>methodname</i>&arg=<i>data</i> <br /><br />';
|
||||||
|
echo 'Where <i>methodname</i> is the name of an allowed method, and <i>data</i> is the argument to the call.<br />';
|
||||||
|
echo '<br />';
|
||||||
|
echo 'If you need jsonp type callback specification, you can provide an additional variable <i>callback</i>.<br />';
|
||||||
|
echo 'Example URL: <br /> http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103';
|
||||||
echo '</body></html>';
|
echo '</body></html>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,26 +19,6 @@ class AurJSON {
|
||||||
private $dbh = false;
|
private $dbh = false;
|
||||||
private $exposed_methods = array('search','info');
|
private $exposed_methods = array('search','info');
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the usage data for the exposed json api.
|
|
||||||
* @return string The usage data in plain format.
|
|
||||||
**/
|
|
||||||
public function usage() {
|
|
||||||
$usage = 'The methods currently allowed are: <br />';
|
|
||||||
$usage .= '<ul>';
|
|
||||||
foreach ($this->exposed_methods as $methodname) {
|
|
||||||
$usage .= "<li>{$methodname}</li>";
|
|
||||||
}
|
|
||||||
$usage .= '</ul><br />';
|
|
||||||
$usage .= 'Each method requires the following HTTP GET syntax:<br />';
|
|
||||||
$usage .= ' type=_methodname_&arg=_data_ <br /><br />';
|
|
||||||
$usage .= 'Where _methodname_ is the name of an exposed method, and _data_ is the data supplied as part of the call.<br />';
|
|
||||||
$usage .= 'The _ characters are included only in this example as placeholders. Do not use them in an actual query.<br /><br />';
|
|
||||||
$usage .= 'If you need jsonp type callback specification, you can provide an additional variable "callback".<br />';
|
|
||||||
$usage .= 'Example URL: <br /> http://aur-url/rpc.php?type=search&args=foobar&callback=jsonp1192244621103';
|
|
||||||
return $usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles post data, and routes the request.
|
* Handles post data, and routes the request.
|
||||||
* @param string $post_data The post data to parse and handle.
|
* @param string $post_data The post data to parse and handle.
|
||||||
|
@ -46,7 +26,7 @@ class AurJSON {
|
||||||
**/
|
**/
|
||||||
public function handle($http_data) {
|
public function handle($http_data) {
|
||||||
// set content type header to json
|
// set content type header to json
|
||||||
//header('content-type: application/json');
|
header('content-type: application/json');
|
||||||
// set up db connection.
|
// set up db connection.
|
||||||
$this->dbh = db_connect();
|
$this->dbh = db_connect();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue