Пример #1
0
 /**
  * Make an API call. For all 
  * 
  * @see http://developer.github.com/v3/
  * 
  * @param string $command e.g "/users"
  * @param string $request e.g "POST" or PATCH, DELETE - if empty it is a GET
  * @param array $post vaiables $_POST variables to send
  * @param boolean $json should we return output as json. Default is false
  * @return boolean|array false if failure. Else: $ary response from github server
  */
 public function apiCall($command, $request = null, $post = null, $json = false)
 {
     if (!isset($_SESSION['access_token']) || empty($_SESSION['access_token'])) {
         $this->errors[] = 'No valid token';
         return false;
     }
     $end_point = 'https://api.github.com';
     $command = $end_point . "{$command}";
     $command .= "?access_token={$_SESSION['access_token']}";
     $c = new mycurl($command);
     if (isset($request)) {
         $c->setRequest($request);
     }
     if (isset($post)) {
         $json = json_encode($post);
         $c->setPost($json);
     }
     $c->createCurl();
     $resp = $c->getWebPage();
     $this->returnCode = $c->getHttpStatus();
     if ($json) {
         return $resp;
     } else {
         $ary = json_decode($resp, true);
         return $ary;
     }
 }