> Let me know if you find it useful. I would love to get some comments.
> -Phil
Hi Phil,
I'm trying out clojure-http-client, & thus far I like the idea of it
quite a bit: a simple but clever wrapper on built-in JDK APIs, so
provides convenience w/o the burden of external jars.
Quickly, I ran into problems with the resourcefully/with-cookies
macro. Making two changes to resourcefully.clj & altering the
signature from the example made it work (but I didn't test too
rigorously).
Re: altering the signature, the example use of with-cookies in the
file is
(with-cookies (get ...) (post ...) ...)
but the macro expects the first argument to be a (possibly nil?)
cookies map, like this
(with-cookies {} (get ...) (post ...)) OR (with-cookies nil
(get ...) (post ...))
Re: changes to resourcefully, here's the diff:
diff --git a/src/clojure/http/resourcefully.clj b/src/clojure/http/
resourcefully.clj
index 0376df8..358c157 100644
--- a/src/clojure/http/resourcefully.clj
+++ b/src/clojure/http/resourcefully.clj
@@ -44,7 +44,7 @@
map. Cookies will be saved if inside with-cookies block.")
[u# & [headers# body#]]
(let [response# (save-cookies (client/request u# ~(str method)
- headers# *cookies*
body#))]
+ headers#
@*cookies* body#))]
(if (error? response#)
(throw (java.io.IOException. (error-message response#)))
response#))))
@@ -59,5 +59,5 @@ map. Cookies will be saved if inside with-cookies
block.")
"Perform body with *cookies* bound to cookie-map. Responses that
set
cookies will have them saved in the *cookies* ref."
[cookie-map & body]
- `(binding [*cookies* (ref (or cookie-map {}))]
+ `(binding [*cookies* (ref (or ~cookie-map {}))]
~...@body))
The gist is that (1), in with-cookies, the parameter "cookie-map" must
be unquoted & thus evaluated to the value passed in -- w/o the unquote
cookie-map gets namespace-qualified to the var resourcefully/cookie-
map, which doesn't exist. (2) in the define-method macro, the
*cookies* ref must be dereferenced when passed to client/request,
because client/request expects a map, not a ref.
Thanks for the lib. I for one would appreciate its inclusion in
contrib once it gets a little more testing.
Best,
Perry
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---