Hi @Scaramaccai,
If you are starting out, it's always best to keepthings as bare as possible
until you discover a better way.
If as you say you can save the usr/pwd, and the decision to keep or replace
the token is entirely left to the token provider, then I think something
like the following may be suitable.
For anyone interested in learning the ins and outs of OO vs Functional,
static typing vs. dynamic, I highly recommend the Programming Languages
Specialization on Coursera.
(defonce user-tokens (atom {:users {}))
;; Returns tok if still valid or a new token if expired/expiring.
(defn get-updated-token [usr pwd tok]
;; ...
)
(defn get-token [usr, psw]
(let [f (fn f [tok]
[tok, (fn [] (f (get-updated-token usr psw tok)))])
path [:users usr]
[tok thunk] (or (get-in @user-tokens path) (f nil))]
(first (swap! user-tokens assoc-in path (thunk)))))
(defn geturl [url]
(client/get url {:oauth-token (get-token "user" "pwd")}))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/clojure/148d5ae6-02b1-48bf-b518-04483cc5bcef%40googlegroups.com.