Skip to content

Instantly share code, notes, and snippets.

@shalecraig
Created December 12, 2014 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalecraig/13abe9140ca72c9caf78 to your computer and use it in GitHub Desktop.
Save shalecraig/13abe9140ca72c9caf78 to your computer and use it in GitHub Desktop.

Pre-#125

String lastId = null;
while (true) {
    BalanceTransactionCollection balanceTransactions =
            BalanceTransaction.all(
                    Collections.<String, Object>singletonMap("starting_after", lastId)
            );
    for (BalanceTransaction tx : balanceTransactions.getData()) {
        // ..
        lastId = tx.getId();
    }
    if (!balanceTransactions.getHasMore()) {
        break;
    }
}

Without Pagination:

String lastId = null;
while (true) {
    BalanceTransactionCollection balanceTransactions =
            BalanceTransaction.all(
                    Collections.<String, Object>singletonMap("starting_after", lastId)
            );
    for (BalanceTransaction tx : balanceTransactions) {
        // ..
        lastId = tx.getId();
    }
    if (!balanceTransactions.getHasMore()) {
        break;
    }
}

With pagination:

BalanceTransactionCollection balanceTransactions = BalanceTransaction.all(null);
for (BalanceTransaction tx : balanceTransactions) {
    // ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment