class GoogleContactsApi::ResultSet

Base class for GroupSet and ContactSet that generically represents a set of results.

Attributes

api[R]
items_per_page[RW]
parsed[RW]
start_index[RW]
total_results[RW]

Public Class Methods

new(response_body, api = nil) click to toggle source

Initialize a new ResultSet from the response, with the given GoogleContacts::Api object if specified.

# File lib/google_contacts_api/result_set.rb, line 13
def initialize(response_body, api = nil)
  @api = api
  @parsed = Hashie::Mash.new(JSON.parse(response_body))
  @total_results = @parsed.feed["openSearch$totalResults"]["$t"].to_i
  @start_index = @parsed.feed["openSearch$startIndex"]["$t"].to_i
  @items_per_page = @parsed.feed["openSearch$itemsPerPage"]["$t"].to_i
  @results = []
end

Public Instance Methods

each() { |x| ... } click to toggle source

Yields to block for each result. Returns an Enumerator if no block is passed.

# File lib/google_contacts_api/result_set.rb, line 24
def each
  return to_enum(:each) unless block_given?
  @results.each { |x| yield x }
end
has_more?() click to toggle source

Return true if there are more results with the same parameters you used

# File lib/google_contacts_api/result_set.rb, line 31
def has_more?
  # 1-based indexing
  @start_index - 1 + @items_per_page <= @total_results
end