Sha256: 3c74388103c82084697c8dab16bc2e463073b855bda65be6d771c91a020fd54d

Contents?: true

Size: 680 Bytes

Versions: 4

Compression:

Stored size: 680 Bytes

Contents

require 'memoizable'

module Twitter
  class RateLimit < Twitter::Base
    include Memoizable

    # @return [Integer]
    def limit
      limit = @attrs['x-rate-limit-limit']
      limit.to_i if limit
    end
    memoize :limit

    # @return [Integer]
    def remaining
      remaining = @attrs['x-rate-limit-remaining']
      remaining.to_i if remaining
    end
    memoize :remaining

    # @return [Time]
    def reset_at
      reset = @attrs['x-rate-limit-reset']
      Time.at(reset.to_i) if reset
    end
    memoize :reset_at

    # @return [Integer]
    def reset_in
      [(reset_at - Time.now).ceil, 0].max if reset_at
    end
    alias retry_after reset_in
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter-6.1.0 lib/twitter/rate_limit.rb
twitter-6.0.0 lib/twitter/rate_limit.rb
twitter-5.17.0 lib/twitter/rate_limit.rb
twitter-5.16.0 lib/twitter/rate_limit.rb