class HomeAway::API::Paginator
Public Class Methods
new(client, hashie, auto_pagination=false)
click to toggle source
@private
# File lib/homeaway/api/paginator.rb, line 22 def initialize(client, hashie, auto_pagination=false) @hashie = hashie @client = client @auto_pagination = auto_pagination end
Public Instance Methods
each() { |entity| ... }
click to toggle source
supply a block that expects a single parameter to iterate through this paginator
# File lib/homeaway/api/paginator.rb, line 29 def each(&block) if @auto_pagination first_hashie = @hashie.clone while true cur_hits = entries.clone cur_hits.each do |entity| if block_given? block.call entity else yield entity end end if @hashie.nextPage && @hashie.page < 300 begin next_page! rescue HomeAway::API::Errors::RequestedRangeNotSatisfiableError # we have a max page limit # reset me to the first so that I can be iterated over again @hashie = first_hashie break end else # reset me to the first so that I can be iterated over again @hashie = first_hashie break end end else entries.each do |entity| if block_given? block.call entity else yield entity end end end end
entries()
click to toggle source
@return [Array] the current page of results as an array of entities
# File lib/homeaway/api/paginator.rb, line 125 def entries entries = @hashie['entries'] ||= nil entries.map { |entry| HomeAway::API::Response.new(entry) } end
Also aliased as: hits
method_missing(name, *args, &block)
click to toggle source
@private
Calls superclass method
# File lib/homeaway/api/paginator.rb, line 116 def method_missing(name, *args, &block) if @hashie.respond_to? name @hashie.send name, *args, &block else super end end
next_page()
click to toggle source
@return [HomeAway::API::Paginator] a paginator object that has the next page of results
# File lib/homeaway/api/paginator.rb, line 76 def next_page return nil unless next_page? next_hashie = @client.get(*parse_url(nextPage)) self.class.new(@client, next_hashie, @auto_pagination) end
next_page!()
click to toggle source
updates this paginator to have the next page of results in place @return [Boolean] true if successful
# File lib/homeaway/api/paginator.rb, line 84 def next_page! return false unless next_page? @hashie = @client.get(*parse_url(nextPage)) true end
next_page?()
click to toggle source
@return [Boolean] does this paginator have another page?
# File lib/homeaway/api/paginator.rb, line 91 def next_page? @hashie.has_key? 'nextPage' end
previous_page()
click to toggle source
@return [HomeAway::API::Paginator] a paginator object that has the previous page of results
# File lib/homeaway/api/paginator.rb, line 96 def previous_page return nil unless previous_page? prev_hashie = @client.get(*parse_url(prevPage)) self.class.new(@client, prev_hashie, @auto_pagination) end
previous_page!()
click to toggle source
updates this paginator to have the previous page of results in place @return [Boolean] true if successful
# File lib/homeaway/api/paginator.rb, line 104 def previous_page! return false unless previous_page? @hashie = @client.get(*parse_url(prevPage)) true end
previous_page?()
click to toggle source
@return [Boolean] does this paginator have previous page?
# File lib/homeaway/api/paginator.rb, line 111 def previous_page? @hashie.has_key? 'prevPage' end
size()
click to toggle source
@return [Integer] the size of this paginator
# File lib/homeaway/api/paginator.rb, line 68 def size return @hashie['size'] if @hashie.has_key? 'size' 0 end
Also aliased as: length
Private Instance Methods
parse_url(input)
click to toggle source
# File lib/homeaway/api/paginator.rb, line 134 def parse_url(input) uri = URI.parse(input) return uri.path, CGI.parse(uri.query) end