示例#1
0
 /**
  * @return Github\ApiException|static
  */
 public function toException()
 {
     if ($this->httpCode < 300 && $this->content !== FALSE) {
         return NULL;
     }
     $error = isset($this->info['error']) ? $this->info['error'] : NULL;
     $e = new Github\RequestFailedException($error ? $error['message'] : '', $error ? (int) $error['code'] : 0);
     if (!$this->hasRemainingRateLimit()) {
         $e = new Github\ApiLimitExceedException("The API rate limit of {$this->getRateLimit()} has been exceeded. See https://developer.github.com/v3/#rate-limiting for details.", $e);
     } elseif ($this->content && $this->isJson()) {
         $response = $this->toArray();
         if ($this->httpCode === 400) {
             $e = new Github\BadRequestException(isset($response['message']) ? $response['message'] : $this->content, $this->httpCode, $e);
         } elseif ($this->httpCode === 422 && isset($response['errors'])) {
             $e = new Github\ValidationFailedException('Validation Failed: ' . self::parseErrors($response), $this->httpCode, $e);
         } elseif ($this->httpCode === 404 && isset($response['message'])) {
             $e = new Github\UnknownResourceException($response['message'] . ': ' . $this->request->getUrl(), $this->httpCode, $e);
         } elseif (isset($response['message'])) {
             $e = new Github\ApiException($response['message'], $this->httpCode, $e);
         }
     }
     return $e->bindResponse($this->request, $this);
 }
示例#2
0
 /**
  * @param Request $request
  * @return resource
  */
 protected function buildCurlResource(Request $request)
 {
     $ch = curl_init((string) $request->getUrl());
     $options = $this->curlOptions;
     $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
     // configuring a POST request
     if ($request->getPost()) {
         $options[CURLOPT_POSTFIELDS] = $request->getPost();
     }
     if ($request->isHead()) {
         $options[CURLOPT_NOBODY] = TRUE;
     } elseif ($request->isGet()) {
         $options[CURLOPT_HTTPGET] = TRUE;
     }
     // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
     // for 2 seconds if the server does not support this header.
     $options[CURLOPT_HTTPHEADER]['Expect'] = '';
     $tmp = array();
     foreach ($request->getHeaders() + $options[CURLOPT_HTTPHEADER] as $name => $value) {
         $tmp[] = trim("{$name}: {$value}");
     }
     $options[CURLOPT_HTTPHEADER] = $tmp;
     // execute request
     curl_setopt_array($ch, $options);
     $this->onRequest($request, $options);
     return $ch;
 }
示例#3
0
文件: Panel.php 项目: runt18/Github-1
 /**
  * @param Api\Request $request
  * @param array $options
  */
 public function begin(Api\Request $request, $options = array())
 {
     $url = $request->getUrl();
     $url->setQuery('');
     $this->calls[spl_object_hash($request)] = (object) array('url' => (string) $url, 'params' => $request->getParameters(), 'options' => self::toConstantNames($options), 'result' => NULL, 'exception' => NULL, 'info' => array(), 'time' => 0);
 }