Esempio n. 1
0
 public function execute(ViadeoRequest $request)
 {
     if (!$this->isAuthenticated()) {
         throw new ViadeoAuthenticationException("No access token is defined");
     }
     $curl_opts = $this->curl_opts;
     $headers = array('Authorization: Bearer ' . $this->getAccessToken());
     if ($request->getMethod() != "GET") {
         $headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
         $curl_opts[CURLOPT_POSTFIELDS] = $request->getParams();
         $curl_opts[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
         $url = $request->getPath();
     } else {
         $url = $request->getFullPath();
     }
     $curl_opts[CURLOPT_HTTPHEADER] = $headers;
     $curl_opts[CURLOPT_URL] = $url;
     $ch = curl_init($url);
     curl_setopt_array($ch, $curl_opts);
     $result = curl_exec($ch);
     if ($result === false) {
         throw new ViadeoConnectionException(curl_error($ch));
     }
     $result_sections = explode("\r\n\r\n", $result);
     $body = end($result_sections);
     $header = prev($result_sections);
     $result = json_decode($body);
     $ex = null;
     if (isset($result->error)) {
         curl_close($ch);
         throw new ViadeoAPIException($result->error->type . " - " . $result->error->message[0]);
     }
     curl_close($ch);
     return isset($result->id) ? new ViadeoGraphObject($this, $result) : $result;
 }
Esempio n. 2
0
 public function execute(ViadeoRequest $request)
 {
     if (!$this->isAuthenticated()) {
         throw new ViadeoAuthenticationException("No access token is defined");
     }
     $curl_opts = $this->curl_opts;
     $curl_opts[CURLOPT_HTTPHEADER] = array('Authorization: Bearer ' . $this->getAccessToken());
     $headers = array('Authorization: Bearer ' . $this->getAccessToken());
     if ($request->getMethod() != "GET") {
         # post method dynamically overriden by Tianji adaptation scripts
         $post_method = "application/x-www-form-urlencoded; charset=UTF-8";
         $headers[] = 'Content-Type: ' . $post_method;
         $json = strpos($post_method, 'json') == FALSE ? false : true;
         $curl_opts[CURLOPT_POSTFIELDS] = $request->getParams(array(), $json);
         $curl_opts[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
         $url = $request->getPath();
     } else {
         $url = $request->getFullPath();
     }
     $curl_opts[CURLOPT_HTTPHEADER] = $headers;
     $curl_opts[CURLOPT_URL] = $url;
     $ch = curl_init($url);
     curl_setopt_array($ch, $curl_opts);
     // mod:btw:dont yell at me
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $result = curl_exec($ch);
     if ($result === false) {
         throw new ViadeoConnectionException(curl_error($ch));
     }
     list($headers, $body) = explode("\r\n\r\n", $result);
     $result = json_decode($body);
     $ex = null;
     if (isset($result->error)) {
         curl_close($ch);
         throw new ViadeoAPIException($result->error->type . " - " . $result->error->message[0]);
     }
     curl_close($ch);
     return isset($result->id) ? new ViadeoGraphObject($this, $result) : $result;
 }