Skip to content

Instantly share code, notes, and snippets.

@jtoy
Created April 6, 2012 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtoy/2322942 to your computer and use it in GitHub Desktop.
Save jtoy/2322942 to your computer and use it in GitHub Desktop.
(require '[clj-http.client :as client])
(defn extract_domain [domain]
(println domain)
(let [unrolled_url (try (:trace-redirects (client/get domain {:throw-entire-message? true})) (catch Exception _ domain))]
(.getHost (java.net.URL. unrolled_url))))
(extract_domain "http://t.co/fDW8Gau")
http://t.co/fDW8Gau
"t.co"
user=> (extract_domain "http://t.co/g98sMxmT")
http://t.co/g98sMxmT
java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.String (NO_SOURCE_FILE:0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment