Class: Octokit::RateLimit

Inherits:
Struct
  • Object
show all
Defined in:
lib/octokit/rate_limit.rb

Overview

Class for API Rate Limit info

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#limitObject

Returns the value of attribute limit


15
16
17
# File 'lib/octokit/rate_limit.rb', line 15

def limit
  @limit
end

#remainingObject

Returns the value of attribute remaining


15
16
17
# File 'lib/octokit/rate_limit.rb', line 15

def remaining
  @remaining
end

#resets_atObject

Returns the value of attribute resets_at


15
16
17
# File 'lib/octokit/rate_limit.rb', line 15

def resets_at
  @resets_at
end

#resets_inObject

Returns the value of attribute resets_in


15
16
17
# File 'lib/octokit/rate_limit.rb', line 15

def resets_in
  @resets_in
end

Class Method Details

.from_response(response) ⇒ RateLimit

Get rate limit info from HTTP response


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/octokit/rate_limit.rb', line 21

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

  info
end