Beispiel #1
0
 /**
  * Function to create a response of type ResponseWithError containing a error message
  * given as argument
  *
  * @param $ERROR_MESSAGE
  * @return ResponseWithError
  */
 private function errorHandler($ERROR_MESSAGE)
 {
     $response = new ResponseWithError();
     $response->setFeed(new stdClass());
     $response->setError($ERROR_MESSAGE);
     return $response;
 }
 /**
  * @param feed {String} parameter with a url to be submitted to the google API.
  */
 public function requestGoogleApi()
 {
     $GOOGLE_RSS_API = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=';
     $ERROR = "Invalid feed";
     $feed = $_GET["feed"];
     $requestUrl = $GOOGLE_RSS_API . $feed;
     $response = getFromURI($requestUrl);
     $responseBody = json_decode($response);
     $response = new Response();
     if ($responseBody->responseStatus != 200) {
         $response = new ResponseWithError();
         $response->setError($ERROR);
     } else {
         $response->setFeed($responseBody->responseData->feed);
     }
     header('Content-Type: application/json');
     echo json_encode($response);
 }