Пример #1
0
 /**
  * Handles the request to the API.
  * It first checks that the method called (parameter 'method') is available in the module (it means that the method exists and is public)
  * It then reads the parameters from the request string and throws an exception if there are missing parameters.
  * It then calls the API Proxy which will call the requested method.
  * 
  * @see the method handleReturnedValue() for the data post process logic 
  * 
  * @return mixed The data resulting from the API call  
  */
 public function process()
 {
     try {
         // read the format requested for the output data
         $this->outputFormatRequested = Piwik_Common::getRequestVar('format', 'xml', 'string', $this->requestToUse);
         $this->outputFormatRequested = strtolower($this->outputFormatRequested);
         // read parameters
         $moduleMethod = Piwik_Common::getRequestVar('method', null, null, $this->requestToUse);
         list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
         if (!Piwik_PluginsManager::getInstance()->isPluginEnabled($module)) {
             throw new Exception_PluginDeactivated($module);
         }
         // call the method via the API_Proxy class
         $api = Piwik_Api_Proxy::getInstance();
         $api->registerClass($module);
         // read method to call meta information
         $className = "Piwik_" . $module . "_API";
         // check method exists
         $api->checkMethodExists($className, $method);
         // get the list of parameters required by the method
         $parameters = $api->getParametersList($className, $method);
         // load the parameters from the request URL
         $finalParameters = $this->getRequestParametersArray($parameters);
         // call the method
         $returnedValue = call_user_func_array(array($api->{$module}, $method), $finalParameters);
         // post process the data
         $toReturn = $this->handleReturnedValue($returnedValue);
     } catch (Exception $e) {
         // if it is not a direct API call, we are requesting the original data structure
         // and we actually are handling this exception at the top level in the FrontController
         if ($this->outputFormatRequested == 'original') {
             throw $e;
         }
         $message = $e->getMessage();
         $toReturn = $this->getExceptionOutput($message, $this->outputFormatRequested);
     }
     return $toReturn;
 }
Пример #2
0
 /**
  * Handles the request to the API.
  * It first checks that the method called (parameter 'method') is available in the module (it means that the method exists and is public)
  * It then reads the parameters from the request string and throws an exception if there are missing parameters.
  * It then calls the API Proxy which will call the requested method.
  * 
  * @return mixed The data resulting from the API call  
  */
 public function process()
 {
     // read the format requested for the output data
     $outputFormat = strtolower(Piwik_Common::getRequestVar('format', 'xml', 'string', $this->request));
     // create the response
     $response = new Piwik_API_ResponseBuilder($this->request, $outputFormat);
     try {
         // read parameters
         $moduleMethod = Piwik_Common::getRequestVar('method', null, null, $this->request);
         list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
         if (!Piwik_PluginsManager::getInstance()->isPluginActivated($module)) {
             throw new Exception_PluginDeactivated($module);
         }
         $module = "Piwik_" . $module . "_API";
         // call the method
         $returnedValue = Piwik_Api_Proxy::getInstance()->call($module, $method, $this->request);
         $toReturn = $response->getResponse($returnedValue);
     } catch (Exception $e) {
         $toReturn = $response->getResponseException($e);
     }
     return $toReturn;
 }