1 | <?php namespace Vindi\Exceptions; |
||
10 | class RateLimitException extends Exception |
||
11 | { |
||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | protected $limit; |
||
16 | |||
17 | /** |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $reset; |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $remaining; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $retryAfter; |
||
31 | |||
32 | /** |
||
33 | * RateLimitException constructor. |
||
34 | * |
||
35 | * @param mixed $response API response. |
||
36 | */ |
||
37 | 4 | public function __construct($response) |
|
46 | |||
47 | /** |
||
48 | * Get first array value from specified header as integer. |
||
49 | * |
||
50 | * @param mixed $response API response. |
||
51 | * @param string $name Header name. |
||
52 | * |
||
53 | * @return int |
||
54 | */ |
||
55 | 4 | private function getHeaderValue($response, $name) |
|
65 | |||
66 | /** |
||
67 | * Maximum request number per minute. |
||
68 | * |
||
69 | * @return int |
||
70 | */ |
||
71 | 2 | public function getLimit() |
|
75 | |||
76 | /** |
||
77 | * Timestamp until there are new remaining requests. |
||
78 | * |
||
79 | * @return int |
||
80 | */ |
||
81 | 2 | public function getReset() |
|
85 | |||
86 | /** |
||
87 | * Remaining requests. |
||
88 | * |
||
89 | * @return int |
||
90 | */ |
||
91 | 2 | public function getRemaining() |
|
95 | |||
96 | /** |
||
97 | * When it's possible to make the next request. |
||
98 | * |
||
99 | * @return int |
||
100 | */ |
||
101 | 2 | public function getRetryAfter() |
|
105 | } |
||
106 |