From ebb4bfcee21020cec5cae08955cf2a8c57d3532c Mon Sep 17 00:00:00 2001 From: Abhiseck Paira Date: Mon, 17 Jan 2022 20:03:01 +0530 Subject: store access token in plstore of the current user Store access token in the plstore of the current user. To do that introduce the function `mastodon-client-store-access-token' of one argument TOKEN. Also define a helper function `mastodon-client--make-user-details-plist' which creates a plist with current users details and returns it. --- lisp/mastodon-client.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lisp/mastodon-client.el') diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index f7d06a5..1c3b2e1 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -116,6 +116,28 @@ Return plist without the KEY." (plstore-item (plstore-get plstore key))) (mastodon-client--remove-key-from-plstore plstore-item))) +(defun mastodon-client--make-user-details-plist () + "Make a plist with current user details. Return it." + `(:username ,(mastodon-client-form-user-from-vars) + :instance ,mastodon-instance-url + :client_id ,(plist-get (mastodon-client) :client_id) + :client_secret ,(plist-get (mastodon-client) :client_secret))) + +(defun mastodon-client-store-access-token (token) + "Save TOKEN as :access_token in plstore of the current user. +Return the plist after the operation." + (let* ((user-details (mastodon-client--make-user-details-plist)) + (plstore (plstore-open (mastodon-client--token-file))) + (username (plist-get user-details :username)) + (plstore-value (setq user-details + (plist-put user-details :access_token token))) + (print-length nil) + (print-level nil)) + (plstore-put plstore (concat "user-" username) plstore-value nil) + (plstore-save plstore) + (plstore-close plstore) + plstore-value)) + (defun mastodon-client-form-user-from-vars () "Create a username from user variable. Return that username. -- cgit v1.2.3