/** * Update the statistics * * @param array $headers */ protected function updateStats(array $headers) { Stats::set(Stats::CURRENT_LIMIT, $headers['X-RateLimit-Remaining']); Stats::set(Stats::TOTAL_LIMIT, $headers['X-RateLimit-Limit']); Stats::set(Stats::LIMIT_RESET_TIME, strtotime($headers['X-RateLimit-Reset'])); }
/** * Generate the stats data * * @return array|null */ public static function generateStats() { if (!Stats::hasData()) { return null; } $totalLimit = Stats::get(Stats::TOTAL_LIMIT); $resetTime = Stats::get(Stats::LIMIT_RESET_TIME); $limitReset = $resetTime < time(); $currentLimit = $limitReset ? $totalLimit : Stats::get(Stats::CURRENT_LIMIT); return ['totalLimit' => $totalLimit, 'currentLimit' => $currentLimit, 'limitReset' => $limitReset ? '' : Date::parse(Config::get('datimFormat'), $resetTime), 'canRun' => $currentLimit > 0 || $limitReset]; }