<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once dirname(__FILE__) . "/../Rosenberg.php";
require_once dirname(__FILE__) . '/../Config.php';
require_once dirname(__FILE__) . "/WWWUtility.php";
if (php_sapi_name() !== 'cli') {
    processGet($_GET);
} else {
    $args1 = array('type' => 'group', 'name' => 'temp');
    $args2 = array('type' => 'data', 'series' => 'dewpoint_C,heatindex_C,inDewpoint', 'from' => time() - 86400, 'duration' => 86400);
    processGet($args1);
}
function processGet(array $aArgs)
{
    header('Content-Type: application/json');
    try {
        $sType = WWWUtility::validateArg($aArgs, 'type', '/^(data|group)$/');
        switch ($sType) {
            case 'group':
                print processGroup($aArgs);
                break;
            case 'data':
                print processData($aArgs);
        }
    } catch (InvalidArgumentException $iae) {
        print "error: " . $iae->getMessage() . ";";
예제 #2
0
    //echo $data->getHttpAccept();
    RestUtils::sendResponse(200, json_encode($send_data), 'application/json');
    /*if($data->getHttpAccept() == 'json'){
    			RestUtils::sendResponse(200, json_encode($send_data),'application/json');
    		}/*else if($data->getHttpAccept() == 'xml'){
    			// Usamos el serializador de xml de PEAR
    			$options = array ('indent' => ' ','addDecl' => false,'rootName' => $fc->getAction(), XML_SERIALIZER_OPTION_RETURN_RESULT => true);
    			$serializer = new XML_Serializer($options);
    			RestUtils::sendResponse(200, $serializer->serialize($send_data),'application/xml');
    		}//*/
}
$data = RestUtils::processRequest();
switch ($data->getMethod()) {
    // this is a request for all users, not one in particular
    case 'get':
        $user_data = processGet($data);
        send($data, $user_data);
        break;
    case 'post':
        // creamos un usuario (o modificamos si ya existe su uuid)
        $user_data = processPost($data);
        send($data, $user_data);
        break;
    case 'put':
        $user_data = processPut($data);
        send($data, $user_data);
        break;
    case 'delete':
        $user_data = processDelete($data);
        send($data, $user_data);
        break;