Sha256: 52d056e3eaff6403c71cab3bf82221ed4848a4ddcc302b87744b991dd273b239
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
require 'twitter/enumerable' require 'twitter/rest/request' require 'twitter/utils' module Twitter class Cursor include Twitter::Enumerable include Twitter::Utils # @return [Hash] attr_reader :attrs alias_method :to_h, :attrs alias_method :to_hash, :to_h deprecate_alias :to_hsh, :to_hash # 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] # @return [Twitter::Cursor] def initialize(key, klass, request) @key = key.to_sym @klass = klass @client = request.client @request_method = request.verb @path = request.path @options = request.options @collection = [] self.attrs = request.perform end private # @return [Integer] def next_cursor @attrs[:next_cursor] || -1 end alias_method :next, :next_cursor # @return [Boolean] def last? next_cursor.zero? end # @return [Hash] def fetch_next_page response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(:cursor => next_cursor)).perform self.attrs = response end # @param attrs [Hash] # @return [Hash] def attrs=(attrs) @attrs = attrs @attrs.fetch(@key, []).each do |element| @collection << (@klass ? @klass.new(element) : element) end @attrs end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
twitter-5.15.0 | lib/twitter/cursor.rb |
twitter-5.14.0 | lib/twitter/cursor.rb |
twitter-5.13.0 | lib/twitter/cursor.rb |