diff options
author | Boutade <thegoofist@protonmail.com> | 2019-09-25 14:30:21 -0500 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2019-09-25 14:30:21 -0500 |
commit | e1b239d0b075bd613a7ea6e321b762dd389e0e5e (patch) | |
tree | cd3130aae46c6c865517104ceb1765e55507902f | |
parent | 4e5ee14582cf2f918a76ffb9e37ee9c5809a53b2 (diff) |
added save and load client state functions
-rw-r--r-- | granolin.lisp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/granolin.lisp b/granolin.lisp index ed25128..ede3a2e 100644 --- a/granolin.lisp +++ b/granolin.lisp @@ -41,6 +41,26 @@ :type string :documentation "Used on sync requests as the value of the SINCE parameter"))) +(defun save-client-state (client &key (fname "granolin.conf")) + "Save a PLIST of client state to disk. Saves HOMESERVER, TIMEOUT, + ACCESS-TOKEN, and NEXT-BATCH values to the file." + + (with-open-file (out fname :direction :output) + (print (list :homeserver (homeserver client) + :timeout (timeout client) + :access-token (access-token client) + :next-batch (next-batch client)) + out))) + +(defun load-client-state (client &optional (fname "granolin.conf")) + "Load client state from a PLIST stored in a file." + (let ((conf (with-open-file (in fname) (read in)))) + (setf (homeserver client) (getf conf :homeserver)) + (setf (timeout client) (getf conf :timeout)) + (setf (access-token client) (getf conf :access-token)) + (setf (next-batch client) (getf conf :next-batch))) + client) + ;; TODO (defun validate-homserver-url (client) "Ensure that the homeserver url is well formed, and makes an attempt to format it if it isnt") |