Sha256: 16ffbe801639f8db48c7acf14ac9a03cee93bac9d743725b5c29497e8c2963e4

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Octokit

  # Class for API Rate Limit info
  #
  # @!attribute [w] limit
  #   @return [Fixnum] Max tries per rate limit period
  # @!attribute [w] remaining
  #   @return [Fixnum] Remaining tries per rate limit period
  # @!attribute [w] resets_at
  #   @return [Time] Indicates when rate limit resets
  # @!attribute [w] resets_in
  #   @return [Fixnum] Number of seconds when rate limit resets
  #
  # @see http://developer.github.com/v3/#rate-limiting
  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
      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
      end

      info
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
octokit-3.0.0 lib/octokit/rate_limit.rb
octokit-3.0.0.pre lib/octokit/rate_limit.rb