Example #1
0
 public function make_request($url, $params = array(), $headers = array(), $method = PicovicoRequest::GET, $include_access_headers = PicovicoRequest::AUTHORIZED)
 {
     if ($include_access_headers == PicovicoRequest::AUTHORIZED and $this->is_logged_in() === FALSE) {
         PicovicoBase::throw_api_exception("Not Requested - reason : Login required");
         return NULL;
     }
     $url = Picovico::API_SCHEME . "://" . Picovico::API_SERVER . "/v" . Picovico::API_VERSION . "/" . $url;
     $ch = curl_init();
     $options = self::$CURL_OPTIONS;
     if (!$params) {
         $params = array();
     }
     $curl_headers = array();
     // access token headers
     if ($include_access_headers === PicovicoRequest::AUTHORIZED) {
         $curl_headers[] = "X-Access-Key: {$this->access_key}";
         $curl_headers[] = "X-Access-Token: {$this->access_token}";
     }
     if ($headers) {
         foreach ($headers as $h_key => $h_val) {
             $curl_headers[] = "{$h_key}: {$h_val}";
         }
     }
     // serialize if array or objects
     foreach ($params as $key => $val) {
         if (is_array($val) || is_object($val)) {
             if (is_array($params)) {
                 $params["{$key}"] = json_encode($val);
             } elseif (is_object($params)) {
                 $params->{$key} = json_encode($val);
             }
         }
     }
     // for put request, if file is supplied, then specifiy the file for PUT
     // and remove the file parameter
     $file_pointer = NULL;
     if ($method === PicovicoRequest::PUT and isset($params["file"])) {
         $file_pointer = fopen($params["file"], "r");
         $filesize = filesize($params["file"]);
         $options[CURLOPT_PUT] = TRUE;
         $options[CURLOPT_INFILE] = $file_pointer;
         $options[CURLOPT_INFILESIZE] = $filesize;
         unset($params["file"]);
     }
     $curl_request_params_string = http_build_query($params, null, '&');
     $curl_request_url = $url;
     if ($method === PicovicoRequest::POST) {
         $options[CURLOPT_POSTFIELDS] = $curl_request_params_string;
     } elseif ($method === PicovicoRequest::GET or $method === PicovicoRequest::PUT or $method === PicovicoRequest::DELETE) {
         if ($curl_request_params_string) {
             $curl_request_url_parts = parse_url($url . "?");
             if (isset($curl_request_url_parts["query"])) {
                 $curl_request_url = $url . "&" . $curl_request_params_string;
             } else {
                 $curl_request_url = $url . "?" . $curl_request_params_string;
             }
         }
     } else {
         $e = new PicovicoException(array("type" => "CurlException", 'message' => "Invalid Request method : {$method}", 'code' => "0"));
         curl_close($ch);
         throw $e;
     }
     $options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
     $options[CURLOPT_URL] = $curl_request_url;
     if ($method === PicovicoRequest::PUT or $method === PicovicoRequest::DELETE) {
         $curl_headers[] = "X-HTTP-Method-Override: " . strtoupper($method);
     }
     if ($curl_headers) {
         $options[CURLOPT_HTTPHEADER] = $curl_headers;
     }
     curl_setopt_array($ch, $options);
     $response = curl_exec($ch);
     if ($response === FALSE) {
         $e = new PicovicoException(array("type" => "CurlException", 'message' => curl_error($ch), 'code' => curl_errno($ch)));
         curl_close($ch);
         throw $e;
     }
     if ($file_pointer != NULL) {
         fclose($file_pointer);
     }
     $curl_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($curl_response_code >= 400) {
         $message = json_decode($response, TRUE);
         $message["_url"] = $options[CURLOPT_URL];
         $e = new PicovicoException(array("type" => "ApiHttpException", 'message' => $message, 'code' => $curl_response_code));
         curl_close($ch);
         throw $e;
     }
     curl_close($ch);
     // Because every response is a valid JSON response
     return json_decode($response, TRUE);
 }
Example #2
0
 function reset()
 {
     PicovicoBase::reset_music($this->vdd);
     PicovicoBase::reset_slides($this->vdd);
     $this->remove_credits();
     $this->vdd["style"] = NULL;
     $this->vdd["quality"] = NULL;
     return $this->vdd;
 }