18
18
(def *oauth-access-token-secret* nil )
19
19
(def *protocol* " http" )
20
20
21
- ; ; Get JSON from clj-apache-http
21
+ ; ; Get JSON from clj-apache-http
22
22
(defmethod http /entity-as :json [entity as state]
23
23
(read-json (http/entity-as entity :string state)))
24
24
28
28
`(binding [*oauth-consumer* ~consumer
29
29
*oauth-access-token* ~access-token
30
30
*oauth-access-token-secret* ~access-token-secret]
31
- (do
31
+ (do
32
32
~@body)))
33
33
34
34
(defmacro with-https
35
35
[ & body]
36
36
`(binding [*protocol* " https" ]
37
- (do
37
+ (do
38
38
~@body)))
39
39
40
40
(defmacro def-twitter-method
@@ -51,21 +51,34 @@ 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
- required-query-param-names# (map (fn [x#]
55
- (keyword (string/replace (name x#) #"-" " _" )))
56
- ~required-params)
57
- optional-query-param-names-mapping# (map (fn [x#]
58
- [x# (keyword (string/replace (name x#) #"-" " _" ))])
59
- provided-optional-params#)
60
- query-params# (merge (apply hash-map
61
- (vec (interleave required-query-param-names# ~required-fn-params)))
62
- (apply merge
63
- (map (fn [x#] {(second x#) ((first x#) rest-map#)}) optional-query-param-names-mapping#)))
54
+ required-query-param-names#
55
+ (map (fn [x#]
56
+ (keyword (string/replace (name x#) #"-" " _" )))
57
+ ~required-params)
58
+
59
+ optional-query-param-names-mapping#
60
+ (map (fn [x#]
61
+ [x# (keyword (string/replace (name x#) #"-" " _" ))])
62
+ provided-optional-params#)
63
+
64
+ query-params#(merge (apply hash-map
65
+ (vec (interleave
66
+ required-query-param-names#
67
+ ~required-fn-params)))
68
+ (apply merge
69
+ (map (fn [x#] {(second x#)
70
+ ((first x#)
71
+ rest-map#)})
72
+ optional-query-param-names-mapping#)))
64
73
need-to-url-encode# (if (= :get ~req-method)
65
- (into {} (map (fn [[k# v#]] [k# (oauth.signature/url-encode v#)]) query-params#))
74
+ (into {}
75
+ (map (fn [[k# v#]]
76
+ [k#
77
+ (oauth.signature/url-encode v#)])
78
+ query-params#))
66
79
query-params#)
67
- oauth-creds# (when (and *oauth-consumer*
68
- *oauth-access-token*)
80
+ oauth-creds# (when (and *oauth-consumer*
81
+ *oauth-access-token*)
69
82
(oauth/credentials *oauth-consumer*
70
83
*oauth-access-token*
71
84
*oauth-access-token-secret*
@@ -76,7 +89,7 @@ take any required and optional arguments and call the associated Twitter method.
76
89
req-uri#
77
90
:query (merge query-params#
78
91
oauth-creds#)
79
- :parameters (http/map->params
92
+ :parameters (http/map->params
80
93
{:use-expect-continue false })
81
94
:as :json ))))))
82
95
@@ -282,7 +295,7 @@ take any required and optional arguments and call the associated Twitter method.
282
295
(def-twitter-method friends-of-name
283
296
:get
284
297
" api.twitter.com/1/friends/ids.json"
285
- [:screen-name ]
298
+ [:screen-name ]
286
299
[]
287
300
(comp #(:content %) status-handler))
288
301
@@ -349,7 +362,7 @@ take any required and optional arguments and call the associated Twitter method.
349
362
350
363
(defn update-profile-image [^String image]
351
364
(let [req-uri__9408__auto__ " http://api.twitter.com/1/account/update_profile_image.json"
352
-
365
+
353
366
oauth-creds__9414__auto__ (when
354
367
(and
355
368
*oauth-consumer*
@@ -379,45 +392,47 @@ take any required and optional arguments and call the associated Twitter method.
379
392
(comp #(:content %) status-handler)))
380
393
381
394
(defn update-profile-background-image [^String image & rest__2570__auto__]
382
- (let [req-uri__2571__auto__ " http://api.twitter.com/1/account/update_profile_background_image.json"
383
- rest-map__2572__auto__ (apply hash-map rest__2570__auto__)
384
- provided-optional-params__2573__auto__ (set/intersection
385
- (set [:title ])
386
- (set
387
- (keys
388
- rest-map__2572__auto__)))
389
- query-param-names__2574__auto__ (sort
390
- (map
391
- (fn
392
- [x__2575__auto__]
393
- (keyword
394
- (string/replace
395
- (name
396
- x__2575__auto__)
397
- #"-"
398
- " _"
399
- )))
400
- provided-optional-params__2573__auto__))
401
- query-params__2576__auto__ (apply
402
- hash-map
403
- (interleave
404
- query-param-names__2574__auto__
405
- (vec
406
- (vals
407
- (sort
408
- (select-keys
409
- rest-map__2572__auto__
410
- provided-optional-params__2573__auto__))))))
411
- oauth-creds__2577__auto__ (when
412
- (and
413
- *oauth-consumer*
414
- *oauth-access-token*)
415
- (oauth/credentials
416
- *oauth-consumer*
417
- *oauth-access-token*
418
- :post
419
- req-uri__2571__auto__
420
- query-params__2576__auto__))]
395
+ (let [req-uri__2571__auto__
396
+ " http://api.twitter.com/1/account/update_profile_background_image.json"
397
+
398
+ rest-map__2572__auto__ (apply hash-map rest__2570__auto__)
399
+ provided-optional-params__2573__auto__ (set/intersection
400
+ (set [:title ])
401
+ (set
402
+ (keys
403
+ rest-map__2572__auto__)))
404
+ query-param-names__2574__auto__ (sort
405
+ (map
406
+ (fn
407
+ [x__2575__auto__]
408
+ (keyword
409
+ (string/replace
410
+ (name
411
+ x__2575__auto__)
412
+ #"-"
413
+ " _"
414
+ )))
415
+ provided-optional-params__2573__auto__))
416
+ query-params__2576__auto__ (apply
417
+ hash-map
418
+ (interleave
419
+ query-param-names__2574__auto__
420
+ (vec
421
+ (vals
422
+ (sort
423
+ (select-keys
424
+ rest-map__2572__auto__
425
+ provided-optional-params__2573__auto__))))))
426
+ oauth-creds__2577__auto__ (when
427
+ (and
428
+ *oauth-consumer*
429
+ *oauth-access-token*)
430
+ (oauth/credentials
431
+ *oauth-consumer*
432
+ *oauth-access-token*
433
+ :post
434
+ req-uri__2571__auto__
435
+ query-params__2576__auto__))]
421
436
((comp #(:content %) status-handler)
422
437
(http/post req-uri__2571__auto__
423
438
:query (merge query-params__2576__auto__ oauth-creds__2577__auto__)
@@ -430,7 +445,7 @@ take any required and optional arguments and call the associated Twitter method.
430
445
:post
431
446
" api.twitter.com/1/account/update_profile.json"
432
447
[]
433
- [:name
448
+ [:name
434
449
:email
435
450
:url
436
451
:location
@@ -605,21 +620,23 @@ take any required and optional arguments and call the associated Twitter method.
605
620
" Handle the various HTTP status codes that may be returned when accessing
606
621
the Twitter API."
607
622
[result]
608
- (condp #(if (coll? %1 )
623
+ (condp #(if (coll? %1 )
609
624
(first (filter (fn [x] (== x %2 )) %1 ))
610
625
(== %2 %1 )) (:code result)
611
626
200 result
612
627
304 nil
613
- [400 401 403 404 406 500 502 503 ] (let [body (:content result)
614
- headers (into {} (:headers result))
615
- error-msg (:error body)
616
- error-code (:code result)
617
- request-uri (:request body)]
618
- (throw (proxy [Exception] [(str " [" error-code " ] " error-msg " . [" request-uri " ]" )]
619
- (request [] (body " request" ))
620
- (remaining-requests [] (headers " X-RateLimit-Remaining" ))
621
- (rate-limit-reset [] (java.util.Date.
622
- (long (headers " X-RateLimit-Reset" )))))))))
628
+ [400 401 403 404 406 500 502 503 ]
629
+ (let [body (:content result)
630
+ headers (into {} (:headers result))
631
+ error-msg (:error body)
632
+ error-code (:code result)
633
+ request-uri (:request body)]
634
+ (throw (proxy [Exception]
635
+ [(str " [" error-code " ] " error-msg " . [" request-uri " ]" )]
636
+ (request [] (body " request" ))
637
+ (remaining-requests [] (headers " X-RateLimit-Remaining" ))
638
+ (rate-limit-reset [] (java.util.Date.
639
+ (long (headers " X-RateLimit-Reset" )))))))))
623
640
624
641
(defn make-rate-limit-handler
625
642
" Creates a handler that will only be called if the API rate limit has been exceeded."
0 commit comments