File: rate_limit.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (52 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

module Octokit
  class Client
    # Methods for API rate limiting info
    #
    # @see https://developer.github.com/v3/#rate-limiting
    module RateLimit
      # Get rate limit info from last response if available
      # or make a new request to fetch rate limit
      #
      # @see https://developer.github.com/v3/rate_limit/#rate-limit
      # @return [Octokit::RateLimit] Rate limit info
      def rate_limit(_options = {})
        return rate_limit! if last_response.nil?

        Octokit::RateLimit.from_response(last_response)
      end
      alias ratelimit rate_limit

      # Get number of rate limted requests remaining
      #
      # @see https://developer.github.com/v3/rate_limit/#rate-limit
      # @return [Integer] Number of requests remaining in this period
      def rate_limit_remaining(_options = {})
        octokit_warn 'Deprecated: Please use .rate_limit.remaining'
        rate_limit.remaining
      end
      alias ratelimit_remaining rate_limit_remaining

      # Refresh rate limit info by making a new request
      #
      # @see https://developer.github.com/v3/rate_limit/#rate-limit
      # @return [Octokit::RateLimit] Rate limit info
      def rate_limit!(_options = {})
        get 'rate_limit'
        Octokit::RateLimit.from_response(last_response)
      end
      alias ratelimit! rate_limit!

      # Refresh rate limit info and get number of rate limted requests remaining
      #
      # @see https://developer.github.com/v3/rate_limit/#rate-limit
      # @return [Integer] Number of requests remaining in this period
      def rate_limit_remaining!(_options = {})
        octokit_warn 'Deprecated: Please use .rate_limit!.remaining'
        rate_limit!.remaining
      end
      alias ratelimit_remaining! rate_limit_remaining!
    end
  end
end