Last active
June 9, 2016 12:43
-
-
Save assembler/99b399ec4d62a3e175f97660e34f5e2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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