Sha256: 8a004b5ad9b3909d41341c24b4e24eff488f1accba85b7adc509b11dbda541fc

Contents?: true

Size: 1.05 KB

Versions: 21

Compression:

Stored size: 1.05 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'].to_i
        info.remaining = response.headers['X-RateLimit-Remaining'].to_i
        info.resets_at = Time.at(response.headers['X-RateLimit-Reset'].to_i)
        info.resets_in = (info.resets_at - Time.now).to_i
      end

      info
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
octokit-2.7.2 lib/octokit/rate_limit.rb
octokit-2.7.1 lib/octokit/rate_limit.rb
octokit-2.7.0 lib/octokit/rate_limit.rb
octokit-2.6.3 lib/octokit/rate_limit.rb
octokit-2.6.2 lib/octokit/rate_limit.rb
octokit-2.6.1 lib/octokit/rate_limit.rb
octokit-2.6.0 lib/octokit/rate_limit.rb
octokit-2.5.1 lib/octokit/rate_limit.rb
octokit-2.5.0 lib/octokit/rate_limit.rb
octokit-2.4.0 lib/octokit/rate_limit.rb
octokit-2.3.1 lib/octokit/rate_limit.rb
octokit-2.3.0 lib/octokit/rate_limit.rb
octokit-2.2.0 lib/octokit/rate_limit.rb
octokit-2.1.2 lib/octokit/rate_limit.rb
octokit-2.1.1 lib/octokit/rate_limit.rb
octokit-2.1.0 lib/octokit/rate_limit.rb
octokit-2.0.0 lib/octokit/rate_limit.rb
octokit-2.0.0.rc4 lib/octokit/rate_limit.rb
octokit-2.0.0.rc3 lib/octokit/rate_limit.rb
octokit-2.0.0.rc2 lib/octokit/rate_limit.rb