(require :eve-quine)
(require :tooter)

(defparameter *client*
 (make-instance 'tooter:client
     :base "https://mastodon.sdf.org"
     :name "tooter-client eve-quine lamb"))

(format t 
 "Visit and authenticate from a in-browser mastodon app:~%~a~%"
 (nth-value 1 (tooter:authorize (func-of *clamb*))))
(format t "Enter code from the browser:~%")
(tooter:authorize (func-of *clamb*) (read-line))

(print "We get one of @publius' posts:")
(print
 (tooter:plain-format-html
  (tooter:content
   (tooter:find-status *client*
    "109894889851888658"))))

;;;; Using an eve-quine to persist that client with secret


;;; Everything is reusable

;;; Make an eve-quine that persists eve-quines to disk.
(defparameter *wriamb*
 (form-eve ('lamb) :form-of
  ''(lambda (eve name outpath)
     (with-open-file (out outpath :Direction :output :if-exists :append
                      :if-does-not-exist :create)
      (let ((*print-pretty* t))
       (prin1 '(require :asdf) out) (terpri out)
       (prin1 '(require :eve-quine) out) (terpri out)
       (format out "(defparameter ~a ~s)~%" name
        (make-load-form eve) out) (terpri out))))))


;;; Make a dependency-loading eve-quine
;; just requires dep when loaded
(defparameter *depamb*
 (form-eve ('lamb) :form-of
  ''(prog1 (values) (require "tooter"))))


;;; Make a client-containing eve-quine
(defparameter *clamb*
 (form-eve ('lamb) :form-of 
  (funcall (lambda (x) `',x)
   (make-load-form *client*))))

;;; persist them to disk to just be #'load ed later.

(loop for clos-quine in (list *wriamb* *depamb* *clamb*)
 for name in '(*wriamb* *depamb* *clamb*)
 do (funcall (Func-of *wriamb*) clos-quine name 
     #p"load-me.lisp"))

;;; Later:
(print "reloading")
(load #p"load-me.lisp")
(print
 (tooter:find-status (func-of *clamb*) 
  "109894889851888658"))
(terpri)
(quit)