Sha256: eae3b0417cc8e09b55787672fecd10b2fefed7f8538891356a5d1b7342183595

Contents?: true

Size: 876 Bytes

Versions: 18

Compression:

Stored size: 876 Bytes

Contents

module Twitter
  class RateLimit
    attr_reader :attrs
    alias to_hash attrs

    # @return [Twitter::RateLimit]
    def initialize(attrs={})
      @attrs = attrs
    end

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

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

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

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

    # Update the attributes of a RateLimit
    #
    # @param attrs [Hash]
    # @return [Twitter::RateLimit]
    def update(attrs)
      @attrs.update(attrs)
      self
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
twitter-4.8.1 lib/twitter/rate_limit.rb
twitter-4.8.0 lib/twitter/rate_limit.rb
twitter-4.7.0 lib/twitter/rate_limit.rb
twitter-4.6.2 lib/twitter/rate_limit.rb
twitter-4.6.1 lib/twitter/rate_limit.rb
twitter-4.6.0 lib/twitter/rate_limit.rb
twitter-4.5.0 lib/twitter/rate_limit.rb
twitter-4.4.4 lib/twitter/rate_limit.rb
twitter-4.4.3 lib/twitter/rate_limit.rb
twitter-4.4.2 lib/twitter/rate_limit.rb
twitter-4.4.1 lib/twitter/rate_limit.rb
twitter-4.4.0 lib/twitter/rate_limit.rb
twitter-4.3.0 lib/twitter/rate_limit.rb
twitter-4.2.0 lib/twitter/rate_limit.rb
twitter-4.1.2 lib/twitter/rate_limit.rb
twitter-4.1.1 lib/twitter/rate_limit.rb
twitter-4.1.0 lib/twitter/rate_limit.rb
twitter-4.0.0 lib/twitter/rate_limit.rb