Skip to content

Instantly share code, notes, and snippets.

View hwjeremy's full-sized avatar

Hugh Jeremy hwjeremy

View GitHub Profile
@hwjeremy
hwjeremy / createSession.swift
Last active July 17, 2018 09:12
Create a Session in Amatino Swift. This is analogous to "logging in" to the Amatino API
// 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 July 17, 2018 09:37
Create an Entity 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 Entity.create(
session: session,
name: "Stark Industries",
callback: { (error, newEntity) in
guard error == nil else {
// Handle errors
}
@hwjeremy
hwjeremy / retrieveEntity.swift
Last active July 17, 2018 09:38
Retrieve an Entity 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 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 / retrieveAccount.swift
Created July 17, 2018 09:52
Retrieve 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.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 July 17, 2018 10:10
Retrieve 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.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 / createAccount.swift
Last active July 17, 2018 10:23
Create 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.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 / retrieveGlobalUnit.swift
Created July 17, 2018 10:22
Retrieve a Global Unit in Amatino Swift - A double-entry accounting library / framework for iOS & MacOS
// 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 July 19, 2018 02:42
Retrieve a Balance 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 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 July 19, 2018 02:44
Retrieve a Recursive Balance 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 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
@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 {