Skip to content

Instantly share code, notes, and snippets.

Hugh Jeremy hwjeremy

Block or report user

Report or block hwjeremy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hwjeremy
hwjeremy / retrievePerformance.swift
Created Aug 5, 2018
Retrieve a Performance in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrievePerformance.swift
// 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 Aug 5, 2018
Retrieve a Position in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrievePosition.swift
// 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 Aug 5, 2018
Retrieve a Tree in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveTree.swift
// 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 Aug 5, 2018
Delete an Account in Amatino Swift - A double-entry accounting library for iOS & MacOS
View deleteAccount.swift
// 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 Aug 5, 2018
Update an Account in Amatino Swift - A double-entry accounting library for iOS & MacOS
View updateAccount.swift
// 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 Aug 2, 2018
Delete a Transaction in Amatino Swift - A double-entry accounting library for iOS & MacOS
View deleteTransaction.swift
// 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 Aug 2, 2018
Update a Transaction in Amatino Swift - A double-entry accounting library for iOS & MacOS
View updateTransaction.swift
// 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 Jul 30, 2018
Retrieve a Ledger in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveLedger.swift
// 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 Jul 19, 2018
Find a specific currency in Amatino Swift - A double-entry accounting library for iOS & MacOS
View findCurrencyWithCode.swift
// 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 Jul 19, 2018
Retrieve available currencies in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveGlobalUnits.swift
// 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 {
You can’t perform that action at this time.