Re: first time without state - and I'm lost

2020-05-14 Thread J.-F. Rompre

Hi @Scaramacci,

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 below, 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 if expired/expiring. 
)

(defn get-token [usr, psw]
  (let [f (fn f [tok]
  [tok, (fn [] (f (get-updated-token usr psw tok)))])]
(let [path [:users usr] 
  [_ 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")}))


On Tuesday, May 12, 2020 at 3:27:01 AM UTC-4, Scaramaccai wrote:
>
>
> (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/d17770bc-7d66-4e87-9e66-0a900b745080%40googlegroups.com.


Re: first time without state - and I'm lost

2020-05-14 Thread J.-F. Rompre
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 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/148d5ae6-02b1-48bf-b518-04483cc5bcef%40googlegroups.com.


Re: first time without state - and I'm lost

2020-05-14 Thread J.-F. Rompre
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 {}))

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

(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 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/60edfcb9-6d33-4ce7-959d-24a8286815a2%40googlegroups.com.


Re: first time without state - and I'm lost

2020-05-14 Thread J.-F. Rompre
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]
  ;; Return 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/ceebd69f-0565-43f3-b86b-79a653ae8f3f%40googlegroups.com.


Re: first time without state - and I'm lost

2020-05-14 Thread J.-F. Rompre
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.