Created
April 14, 2009 22:28
-
-
Save stuhood/95473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(java.io BufferedReader IOException InputStream InputStreamReader OutputStreamWriter) | |
'(java.net URL URLConnection URLEncoder) | |
'(sun.misc BASE64Encoder)) | |
(def update-url "https://twitter.com/statuses/update.xml") | |
(defn creds [username password] | |
(.trim (.encode (BASE64Encoder.) (.getBytes (str username ":" password))))) | |
(defn twitter [username password text] | |
(let [creds (creds username password) | |
con (doto (.openConnection (URL. update-url)) | |
(.setDoInput true) | |
(.setDoOutput true) | |
(.setUseCaches false) | |
(.setRequestProperty "Authorization" (str "Basic " creds)) | |
(.setRequestProperty "Content-Type" "application/x-www-form-urlencoded") | |
(.setRequestProperty "User-Agent" "clojurebot"))] | |
(println (.getRequestProperties con)) | |
(with-open [wrt (OutputStreamWriter. (.getOutputStream con))] | |
(.write wrt (str "status=" (URLEncoder/encode text "UTF-8"))) | |
(.flush wrt) | |
(with-open [rdr (BufferedReader. (InputStreamReader. (.getInputStream con)))] | |
(apply str (line-seq rdr)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment