- $app = Application::from_api_key($db, $_REQUEST['key']) or cerbere_die("Invalid application API key");
+ $app = Application::from_api_key($db, $_REQUEST['key']) or $apiResponse->die("Invalid application API key");
switch ($command = $url[1]) {
case '':
//Nothing to do
//TODO: offer documentation instead
die();
case 'checkuserkey':
if (count($url) < 2) {
- cerbere_die("/checkuserkey/ must be followed by an user key");
+ $apiResponse->die("/checkuserkey/ must be followed by an user key");
}
$reply = (boolean)$app->get_perso_id($url[2]);
- api_output($reply, "check");
+ $apiResponse->output($reply, "check");
break;
case 'pushuserdata':
if (count($url) < 3) {
- cerbere_die("/pushuserdata/ must be followed by an user key");
+ $apiResponse->die("/pushuserdata/ must be followed by an user key");
}
- $perso_id = $app->get_perso_id($url[2]) or cerbere_die("Invalid application user key");
+ $perso_id = $app->get_perso_id($url[2]) or $apiResponse->die("Invalid application user key");
//then, falls to 'pushdata'
case 'pushdata':
$data_id = $_REQUEST['data'] ?: new_guid();
//Gets data
switch ($mode = $_REQUEST['mode']) {
case '':
- cerbere_die("Add in your data posted or in the URL mode=file to read data from the file posted (one file per api call) or mode=request to read data from \$_REQUEST['data'].");
+ $apiResponse->die("Add in your data posted or in the URL mode=file to read data from the file posted (one file per api call) or mode=request to read data from \$_REQUEST['data'].");
case 'request':
$data = $_REQUEST['data'];
$format = "raw";
break;
case 'file':
- $file = $_FILES['datafile']['tmp_name'] or cerbere_die("File is missing");
+ $file = $_FILES['datafile']['tmp_name'] or $apiResponse->die("File is missing");
if (!is_uploaded_file($file)) {
- cerbere_die("Invalid form request");
+ $apiResponse->die("Invalid form request");
}
$data = "";
if (preg_match('/\.tar$/', $file)) {
$format = "tar";
$data = file_get_contents($file);
} elseif (preg_match('/\.tar\.bz2$/', $file)) {
$format = "tar";
} elseif (preg_match('/\.bz2$/', $file)) {
$format = "raw";
} else {
$format = "raw";
$data = file_get_contents($file);
}
if ($data === "") {
//.bz2
- $bz = bzopen($file, "r") or cerbere_die("Couldn't open $file");
+ $bz = bzopen($file, "r") or $apiResponse->die("Couldn't open $file");
- // pass back as string. or simple xml object if you want!
- return $xml->asXML();
-}
-
-/**
- * Outputs API reply, printing it in the specified format.
- *
- * The format will be read form $_REQUEST['format'].
- *
- * @param mixed $reply the reply to format
- * @param string $xmlRoot the XML root element name (optional, default value is 'data').
- * @param string $xmlChildren the XML children elements name (optional, will be deducted from the context if omitted, or, if not possible, will be unknownNode)