Skip to content

Instantly share code, notes, and snippets.

@hwjeremy
hwjeremy / createTransaction.swift
Last active Jul 19, 2018
Create a Transaction in Amatino Swift - A double-entry accounting library / framework for iOS & MacOS
View createTransaction.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
import Foundation
import Amatino
try Transaction.create(
session: session,
entity: entity,
transactionTime: Date(),
@hwjeremy
hwjeremy / createSession.swift
Last active Jul 17, 2018
Create a Session in Amatino Swift. This is analogous to "logging in" to the Amatino API
View createSession.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Session.create(
email: "clever@cookie.com",
secret: "high entropy passphrase",
callback: { (error, session) in
guard error == nil else {
// Handle errors. In particular, look out for 401, which
// would indicate invalid credentials such as a mistyped
@hwjeremy
hwjeremy / createEntity.swift
Last active Jul 17, 2018
Create an Entity in Amatino Swift - A double-entry accounting library for iOS & MacOS
View createEntity.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Entity.create(
session: session,
name: "Stark Industries",
callback: { (error, newEntity) in
guard error == nil else {
// Handle errors
}
@hwjeremy
hwjeremy / retrieveEntity.swift
Last active Jul 17, 2018
Retrieve an Entity in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveEntity.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Entity.retrieve(
session: session,
entityId: starkIndustriesId,
callback: { (error: Error?, retrievedEntity: Entity?) in
guard error == nil else {
// Handle errors, e.g. a 404 for a non-existant entity id
}
@hwjeremy
hwjeremy / createAccount.swift
Last active Jul 17, 2018
Create an Account in Amatino Swift - A double-entry accounting library for iOS & MacOS
View createAccount.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Account.create(
session: session,
entity: starkIndustries,
name: "Suit Cash",
type: .asset,
description: "A stash of cash for building new Iron Man suits",
globalUnit: usd,
@hwjeremy
hwjeremy / retrieveAccount.swift
Created Jul 17, 2018
Retrieve an Account in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveAccount.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Account.retrieve(
session: session,
entity: starkIndustries,
accountId: cashAccountId,
callback: { (error: Error?, account: Account?) in
guard error == nil else {
// Handle error, e.g. a 404 for an account that does not
@hwjeremy
hwjeremy / retrieveTransaction.swift
Created Jul 17, 2018
Retrieve a Transaction in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveTransaction.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Transaction.retrieve(
session: session,
entity: starkIndustries,
transactionId: borrowedCashTxId,
callback: { (error: Error?, transaction: Transaction?) in
guard error == nil else {
// Handle error. E.g. 404 for an unknown Transaction, or 403
@hwjeremy
hwjeremy / retrieveGlobalUnit.swift
Created Jul 17, 2018
Retrieve a Global Unit in Amatino Swift - A double-entry accounting library / framework for iOS & MacOS
View retrieveGlobalUnit.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
GlobalUnit.retrieve(
unitId: 5, // The ID for U.S. dollars
session: session,
callback: { (error: Error?, unit: GlobalUnit?) in
guard error == nil else {
// Handle errors, e.g. a 404 for an unknown unit
}
@hwjeremy
hwjeremy / retrieveBalance.swift
Created Jul 19, 2018
Retrieve a Balance in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveBalance.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try Balance.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
@hwjeremy
hwjeremy / retrieveRecursiveBalance.swift
Created Jul 19, 2018
Retrieve a Recursive Balance in Amatino Swift - A double-entry accounting library for iOS & MacOS
View retrieveRecursiveBalance.swift
// Amatino Swift: https://github.com/amatino-code/amatino-swift
// Double entry accounting API
try RecursiveBalance.retrieve(
session: session,
entity: starkIndustries,
account: cashAccount,
callback: { (error: Error?, balance: RecursiveBalance?) in
guard error == nil else {
// Handle error, e.g. 404 account not found, 403 you are not