Skip to content

Commit 2be5f4f

Browse files
author
Matt Revelle
committed
Added fixes reported and made by daniel42.
1 parent f478bf3 commit 2be5f4f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/twitter.clj

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
(def *protocol* "http")
2020

2121
;; Get JSON from clj-apache-http
22-
(defmethod http/entity-as :json [entity as]
23-
(read-json (http/entity-as entity :string)))
22+
(defmethod http/entity-as :json [entity as state]
23+
(read-json (http/entity-as entity :string state)))
2424

2525
(defmacro with-oauth
2626
"Set the OAuth access token to be used for all contained Twitter requests."
@@ -51,21 +51,23 @@ take any required and optional arguments and call the associated Twitter method.
5151
rest-map# (apply hash-map rest#)
5252
provided-optional-params# (set/intersection (set ~optional-params)
5353
(set (keys rest-map#)))
54-
query-param-names# (sort (map (fn [x#] (keyword (string/replace #"-" "_" (name x#))))
54+
query-param-names# (sort (map (fn [x#] (keyword (string/replace (name x#) #"-" "_")))
5555
(concat ~required-params provided-optional-params#)))
5656
query-params# (apply hash-map (interleave query-param-names#
5757
(vec (concat ~required-fn-params
5858
(vals (sort (select-keys rest-map#
5959
provided-optional-params#)))))))
60+
need-to-url-encode# (if (= :get ~req-method)
61+
(into {} (map (fn [[k# v#]] [k# (oauth.signature/url-encode v#)]) query-params#))
62+
query-params#)
6063
oauth-creds# (when (and *oauth-consumer*
6164
*oauth-access-token*)
6265
(oauth/credentials *oauth-consumer*
6366
*oauth-access-token*
6467
*oauth-access-token-secret*
6568
~req-method
6669
req-uri#
67-
(into {} (map (fn [[k# v#]] [k# (oauth.signature/url-encode v#)]) query-params#))))]
68-
; (into {} (map (fn [k# v#] [k# (oauth.signature/url-encode v#)]) query-params#))
70+
need-to-url-encode#))]
6971
(~handler (~(symbol "http" (name req-method))
7072
req-uri#
7173
:query (merge query-params#
@@ -386,10 +388,11 @@ take any required and optional arguments and call the associated Twitter method.
386388
[x__2575__auto__]
387389
(keyword
388390
(string/replace
391+
(name
392+
x__2575__auto__)
389393
#"-"
390394
"_"
391-
(name
392-
x__2575__auto__))))
395+
)))
393396
provided-optional-params__2573__auto__))
394397
query-params__2576__auto__ (apply
395398
hash-map
@@ -604,9 +607,10 @@ the Twitter API."
604607
304 nil
605608
[400 401 403 404 406 500 502 503] (let [body (:content result)
606609
headers (into {} (:headers result))
607-
error-msg (body "error")
608-
request-uri (body "request")]
609-
(throw (proxy [Exception] [(str error-msg ". [" request-uri "]")]
610+
error-msg (:error body)
611+
error-code (:code result)
612+
request-uri (:request body)]
613+
(throw (proxy [Exception] [(str "[" error-code "] " error-msg ". [" request-uri "]")]
610614
(request [] (body "request"))
611615
(remaining-requests [] (headers "X-RateLimit-Remaining"))
612616
(rate-limit-reset [] (java.util.Date.

0 commit comments

Comments
 (0)