Retrieve a Ledger in Amatino Swift - A double-entry accounting library for iOS & MacOS
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
// 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. | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The parameters passed to
Ledger.retrieve()
may be found in the following gists:session
- Create SessionstarkIndustries
- Retrieve EntitycashAccount
is an example of an Account created using the technique exemplified in Create Account.