Skip to content

Instantly share code, notes, and snippets.

@stuhood stuhood/gist:95473
Created Apr 14, 2009

What would you like to do?
(import '( BufferedReader IOException InputStream InputStreamReader OutputStreamWriter)
'( URL URLConnection URLEncoder)
'(sun.misc BASE64Encoder))
(def update-url "")
(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
You can’t perform that action at this time.