Sha256: c85cdbda09dbbb9db5096fc0053ab95da595e108d84affc8bfc4e61ebf4baf60

Contents?: true

Size: 1.09 KB

Versions: 30

Compression:

Stored size: 1.09 KB

Contents

module Octokit

  # Class for API Rate Limit info
  #
  # @!attribute [w] limit
  #   @return [Integer] Max tries per rate limit period
  # @!attribute [w] remaining
  #   @return [Integer] Remaining tries per rate limit period
  # @!attribute [w] resets_at
  #   @return [Time] Indicates when rate limit resets
  # @!attribute [w] resets_in
  #   @return [Integer] 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, 0].max
      end

      info
    end
  end
end

Version data entries

30 entries across 24 versions & 3 rubygems

Version Path
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/octokit-4.18.0/lib/octokit/rate_limit.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/octokit-4.18.0/lib/octokit/rate_limit.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/octokit-4.18.0/lib/octokit/rate_limit.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/rate_limit.rb
octokit-4.18.0 lib/octokit/rate_limit.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/octokit-4.16.0/lib/octokit/rate_limit.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/octokit-4.14.0/lib/octokit/rate_limit.rb
octokit-4.16.0 lib/octokit/rate_limit.rb
octokit-4.15.0 lib/octokit/rate_limit.rb
tdiary-5.1.0 vendor/bundle/gems/octokit-4.14.0/lib/octokit/rate_limit.rb
tdiary-5.0.13 vendor/bundle/gems/octokit-4.13.0/lib/octokit/rate_limit.rb
octokit-4.14.0 lib/octokit/rate_limit.rb
tdiary-5.0.12.1 vendor/bundle/gems/octokit-4.13.0/lib/octokit/rate_limit.rb
tdiary-5.0.11 vendor/bundle/gems/octokit-4.10.0/lib/octokit/rate_limit.rb
tdiary-5.0.11 vendor/bundle/gems/octokit-4.13.0/lib/octokit/rate_limit.rb
octokit-4.13.0 lib/octokit/rate_limit.rb
octokit-4.12.0 lib/octokit/rate_limit.rb
octokit-4.11.0 lib/octokit/rate_limit.rb
octokit-4.10.0 lib/octokit/rate_limit.rb
tdiary-5.0.9 vendor/bundle/gems/octokit-4.9.0/lib/octokit/rate_limit.rb