about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-27T14·54+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-27T14·56+0000
commit49521429160890b58c8724e8ca24b8a80d3d2cce (patch)
treea9d7b33fba9286b49678fb036bc0b42627389e08
parent5399b4bd0357383eb95edeb5b653c3e4a6fd3de1 (diff)
Sketch ideas for YNAB integration
The end goal is to have some functions that help me manage my Monzo and YNAB
accounts. YNAB (i.e. youneedabudget.com) doesn't support Monzo
integrations. However, both services offer APIs. Here I'm sketching ideas for
what the API integrations might look like. Coming soon: monzo.el.
-rw-r--r--configs/shared/.emacs.d/wpc/ynab.el56
1 files changed, 56 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/ynab.el b/configs/shared/.emacs.d/wpc/ynab.el
new file mode 100644
index 000000000000..7e132e20c244
--- /dev/null
+++ b/configs/shared/.emacs.d/wpc/ynab.el
@@ -0,0 +1,56 @@
+;;; ynab.el --- Functions for YNAB's API -*- lexical-binding: t -*-
+;; Author: William Carroll <wpcarro@gmail.com>
+
+;;; Commentary:
+;; I'm not sure what the outcome of this project is.  I'm just writing some
+;; Elisp at the moment to document some of my cursory interactions with YNAB's
+;; API.
+
+;;; Code:
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'json)
+(require 'a)
+(require 'request)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Library
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar ynab/api-url "https://api.youneedabudget.com/v1/"
+  "The URL of the YNAB API.")
+
+(defun ynab/get-secret (name)
+  "Fetch and decrypt the secret for YNAB at NAME in the password store."
+  (password-store-get (format "%s/%s" "finance/youneedabudget.com" name)))
+
+(defvar ynab/personal-access-token
+  (ynab/get-secret "personal-access-token")
+  "My personal access token to YNAB's API.")
+
+(defvar ynab/budget-id
+  (ynab/get-secret "budget-id")
+  "The ID of my current budget on YNAB.")
+
+(defvar ynab/account-id
+  (ynab/get-secret "account-id")
+  "The ID of my current budget on YNAB.")
+
+(defun ynab/url-for-endpoint (endpoint)
+  "Return the URL for the YNAB ENDPOINT.
+This will resolve any variables in the form of {variable_name} using a prefined
+scope object."
+  (format "%s%s" ynab/api-url endpoint))
+
+(macros/comment
+ ;; TODO: Use these this map to resolve variables in an endpoint URL like
+ ;; '/budgets/{budget_id}/'.
+ '((budget_id . (ynab/get-secret "budget-id"))
+   (account_id . (ynab/get-secret "account-id")))
+ (request (ynab/url-for-endpoint "/budgets/{budget_id}/transactions")))
+
+(provide 'ynab)
+;;; ynab.el ends here