[bknr-cvs] hans changed trunk/projects/planetwit/

BKNR Commits bknr at bknr.net
Thu Aug 20 12:42:30 UTC 2009


Revision: 4446
Author: hans
URL: http://bknr.net/trac/changeset/4446

factor out make-tiny-url function
U   trunk/projects/planetwit/http-client.clj
U   trunk/projects/planetwit/planetwit.clj

Modified: trunk/projects/planetwit/http-client.clj
===================================================================
--- trunk/projects/planetwit/http-client.clj	2009-08-20 12:21:41 UTC (rev 4445)
+++ trunk/projects/planetwit/http-client.clj	2009-08-20 12:42:30 UTC (rev 4446)
@@ -21,7 +21,7 @@
     (HttpRequest. (method-string method) url)))
 
 (defn simple-http-request
-  [url attributes]
+  [url & attributes]
   (let [{:keys [method content-type content client basic-authorization], :or {method :get}} attributes
         client (or client (HttpClient.))
         request (make-request url method content-type content)]

Modified: trunk/projects/planetwit/planetwit.clj
===================================================================
--- trunk/projects/planetwit/planetwit.clj	2009-08-20 12:21:41 UTC (rev 4445)
+++ trunk/projects/planetwit/planetwit.clj	2009-08-20 12:42:30 UTC (rev 4446)
@@ -53,6 +53,11 @@
    (catch java.io.FileNotFoundException _
      (println (format "could not update twitter status (no auth file):\n%s\n" status)))))
 
+(defn make-tiny-url
+  "Make a tiny url from URL using the tinyurl.com service"
+  [url]
+  (:body (http/simple-http-request (format "http://tinyurl.com/api-create.php?url=%s" url))))
+
 (defn post-twits
   "Given a list of new item hashes in ITEMS, send a twitter status
   update for each of them consisting of the :title string and a tiny
@@ -61,13 +66,9 @@
   (when items
     (let [item (first items)]
       (println (:title item))
-      (update-twitter-status
-       (format "%s %s"
-               (:title item)
-               (:body (http/simple-http-request
-                       (format "http://tinyurl.com/api-create.php?url=%s"
-                               (:guid item))
-                       nil))))
+      (update-twitter-status (format "%s %s"
+                                     (:title item)
+                                     (make-tiny-url (:guid item))))
       (recur (rest items)))))
 
 (defn load-feed





More information about the Bknr-cvs mailing list