Hi @Scaramaccai,

If you are starting out, it's always best to keep things 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 {}))

(defn get-updated-token [usr pwd tok]
    ;; Returns tok if still valid or a new token 
)

(defn get-token [usr, psw]
  (let [f (fn f [tok]
              [tok, (fn [] (f (get-updated-token usr psw tok)))])
        path [:users usr] 
        thunk (or (get-in @user-tokens path) (f nil))
        [token thunk'] (thunk)]
    (do (swap! user-tokens assoc-in path thunk')
        token))) 

(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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/76903546-bc8b-4747-aa2d-0099c9f6e7bc%40googlegroups.com.

Reply via email to