Skip to content

Instantly share code, notes, and snippets.

(ns index
(:use compojure))
(defservlet home
(GET "/"
(html [:h1 "Flockr"]
(html [:h2 "Twitter Portal"]))))
(run-server {:port 8080} "/*" home)
(ns index
(:use compojure))
(ns flockr.template
(:use compojure ))
(defn page
([title body]
(html [:html
(html [:head
(html [:title title])
]
(html [:body
(load-file "./template.clj")
(ns flockr
(:use compojure )
(:refer flockr.template))
(GET "/:twitter-name"
(page "Your Flock"
(html [:h1 "Welcome " (route :twitter-name)])))
(GET "/:twitter-name"
(page "Your Flock"
(html [:h1 "Welcome " (route :twitter-name)]
(map twitter-status
(read-json-string (let [[status headers body]
(http-get *twitter-url*)] body))))))
(defn twitter-status
([tweet]
(html [:p {:class "tweet"}
(html [:div {:class "tweet-text"} (get tweet "text")])
(html [:div {:class "tweet-user"} (get (get tweet "user") "name") ])])))
(def *twitter-url* "http://twitter.com/statuses/public_timeline.json")
(defn login
([params session]
(dosync
(alter session assoc :twitter-user (params :twitter-user))
(alter session assoc :twitter-password (params :twitter-password)))
(compojure.http.helpers/redirect-to (str "/" (@session :twitter-user)))))
(defn urlize
"A function that takes some text and creates links out of URLs
that it finds"
([text]
(.replaceAll
(re-matcher #"https?://[-\w]+\.\w[-\w/]*+" text)
"<a href=\"$0\">$0</a>")))
(defn twitter-status
([tweet]