module MikuTwitter::RateLimiting

API残数

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File core/lib/mikutwitter/rate_limiting.rb, line 28
def initialize(*args)
  super
  @api_remain = {}            # resource_name => Resource
end

Public Instance Methods

ratelimit(resource_name) click to toggle source
# File core/lib/mikutwitter/rate_limiting.rb, line 33
def ratelimit(resource_name)
  type_strict resource_name => String
  @api_remain[resource_name] end
ratelimit_rewind(resource_name, response = nil) click to toggle source

APIリクエスト制限の残数を返す(OAuthトークン毎) response にHTTPRequestを設定すると、その数が設定される

# File core/lib/mikutwitter/rate_limiting.rb, line 39
def ratelimit_rewind(resource_name, response = nil)
  type_strict resource_name => :to_s
  resource_name = resource_name.to_s.freeze
  if response and response['X-Rate-Limit-Reset']
    time = Time.at(response['X-Rate-Limit-Reset'].to_i)
    @api_remain[resource_name] = Resource.new(response['X-Rate-Limit-Limit'].to_i,
                                              response['X-Rate-Limit-Remaining'].to_i,
                                              time,
                                              resource_name) end
  @api_remain[resource_name] end