Sha256: 551b234e77767d52d5fbf3a2d059796b8819db99c11f49b22520e1fb5b5e31b1

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 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 https://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

9 entries across 9 versions & 1 rubygems

Version Path
octokit-3.5.2 lib/octokit/rate_limit.rb
octokit-3.4.2 lib/octokit/rate_limit.rb
octokit-3.4.1 lib/octokit/rate_limit.rb
octokit-3.4.0 lib/octokit/rate_limit.rb
octokit-3.3.1 lib/octokit/rate_limit.rb
octokit-3.3.0 lib/octokit/rate_limit.rb
octokit-3.2.0 lib/octokit/rate_limit.rb
octokit-3.1.2 lib/octokit/rate_limit.rb
octokit-3.1.0 lib/octokit/rate_limit.rb