about summary refs log tree commit diff
path: root/monzo_ynab/main.go
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-02-10T23·22+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-02-10T23·24+0000
commite223adfec540f3de19342b16eeb6336f14ff11e5 (patch)
treed24abff8125bc547bbb40e86851cb91b18913858 /monzo_ynab/main.go
parent2e719d117418e1e8718b242c0098b5e658fe714f (diff)
Begin work on YNAB client
After reading these docs
https://api.youneedabudget.com/v1#/Transactions/createTransaction I successfully
made a request to post a transaction to my YNAB account. Hastily created a
client.go that doesn't contain much at the moment.
Diffstat (limited to 'monzo_ynab/main.go')
-rw-r--r--monzo_ynab/main.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/monzo_ynab/main.go b/monzo_ynab/main.go
index 835cfadcb7..06f1944eab 100644
--- a/monzo_ynab/main.go
+++ b/monzo_ynab/main.go
@@ -13,10 +13,31 @@ import (
 	"fmt"
 )
 
+var (
+	ynabAccountID = os.Getenv("ynab_account_id")
+)
+
 ////////////////////////////////////////////////////////////////////////////////
 // Business Logic
 ////////////////////////////////////////////////////////////////////////////////
 
+// Convert a Monzo transaction struct, `tx`, into a YNAB transaction struct.
+func toYnab(tx monzoSerde.Transaction) ynabSerde.Transaction {
+	return ynabSerde.Transaction{
+		Id: tx.Id,
+		Date: tx.Created,
+		Amount: tx.Amount,
+		Memo: tx.Notes,
+		AccountId: ynabAccountID,
+	}
+}
+
 func main() {
-	fmt.Println("To be implemented...")
+	txs := monzo.TransactionsLast24Hours()
+	var ynabTxs []ynabSerde.Transaction{}
+	for tx := range txs {
+		append(ynabTxs, toYnab(tx))
+	}
+	ynab.PostTransactions(ynabTxs)
+	os.Exit(0)
 }