class Twitter::SearchResults
Attributes
attrs[R]
@return [Hash]
rate_limit[R]
@return [Hash]
to_h[R]
@return [Hash]
to_hash[R]
@return [Hash]
Public Class Methods
new(request)
click to toggle source
Initializes a new SearchResults
object
@param request [Twitter::REST::Request] @return [Twitter::SearchResults]
# File lib/twitter/search_results.rb, line 20 def initialize(request) @client = request.client @request_method = request.verb @path = request.path @options = request.options @collection = [] self.attrs = request.perform end
Private Instance Methods
attrs=(attrs)
click to toggle source
@param attrs [Hash] @return [Hash]
# File lib/twitter/search_results.rb, line 58 def attrs=(attrs) @attrs = attrs @attrs.fetch(:statuses, []).collect do |tweet| @collection << Tweet.new(tweet) end @attrs end
fetch_next_page()
click to toggle source
@return [Hash]
# File lib/twitter/search_results.rb, line 50 def fetch_next_page response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(next_page)) self.attrs = response.perform @rate_limit = response.rate_limit end
last?()
click to toggle source
@return [Boolean]
# File lib/twitter/search_results.rb, line 32 def last? !next_page? end
next_page()
click to toggle source
Returns a Hash of query parameters for the next result in the search
@note Returned Hash can be merged into the previous search options list to easily access the next page. @return [Hash] The parameters needed to fetch the next page.
# File lib/twitter/search_results.rb, line 45 def next_page query_string_to_hash(@attrs[:search_metadata][:next_results]) if next_page? end
next_page?()
click to toggle source
@return [Boolean]
# File lib/twitter/search_results.rb, line 37 def next_page? !!@attrs[:search_metadata][:next_results] unless @attrs[:search_metadata].nil? end
query_string_to_hash(query_string)
click to toggle source
Converts query string to a hash
@param query_string [String] The query string of a URL. @return [Hash] The query string converted to a hash (with symbol keys). @example Convert query string to a hash
query_string_to_hash("foo=bar&baz=qux") #=> {:foo=>"bar", :baz=>"qux"}
# File lib/twitter/search_results.rb, line 72 def query_string_to_hash(query_string) query = CGI.parse(URI.parse(query_string).query) Hash[query.collect { |key, value| [key.to_sym, value.first] }] end