Class: Twitter::Cursor

### Home Classes Methods

### In Files

- lib/twitter/cursor.rb

### Parent

Object

### Methods

- ::from_response
- ::new
- #all
- #each
- #first
- #first?
- #last
- #last?
- #next
- #next_cursor
- #previous
- #previous_cursor

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- Twitter
- Twitter::API
- Twitter::API::Arguments
- Twitter::API::DirectMessages
- Twitter::API::Favorites
- Twitter::API::FriendsAndFollowers
- Twitter::API::Help
- Twitter::API::Lists
- Twitter::API::PlacesAndGeo
- Twitter::API::SavedSearches
- Twitter::API::Search
- Twitter::API::SpamReporting
- Twitter::API::SuggestedUsers
- Twitter::API::Timelines
- Twitter::API::Trends
- Twitter::API::Tweets
- Twitter::API::Undocumented
- Twitter::API::Users
- Twitter::API::Utils
- Twitter::Action
- Twitter::Action::Favorite
- Twitter::Action::Follow
- Twitter::Action::ListMemberAdded
- Twitter::Action::Mention
- Twitter::Action::Reply
- Twitter::Action::Retweet
- Twitter::Action::Status
- Twitter::Action::Tweet
- Twitter::ActionFactory
- Twitter::Base
- Twitter::BasicUser
- Twitter::Client
- Twitter::Configurable
- Twitter::Configuration
- Twitter::Creatable
- Twitter::Cursor
- Twitter::Default
- Twitter::DirectMessage
- Twitter::Entity
- Twitter::Entity::Hashtag
- Twitter::Entity::Url
- Twitter::Entity::UserMention
- Twitter::Error
- Twitter::Error::AlreadyFavorited
- Twitter::Error::AlreadyRetweeted
- Twitter::Error::BadGateway
- Twitter::Error::BadRequest
- Twitter::Error::ClientError
- Twitter::Error::ConfigurationError
- Twitter::Error::DecodeError
- Twitter::Error::EnhanceYourCalm
- Twitter::Error::Forbidden
- Twitter::Error::GatewayTimeout
- Twitter::Error::IdentityMapKeyError
- Twitter::Error::InternalServerError
- Twitter::Error::NotAcceptable
- Twitter::Error::NotFound
- Twitter::Error::RateLimited
- Twitter::Error::ServerError
- Twitter::Error::ServiceUnavailable
- Twitter::Error::TooManyRequests
- Twitter::Error::Unauthorized
- Twitter::Error::UnprocessableEntity
- Twitter::Exceptable
- Twitter::Factory
- Twitter::Geo
- Twitter::Geo::Point
- Twitter::Geo::Polygon
- Twitter::GeoFactory
- Twitter::Identity
- Twitter::IdentityMap
- Twitter::Language
- Twitter::List
- Twitter::Media
- Twitter::Media::Photo
- Twitter::MediaFactory
- Twitter::Metadata
- Twitter::OEmbed
- Twitter::Place
- Twitter::ProfileBanner
- Twitter::RateLimit
- Twitter::Relationship
- Twitter::Request
- Twitter::Request::MultipartWithFile
- Twitter::Response
- Twitter::Response::ParseJson
- Twitter::Response::RaiseError
- Twitter::SavedSearch
- Twitter::SearchResults
- Twitter::Settings
- Twitter::Size
- Twitter::SourceUser
- Twitter::Status
- Twitter::Suggestion
- Twitter::TargetUser
- Twitter::Trend
- Twitter::Tweet
- Twitter::User
- Twitter::Version
- Enumerable
- Kernel

No matching classes.

# Twitter::Cursor

### Attributes

attrs[R]
collection[R]
to_hash[R]

### Public Class Methods

from_response(response, collection_name, klass, client, method_name, method_options) click to toggle source

Initializes a new Cursor object

@param response [Hash] @param collection_name [String, Symbol] The name of the method to return the collection @param klass [Class] The class to instantiate object in the collection @param client [Twitter::Client] @param method_name [String, Symbol] @param method_options [Hash] @return [Twitter::Cursor]

    # File lib/twitter/cursor.rb, line 18
    def self.from_response(response, collection_name, klass, client, method_name, method_options)
      new(response[:body], collection_name, klass, client, method_name, method_options)
    end

new(attrs, collection_name, klass, client, method_name, method_options) click to toggle source

Initializes a new Cursor

@param attrs [Hash] @param collection_name [String, Symbol] The name of the method to return the collection @param klass [Class] The class to instantiate object in the collection @param client [Twitter::Client] @param method_name [String, Symbol] @param method_options [Hash] @return [Twitter::Cursor]

    # File lib/twitter/cursor.rb, line 31
    def initialize(attrs, collection_name, klass, client, method_name, method_options)
      @attrs = attrs
      @client = client
      @method_name = method_name
      @method_options = method_options
      @collection = Array(attrs[collection_name.to_sym]).map do |item|
        if klass
          klass.fetch_or_new(item)
        else
          item
        end
      end
      singleton_class.class_eval do
        alias_method(collection_name.to_sym, :collection)
      end
    end

### Public Instance Methods

all(collection=collection, cursor=next_cursor) click to toggle source

@param collection [Array] @param cursor [Integer] @return [Array]

    # File lib/twitter/cursor.rb, line 51
    def all(collection=collection, cursor=next_cursor)
      cursor = @client.send(@method_name.to_sym, @method_options.merge(:cursor => cursor))
      collection += cursor.collection
      cursor.last? ? collection.flatten : all(collection, cursor.next_cursor)
    end

each() click to toggle source

@return [Enumerable]

    # File lib/twitter/cursor.rb, line 58
    def each
      all(collection, next_cursor).each do |element|
        yield element
      end
    end

first() click to toggle source
Alias for: first?
first?() click to toggle source

@return [Boolean]

    # File lib/twitter/cursor.rb, line 75
    def first?
      previous_cursor.zero?
    end

Also aliased as: first
last() click to toggle source
Alias for: last?
last?() click to toggle source

@return [Boolean]

    # File lib/twitter/cursor.rb, line 81
    def last?
      next_cursor.zero?
    end

Also aliased as: last
next() click to toggle source
Alias for: next_cursor
next_cursor() click to toggle source

    # File lib/twitter/cursor.rb, line 64
    def next_cursor
      @attrs[:next_cursor] || -1
    end

Also aliased as: next
previous() click to toggle source
Alias for: previous_cursor
previous_cursor() click to toggle source

    # File lib/twitter/cursor.rb, line 69
    def previous_cursor
      @attrs[:previous_cursor]
    end

Also aliased as: previous

[Validate]

Generated with the Darkfish Rdoc Generator 2.