Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! We cleaned up your code for you! #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.markdown
Expand Up @@ -16,21 +16,21 @@ Access the Twitter API from Clojure.

;; Make a OAuth consumer
(def oauth-consumer (oauth/make-consumer <key>
<secret>
<secret>
"https://api.twitter.com/oauth/request_token"
"https://api.twitter.com/oauth/access_token"
"https://api.twitter.com/oauth/authorize"
:hmac-sha1))

(def oauth-access-token
(def oauth-access-token
;; Look up an access token you've stored away after the user
;; authorized a request token and you traded it in for an
;; access token. See clj-oauth (http://github.com/mattrepl/clj-oauth) for an example.)
(def oauth-access-token-secret
;; The secret included with the access token)

;; Post to twitter
(twitter/with-oauth oauth-consumer
(twitter/with-oauth oauth-consumer
oauth-access-token
oauth-access-token-secret
(twitter/update-status "posting from #clojure with #oauth"))
Expand Down
24 changes: 12 additions & 12 deletions src/twitter.clj
Expand Up @@ -18,7 +18,7 @@
(def *oauth-access-token-secret* nil)
(def *protocol* "http")

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

Expand All @@ -28,13 +28,13 @@
`(binding [*oauth-consumer* ~consumer
*oauth-access-token* ~access-token
*oauth-access-token-secret* ~access-token-secret]
(do
(do
~@body)))

(defmacro with-https
[ & body]
`(binding [*protocol* "https"]
(do
(do
~@body)))

(defmacro def-twitter-method
Expand Down Expand Up @@ -64,8 +64,8 @@ take any required and optional arguments and call the associated Twitter method.
need-to-url-encode# (if (= :get ~req-method)
(into {} (map (fn [[k# v#]] [k# (oauth.signature/url-encode v#)]) query-params#))
query-params#)
oauth-creds# (when (and *oauth-consumer*
*oauth-access-token*)
oauth-creds# (when (and *oauth-consumer*
*oauth-access-token*)
(oauth/credentials *oauth-consumer*
*oauth-access-token*
*oauth-access-token-secret*
Expand All @@ -76,7 +76,7 @@ take any required and optional arguments and call the associated Twitter method.
req-uri#
:query (merge query-params#
oauth-creds#)
:parameters (http/map->params
:parameters (http/map->params
{:use-expect-continue false})
:as :json))))))

Expand Down Expand Up @@ -282,7 +282,7 @@ take any required and optional arguments and call the associated Twitter method.
(def-twitter-method friends-of-name
:get
"api.twitter.com/1/friends/ids.json"
[:screen-name]
[:screen-name]
[]
(comp #(:content %) status-handler))

Expand Down Expand Up @@ -349,7 +349,7 @@ take any required and optional arguments and call the associated Twitter method.

(defn update-profile-image [^String image]
(let [req-uri__9408__auto__ "http://api.twitter.com/1/account/update_profile_image.json"

oauth-creds__9414__auto__ (when
(and
*oauth-consumer*
Expand Down Expand Up @@ -388,7 +388,7 @@ take any required and optional arguments and call the associated Twitter method.
rest-map__2572__auto__)))
query-param-names__2574__auto__ (sort
(map
(fn
(fn
[x__2575__auto__]
(keyword
(string/replace
Expand Down Expand Up @@ -430,7 +430,7 @@ take any required and optional arguments and call the associated Twitter method.
:post
"api.twitter.com/1/account/update_profile.json"
[]
[:name
[:name
:email
:url
:location
Expand Down Expand Up @@ -605,7 +605,7 @@ take any required and optional arguments and call the associated Twitter method.
"Handle the various HTTP status codes that may be returned when accessing
the Twitter API."
[result]
(condp #(if (coll? %1)
(condp #(if (coll? %1)
(first (filter (fn [x] (== x %2)) %1))
(== %2 %1)) (:code result)
200 result
Expand All @@ -618,7 +618,7 @@ the Twitter API."
(throw (proxy [Exception] [(str "[" error-code "] " error-msg ". [" request-uri "]")]
(request [] (body "request"))
(remaining-requests [] (headers "X-RateLimit-Remaining"))
(rate-limit-reset [] (java.util.Date.
(rate-limit-reset [] (java.util.Date.
(long (headers "X-RateLimit-Reset")))))))))

(defn make-rate-limit-handler
Expand Down
4 changes: 2 additions & 2 deletions src/twitter/query.clj
Expand Up @@ -5,7 +5,7 @@
(defn or
"Build up a search string where all terms are OR'd."
[& terms]
(java.net.URLEncoder/encode
(string/join " OR "
(java.net.URLEncoder/encode
(string/join " OR "
(map #(str "\"" % "\"") terms))
"UTF-8"))