From e223adfec540f3de19342b16eeb6336f14ff11e5 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 10 Feb 2020 23:22:36 +0000 Subject: 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. --- monzo_ynab/main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'monzo_ynab/main.go') diff --git a/monzo_ynab/main.go b/monzo_ynab/main.go index 835cfadcb7db..06f1944eab70 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) } -- cgit 1.4.1