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

#limit=(value) ⇒ Integer (writeonly)

Returns Max tries per rate limit period.

Returns:

  • (Integer)

    Max tries per rate limit period



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octokit/rate_limit.rb', line 16

class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
  # Get rate limit info from HTTP response
  #
  # @param response [#headers] HTTP response
  # @return [RateLimit]
  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
end

#remaining=(value) ⇒ Integer (writeonly)

Returns Remaining tries per rate limit period.

Returns:

  • (Integer)

    Remaining tries per rate limit period



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octokit/rate_limit.rb', line 16

class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
  # Get rate limit info from HTTP response
  #
  # @param response [#headers] HTTP response
  # @return [RateLimit]
  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
end

#resets_at=(value) ⇒ Time (writeonly)

Returns Indicates when rate limit resets.

Returns:

  • (Time)

    Indicates when rate limit resets



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octokit/rate_limit.rb', line 16

class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
  # Get rate limit info from HTTP response
  #
  # @param response [#headers] HTTP response
  # @return [RateLimit]
  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
end

#resets_in=(value) ⇒ Integer (writeonly)

Returns Number of seconds when rate limit resets.

Returns:

  • (Integer)

    Number of seconds when rate limit resets



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/octokit/rate_limit.rb', line 16

class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
  # Get rate limit info from HTTP response
  #
  # @param response [#headers] HTTP response
  # @return [RateLimit]
  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
end

Class Method Details

.from_response(response) ⇒ RateLimit

Get rate limit info from HTTP response

Parameters:

  • response (#headers)

    HTTP response

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
# 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