class Starwars::Cursor
A pagination container for starwars
Public Instance Methods
Yields the subsequent page responses to a given block @yieldparam [Starwars::Base] response @return [Enumerable, nil] @example fetch the next page
Starwars::Planet.fetch_all.each_page{|page| p page.items.map(&:name)} Starwars::Planet.fetch_all.each{|page| p page.items.map(&:name)} Starwars::Planet.fetch_all.each_with_index{|page, index| p page.items.map(&:name) }
@api public
# File lib/starwars/cursor.rb, line 93 def each_page return to_enum(__callee__) unless block_given? yield(next_page) until last_page? end
Checks wheather this is the last page @return [Boolean] @example are we at the last page?
Starwars::Planet.fetch_all.last_page?
@api public
# File lib/starwars/cursor.rb, line 59 def last_page? !next_page? end
Returns the next page @return [Starwars::Base] @example fetch the next page
page = Starwars::Planet.fetch_all page.next_page
@api public
# File lib/starwars/cursor.rb, line 78 def next_page return if last_page? perform_request end
Checks wheather this there is more pages @return [Boolean] @example do we have a next page?
Starwars::Planet.fetch_all.next_page?
@api public
# File lib/starwars/cursor.rb, line 68 def next_page? !self.next.nil? end
A wrapper to get the pages count from the api @return [Integer] @example get the total number of pages
Starwars::Planet.fetch_all.number_of_pages
@example get the total number of pages
Starwars::Starship.fetch_all.number_of_pages
@api public
# File lib/starwars/cursor.rb, line 39 def number_of_pages self[:count] end
A wrapper to get the results within a page @note This wrapper is needed to define the items alias method @return [Array] @example Return the items array within the page
Starwars::Planet.fetch_all.results Starwars::Planet.fetch_all.items
@api public
# File lib/starwars/cursor.rb, line 50 def results self[:results] end