Sha256: 4302282bf444e9707075407ea9fd8f2ada9972077716ecfe82cc8a2e291129c8

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

module Nearmiss
  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 [Nearmiss::RateLimit] Rate limit info
      def rate_limit(options = {})
        return rate_limit! if last_response.nil?

        Nearmiss::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 [Fixnum] Number of requests remaining in this period
      def rate_limit_remaining(options = {})
        nearmiss_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
      #
      # @return [Nearmiss::RateLimit] Rate limit info
      def rate_limit!(options = {})
        get "rate_limit"
        Nearmiss::RateLimit.from_response(last_response)
      end
      alias ratelimit! rate_limit!

      # Refresh rate limit info and get number of rate limted requests remaining
      #
      # @return [Fixnum] Number of requests remaining in this period
      def rate_limit_remaining!(options = {})
        nearmiss_warn "Deprecated: Please use .rate_limit!.remaining"
        rate_limit!.remaining
      end
      alias ratelimit_remaining! rate_limit_remaining!

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nearmiss-ruby-1.0.4 lib/nearmiss-ruby/client/rate_limit.rb
nearmiss-ruby-1.0.3 lib/nearmiss-ruby/client/rate_limit.rb
nearmiss-ruby-1.0.2 lib/nearmiss-ruby/client/rate_limit.rb
nearmiss-ruby-1.0.1 lib/nearmiss-ruby/client/rate_limit.rb
nearmiss-ruby-1.0.0 lib/nearmiss-ruby/client/rate_limit.rb