Skip to content

Instantly share code, notes, and snippets.

@hwjeremy
Last active July 30, 2018 10:38
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 hwjeremy/08cc1adfaf763e694370edc2bb923cee to your computer and use it in GitHub Desktop.
Save hwjeremy/08cc1adfaf763e694370edc2bb923cee to your computer and use it in GitHub Desktop.
Retrieve a Ledger in Amatino Swift - A double-entry accounting library for iOS & MacOS
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Ledger.retrieve(
session: session,
entity: starkIndustries,
account: cashAccount,
callback: { (error: Error?, balance: Balance?) in
guard error == nil else {
// Handle error, e.g. 404 account not found, 403
// you are not authorised to view the account
}
guard let cashLedger: Ledger = ledger else {
// Should never happen, but practicing safe nil
// unwrapping is good feng shui
}
// Do cool stuff with cashLedger. For example, we can
// iterate over all the LedgerRows it contains:
for line in cashLedger {
print('Running balance: (\line.balance)')
}
// Ledgers are paginated in batches of 500 rows. To
// get the next 500 rows, we call .nextPage():
try! cashLedger.nextPage() { (error, rows) in
guard let newRows: [LedgerRow] = rows else {
// Handle errors
}
for line in newRows {
print('Running balance: (\line.balance)')
}
}
// The newly retrieved rows are now available in
// the original `cashLedger` as well.
})
@hwjeremy
Copy link
Author

The parameters passed to Ledger.retrieve() may be found in the following gists:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment