Skip to content

Instantly share code, notes, and snippets.

@hiredman hiredman/kevin.clj
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"))]
(with-open [wrt (OutputStreamWriter. (.getOutputStream con))
rdr (BufferedReader. (InputStreamReader. (.getInputStream con)))]
(.write wrt (str "status=" (URLEncoder/encode text "UTF-8")))
(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.