Skip to content

Instantly share code, notes, and snippets.

@assembler
Last active June 9, 2016 12:43
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