diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index a9b5454f714..851631cccf8 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -9,7 +9,7 @@ */ class ApiLimitExceedException extends RuntimeException { - public function __construct($limit, $code = 0, $previous = null) + public function __construct($limit = 5000, $code = 0, $previous = null) { parent::__construct('You have reached GitHub hour limit! Actual limit is: '. $limit, $code, $previous); } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 16457bd0683..f28f54bd9e2 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -47,7 +47,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $response = parent::request($path, $parameters, $httpMethod, $headers); $key = trim($this->options['base_url'].$path, '/'); - if ($response->isNotModified()) { + if (304 == $response->getStatusCode()) { return $this->getCache()->get($key); } @@ -64,7 +64,13 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', protected function createRequest($httpMethod, $url) { $request = parent::createRequest($httpMethod, $url); - $request->addHeader(sprintf('If-Modified-Since: %s', date('r', $this->getCache()->getModifiedSince($url)))); + + if ($modifiedAt = $this->getCache()->getModifiedSince($url)) { + $modifiedAt = new \DateTime('@'.$modifiedAt); + $modifiedAt->setTimezone(new \DateTimeZone('GMT')); + + $request->addHeader(sprintf('If-Modified-Since: %s GMT', $modifiedAt->format('l, d-M-y H:i:s'))); + } return $request; } diff --git a/lib/Github/HttpClient/Message/Response.php b/lib/Github/HttpClient/Message/Response.php index 35f2ada5264..c039ac4bae6 100644 --- a/lib/Github/HttpClient/Message/Response.php +++ b/lib/Github/HttpClient/Message/Response.php @@ -3,7 +3,6 @@ namespace Github\HttpClient\Message; use Buzz\Message\Response as BaseResponse; - use Github\Exception\ApiLimitExceedException; class Response extends BaseResponse @@ -55,23 +54,13 @@ public function getPagination() */ public function getApiLimit() { - $header = $this->getHeaderAttributes('X-RateLimit-Remaining'); + $header = $this->getHeader('X-RateLimit-Remaining'); if (!empty($header)) { $this->remainingCalls = $header; } if (null !== $this->remainingCalls && 1 > $this->remainingCalls) { - throw new ApiLimitExceedException($this->options['api_limit']); + throw new ApiLimitExceedException($this->getHeader('X-RateLimit-Limit')); } } - - /** - * Is not modified - * - * @return Boolean - */ - public function isNotModified() - { - return 304 === $this->getStatusCode(); - } }