class Twitter::Cursor
Attributes
attrs[R]
@return [Hash]
to_h[R]
@return [Hash]
to_hash[R]
@return [Hash]
Public Class Methods
new(key, klass, request, limit = nil)
click to toggle source
Initializes a new Cursor
@param key [String, Symbol] The key to fetch the data from the response @param klass [Class] The class to instantiate objects in the response @param request [Twitter::REST::Request] @param limit [Integer] After reaching the limit, we stop fetching next page @return [Twitter::Cursor]
# File lib/twitter/cursor.rb, line 21 def initialize(key, klass, request, limit = nil) @key = key.to_sym @klass = klass @client = request.client @request_method = request.verb @path = request.path @options = request.options @collection = [] @limit = limit self.attrs = request.perform end
Private Instance Methods
attrs=(attrs)
click to toggle source
@param attrs [Hash] @return [Hash]
# File lib/twitter/cursor.rb, line 62 def attrs=(attrs) @attrs = attrs @attrs.fetch(@key, []).each do |element| @collection << (@klass ? @klass.new(element) : element) end @attrs end
fetch_next_page()
click to toggle source
@return [Hash]
# File lib/twitter/cursor.rb, line 55 def fetch_next_page response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(cursor: next_cursor)).perform self.attrs = response end
last?()
click to toggle source
@return [Boolean]
# File lib/twitter/cursor.rb, line 42 def last? return false if next_cursor.is_a?(String) return true if next_cursor.nil? next_cursor.zero? end
next_cursor()
click to toggle source
@return [Integer]
# File lib/twitter/cursor.rb, line 36 def next_cursor @attrs[:next_cursor] end
Also aliased as: next
reached_limit?()
click to toggle source
@return [Boolean]
# File lib/twitter/cursor.rb, line 50 def reached_limit? @limit && @limit <= attrs[@key].count end