getParameter.php 2.56 KB
<?php

/**
 * @api {get} getParameter.php getParameter
 * @apiDescription Provides data corresponding to a parameter chosen by the user among those available in AMDA (common
 * or user defined parameters).
 * @apiName getParameter
 * @apiGroup webservices
 *
 * @apiParam {String} token The API token.
 * @apiParam {String} startTime Beginning of the time interval (ISO 8601 or UNIXTIME format).
 * @apiParam {String} stopTime End of the time interval (ISO 8601 or UNIXTIME format).
 * @apiParam {String} parameterID Identifier of the parameter, as defined in the file returned by the *getParameterList*
 * or *getObsDataTree* web-services.
 * @apiParam {String} [sampling] Sampling of data (*in seconds*).
 * @apiParam {String} [userID] Identifier of the user in AMDA (*mandatory for user owned data*)
 * @apiParam {String} [password] Password of the user in AMDA (*mandatory for user owned data*)
 * @apiParam {String} [outputFormat] Format of the returned file. Two options: `VOTable` and `ASCII`.
 * @apiParam {String} [timeFormat] Format of time in the data files. Two options: `ISO8601` and `UNIXTIME`.
 * @apiParam {Boolean} [gzip] `1` if the file must be compressed before delivery.
 *
 * @apiSuccess {String} success `true`
 * @apiSuccess {String} dataFileURLs URL of the files matching the criteria. If the file is empty, there is no data
 * matching these criteria.
 * @apiSuccess {String} status status of the job ( done | in_progress )
 *
 * @apiSuccessExample Success-Response:
 *     HTTP/1.1 200 OK
 *     [success] => 1
 *     [dataFileURLS] => http://amda.irap.omp.eu/AMDA/data/WSRESULT/getparameter_c1_hia_dens_20130923T090000_20130924T130000.txt
 *     [status] => done
 *
 * @apiErrorExample Error-Response:
 * {"error":"Exception detected : Cannot find parameter local file c1_hia_dens1"}

 */

	require_once '../config.php';

	if (!key_exists("token", $_GET)) 
	{
		$result = array('success' => false, 'message' => "Authentication is required for this webservice.");
		exit(json_encode($result));
	} 
	 
	if ($_GET['startTime'] && strpos($_GET['startTime'], ' ') !== false) 
	{
		$result = array('success' => false, 
					'message' => "Check that there is no + (plus) character in your time definition. + is a special character and should be encoded by %2B");
		exit(json_encode($result));
	}
	
	$amda_ws = new WebServer();

	if ($amda_ws->getNewToken()['token'] != $_GET["token"]) 
	{
		$result = array('success' => false, 'status' => 'expired', 'message' => "Token expired. Please authenticate again.");
	} else 
	{
		$result = $amda_ws->getParameter($_GET);
	}
	
	echo json_encode($result);
?>