|
19 | 19 | (def *protocol* "http")
|
20 | 20 |
|
21 | 21 | ;; 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))) |
24 | 24 |
|
25 | 25 | (defmacro with-oauth
|
26 | 26 | "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.
|
51 | 51 | rest-map# (apply hash-map rest#)
|
52 | 52 | provided-optional-params# (set/intersection (set ~optional-params)
|
53 | 53 | (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#) #"-" "_"))) |
55 | 55 | (concat ~required-params provided-optional-params#)))
|
56 | 56 | query-params# (apply hash-map (interleave query-param-names#
|
57 | 57 | (vec (concat ~required-fn-params
|
58 | 58 | (vals (sort (select-keys rest-map#
|
59 | 59 | 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#) |
60 | 63 | oauth-creds# (when (and *oauth-consumer*
|
61 | 64 | *oauth-access-token*)
|
62 | 65 | (oauth/credentials *oauth-consumer*
|
63 | 66 | *oauth-access-token*
|
64 | 67 | *oauth-access-token-secret*
|
65 | 68 | ~req-method
|
66 | 69 | 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#))] |
69 | 71 | (~handler (~(symbol "http" (name req-method))
|
70 | 72 | req-uri#
|
71 | 73 | :query (merge query-params#
|
@@ -386,10 +388,11 @@ take any required and optional arguments and call the associated Twitter method.
|
386 | 388 | [x__2575__auto__]
|
387 | 389 | (keyword
|
388 | 390 | (string/replace
|
| 391 | + (name |
| 392 | + x__2575__auto__) |
389 | 393 | #"-"
|
390 | 394 | "_"
|
391 |
| - (name |
392 |
| - x__2575__auto__)))) |
| 395 | + ))) |
393 | 396 | provided-optional-params__2573__auto__))
|
394 | 397 | query-params__2576__auto__ (apply
|
395 | 398 | hash-map
|
@@ -604,9 +607,10 @@ the Twitter API."
|
604 | 607 | 304 nil
|
605 | 608 | [400 401 403 404 406 500 502 503] (let [body (:content result)
|
606 | 609 | 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 "]")] |
610 | 614 | (request [] (body "request"))
|
611 | 615 | (remaining-requests [] (headers "X-RateLimit-Remaining"))
|
612 | 616 | (rate-limit-reset [] (java.util.Date.
|
|
0 commit comments