Skip to content

Instantly share code, notes, and snippets.

View hwjeremy's full-sized avatar

Hugh Jeremy hwjeremy

View GitHub Profile
@hwjeremy
hwjeremy / retrievePerformance.swift
Created August 5, 2018 04:41
Retrieve a Performance 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 Performance.retrieve(
session: session,
entity: starkIndustries,
startTime: Date(timeIntervalSinceNow: (-3600*24*10)),
endTime: Date(),
globalUnit: usd,
callback: { (error, performance) in
@hwjeremy
hwjeremy / retrievePosition.swift
Created August 5, 2018 04:37
Retrieve a Position 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 Position.retrieve(
session: session,
entity: starkIndustries,
globalUnit: usd,
callback: { (error, position) in
// position.assets, position.liabilities,
// and position.equities combine to give
@hwjeremy
hwjeremy / retrieveTree.swift
Last active August 5, 2018 04:42
Retrieve a Tree 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 Tree.retrieve(
session: session,
entity: starkIndustries,
globalUnit: usd,
callback: { (error: Error?, tree: Tree?) in {
// tree.accounts contains a hierachary of all
// Accounts in this entity, as either TreeNode
@hwjeremy
hwjeremy / deleteAccount.swift
Created August 5, 2018 04:25
Delete an Account 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 account.delete(
entryReplacement: cash,
callback: { (error) in
// A lack of error indicates the Account is a goner
})
@hwjeremy
hwjeremy / updateAccount.swift
Created August 5, 2018 04:20
Update an Account 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 account.update(
name: "Newly updated account name",
parent: nil,
type: account.type, // using the existing value
counterParty: nil,
colour: nil,
globalUnit: USD,
@hwjeremy
hwjeremy / deleteTransaction.swift
Created August 2, 2018 07:24
Delete a Transaction 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 transaction.delete( { (error, transaction) in
// It's gone! The returned transaction is in an
// .active = false state and is no longer used.
})
@hwjeremy
hwjeremy / updateTransaction.swift
Created August 2, 2018 07:17
Update a Transaction 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 transaction.update(
transactionTime: transaction.transactionTime,
description: "Some new description",
globalUnit: usd,
entries: transaction.entries,
callback { (error, transaction) in
// Woot! The returned Transaction instance
@hwjeremy
hwjeremy / retrieveLedger.swift
Last active July 30, 2018 10:38
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
@hwjeremy
hwjeremy / findCurrencyWithCode.swift
Created July 19, 2018 03:45
Find a specific currency in Amatino Swift - A double-entry accounting library for iOS & MacOS
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
guard let USD: GlobalUnit = currencies.findWith(code: "USD") else {
// .findWith() returns an optional. If we end up here, Amatino
// doesn't support a currency with the supplied code.
}
// Do cool stuff with our new currency
print("Loaded a currency! Name: \(USD.name)")
@hwjeremy
hwjeremy / retrieveGlobalUnits.swift
Last active July 19, 2018 03:43
Retrieve available currencies 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 GlobalUnitList.retrieve(
session: session,
callback: { (error: Error?, units: GlobalUnitsList?) in
guard error == nil else {
// Handle errors
}
guard currencies: GlobalUnitList = units else {