Skip to content

Instantly share code, notes, and snippets.

@assembler assembler/paginate.rb
Last active Jun 9, 2016

Embed
What would you like to do?
def paginate
return enum_for(:paginate) unless block_given?
page = 0
page_count = nil
partners = []
loop do
response = fetch_all(page)
page_count ||= (response['partners_count'].to_f / PARTNERS_PER_PAGE)
yield response["partners"]
break if page >= page_count
page += 1
end
end
client.paginate.lazy.take(3).flatten # takes first 3 pages of partners
client.paginate.each { |parnters| ... } # takes all partners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.