mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-18 05:42:41 +09:00
Update composer dependencies
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Github\Api;
|
||||
|
||||
use Github\Api\RateLimit\RateLimitResource;
|
||||
|
||||
/**
|
||||
* Get rate limits.
|
||||
*
|
||||
@@ -12,36 +14,93 @@ namespace Github\Api;
|
||||
class RateLimit extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* Get rate limits.
|
||||
* @var RateLimitResource[]
|
||||
*/
|
||||
protected $resources = [];
|
||||
|
||||
/**
|
||||
* Get rate limits data in an array.
|
||||
*
|
||||
* @deprecated since 2.11.0 Use `->getResources()` instead
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRateLimits()
|
||||
{
|
||||
return $this->get('/rate_limit');
|
||||
return $this->fetchLimits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rate limit resource objects.
|
||||
*
|
||||
* @return RateLimitResource[]
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
$this->fetchLimits();
|
||||
|
||||
return $this->resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rate limit resource object by the given name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return RateLimitResource|false
|
||||
*/
|
||||
public function getResource($name)
|
||||
{
|
||||
// Fetch once per instance
|
||||
if (empty($this->resources)) {
|
||||
$this->fetchLimits();
|
||||
}
|
||||
|
||||
if (!isset($this->resources[$name])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->resources[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data directly from the GitHub API endpoint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function fetchLimits()
|
||||
{
|
||||
$result = $this->get('/rate_limit') ?: [];
|
||||
|
||||
// Assemble Limit instances
|
||||
foreach ($result['resources'] as $resourceName => $resource) {
|
||||
$this->resources[$resourceName] = new RateLimitResource($resourceName, $resource);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get core rate limit.
|
||||
*
|
||||
* @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCoreLimit()
|
||||
{
|
||||
$response = $this->getRateLimits();
|
||||
|
||||
return $response['resources']['core']['limit'];
|
||||
return $this->getResource('core')->getLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search rate limit.
|
||||
*
|
||||
* @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSearchLimit()
|
||||
{
|
||||
$response = $this->getRateLimits();
|
||||
|
||||
return $response['resources']['search']['limit'];
|
||||
return $this->getResource('search')->getLimit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user