about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--monzo_ynab/.envrc2
-rw-r--r--monzo_ynab/main.go23
-rw-r--r--monzo_ynab/requests.txt22
-rw-r--r--monzo_ynab/ynab/client.go24
4 files changed, 70 insertions, 1 deletions
diff --git a/monzo_ynab/.envrc b/monzo_ynab/.envrc
index 322e99ad6b35..50fd9db4ac25 100644
--- a/monzo_ynab/.envrc
+++ b/monzo_ynab/.envrc
@@ -8,4 +8,6 @@ source_up
 export monzo_client_id="$(pass show finance/monzo/client-id)"
 export monzo_client_secret="$(pass show finance/monzo/client-secret)"
 export ynab_personal_access_token="$(pass show finance/youneedabudget.com/personal-access-token)"
+export ynab_account_id="$(pass show finance/youneedabudget.com/personal-access-token)"
+export ynab_budget_id="$(pass show finance/youneedabudget.com/budget-id)"
 eval "$(lorri direnv)"
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)
 }
diff --git a/monzo_ynab/requests.txt b/monzo_ynab/requests.txt
index 5698dfee3763..2da17c0b326a 100644
--- a/monzo_ynab/requests.txt
+++ b/monzo_ynab/requests.txt
@@ -4,6 +4,7 @@
 :ynab = https://api.youneedabudget.com/v1
 :ynab-access-token := (getenv "ynab_personal_access_token")
 :ynab-budget-id := (getenv "ynab_budget_id")
+:ynab-account-id := (getenv "ynab_account_id")
 
 # Test
 GET :ynab/budgets
@@ -11,6 +12,27 @@ Authorization: Bearer :ynab-access-token
 
 # List transactions
 GET :ynab/budgets/:ynab-budget-id/transactions
+Authorization: Bearer :ynab-access-token
+
+# Post transactions
+POST :ynab/budgets/:ynab-budget-id/transactions
+Authorization: Bearer :ynab-access-token
+Content-Type: application/json
+{
+  "transactions": [
+    {
+      "account_id": ":ynab-account-id",
+      "date": "2019-12-30",
+      "amount": 10000,
+      "payee_name": "Richard Stallman",
+      "memo": "Not so free software after all...",
+      "cleared": "cleared",
+      "approved": true,
+      "flag_color": "red",
+      "import_id": "xyz-123"
+    }
+  ]
+}
 
 ################################################################################
 # Monzo
diff --git a/monzo_ynab/ynab/client.go b/monzo_ynab/ynab/client.go
new file mode 100644
index 000000000000..0492b9071adc
--- /dev/null
+++ b/monzo_ynab/ynab/client.go
@@ -0,0 +1,24 @@
+package client
+
+import (
+	"serde"
+)
+
+// See requests.txt for more details.
+func PostTransactions(accountID string, txs []serde.Transaction{}) error {
+	return map[string]string{
+		"transactions": [
+			{
+				"account_id": accountID,
+					"date": "2019-12-30",
+					"amount": 10000,
+					"payee_name": "Richard Stallman",
+					"memo": "Not so free software after all...",
+					"cleared": "cleared",
+					"approved": true,
+					"flag_color": "red",
+					"import_id": "xyz-123"
+			}
+		]
+	}
+}