Hi everyone, I wanted to give a try to Clojure and functional programming in general but I can't really stop thinking "object oriented" or "with state everywhere". After 20+ years with objects + state I guess I'm lost without them :)
The first thing I want to try is to get some data from an API that needs OAuth authentication. I would like to hide the fact that there's an OAuth token to be sent. In pseudo-Java I would do something like: class MyAuthHttpClient { private token; public MyAuthHttpClient(String usr, String psw) {...} public ... getResponse(Url) { // here check if token is available and if it is expiring; // if expiring -> fetch a new token before call the http service // caller doesn't even know there's a token involved in the process } } What's the proper way to do that in Clojure? I guess one way would be to have a function that returns a new token given a (possibly old) token and user+psw (defn gettkn [usr, psw, tkn] (return a new token if tkn is expiring or tkn if not expiring)) (def wrap-gettkn (partial gettkn "myuser" "mypass")) (defn geturl [url, tkn] client/get url {:oauth-token (wrap-gettkn tkn)}) I can "save" usr and psw, but I always have to "keep" the tkn around at every level; while I would like the token to be "hidden" to the "geturl" clients (just like I did in the "private token" in the pseudo-Java). What's the proper way of doing something like this in Clojure? -- 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/6aa66613-24d9-4ebc-87d4-e9a6cca05165%40googlegroups.com.