Repository navigation
Expand file tree
/
Copy pathRateLimit.php
More file actions
70 lines (59 loc) · 1.42 KB
/
Copy pathRateLimit.php
File metadata and controls
70 lines (59 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Github\Api;
use Github\Api\RateLimit\RateLimitResource;
/**
* Get rate limits.
*
* @link https://developer.github.com/v3/rate_limit/
*
* @author Jeff Finley <quickliketurtle@gmail.com>
*/
class RateLimit extends AbstractApi
{
/**
* @var RateLimitResource[]
*/
protected $resources = [];
/**
* 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;
}
}