123456789_123456789_123456789_123456789_123456789_

Class: Octokit::RateLimit

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: lib/octokit/rate_limit.rb

Overview

Class for API Rate Limit info

Class Method Summary

Class Method Details

.from_response(response) ⇒ RateLimit

Get rate limit info from HTTP response

Parameters:

  • response (#headers)

    HTTP response

[ GitHub ]

  
# File 'lib/octokit/rate_limit.rb', line 21

def self.from_response(response)
  info = new
  headers = response.headers if response.respond_to?(:headers) && !response.headers.nil?
  headers ||= response.response_headers if response.respond_to?(:response_headers) && !response.response_headers.nil?
  if headers
    info.limit = (headers['X-RateLimit-Limit'] || 1).to_i
    info.remaining = (headers['X-RateLimit-Remaining'] || 1).to_i
    info.resets_at = Time.at((headers['X-RateLimit-Reset'] || Time.now).to_i)
    info.resets_in = [(info.resets_at - Time.now).to_i, 0].max
  end

  info
end