Class: Twitter::Cursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Utils
Defined in:
lib/twitter/cursor.rb

Overview

Represents a cursor for paginating through Twitter API responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Methods included from Enumerable

#each

Constructor Details

#initialize(key, klass, request, limit = nil) ⇒ Twitter::Cursor

Initializes a new Cursor

Examples:

cursor = Twitter::Cursor.new(:users, Twitter::User, request)

Parameters:

  • key (String, Symbol)

    The key to fetch the data from the response

  • klass (Class)

    The class to instantiate objects in the response

  • request (Twitter::REST::Request)
  • limit (Integer) (defaults to: nil)

    After reaching the limit, we stop fetching next page



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/twitter/cursor.rb', line 45

def initialize(key, klass, request, limit = nil)
  @key = key
  @klass = klass
  @client = request.client
  @request_method = request.verb
  @path = request.path
  @options = request.options
  @collection = []
  @limit = limit
  self.attrs = request.perform
end

Instance Attribute Details

#attrsHash Also known as: to_h

The raw response attributes

Examples:

cursor.attrs # => {users: [...], next_cursor: 123}

Returns:

  • (Hash)


17
18
19
# File 'lib/twitter/cursor.rb', line 17

def attrs
  @attrs
end