6c5f45712535

Refactor itunes.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 28 Sep 2011 21:01:32 -0400
parents e10e3e94781d
children 8d6cf4d81909
branches/tags (none)
files src/newseasons/views/main.clj

Changes

--- a/src/newseasons/views/main.clj	Wed Sep 28 20:51:41 2011 -0400
+++ b/src/newseasons/views/main.clj	Wed Sep 28 21:01:32 2011 -0400
@@ -8,6 +8,27 @@
 
 (def email-regex #"[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}")
 
+(defn itunes-search [params]
+  ((parse-string (:body (client/get "http://itunes.apple.com/search"
+                                    {:query-params params})))
+     "results"))
+
+(defn itunes-search-show [query]
+  (itunes-search {"term" query
+                  "media" "tvShow"
+                  "entity" "tvSeason"
+                  "attribute" "showTerm"}))
+
+
+(defn itunes-lookup [field id]
+  ((parse-string (:body (client/get "http://itunes.apple.com/search"
+                                    {:query-params {field id}})))
+     "results"))
+
+(defn itunes-lookup-artist [id]
+  (itunes-lookup "id" id))
+
+
 ; Home ------------------------------------------------------------------------
 (defpage [:get "/"] []
          (t/home))
@@ -22,17 +43,10 @@
 
 
 ; Search ----------------------------------------------------------------------
-(defn search-itunes [query]
-  ((parse-string (:body (client/get "http://itunes.apple.com/search"
-                                    {:query-params {"term" query
-                                                    "media" "tvShow"
-                                                    "entity" "tvSeason"
-                                                    "attribute" "showTerm"}})))
-     "results"))
 
 (defpage [:get "/search"] {:keys [query]}
          ; TODO: Images.
-         (let [results (search-itunes query)
+         (let [results (itunes-search-show query)
                artists (distinct (map #(select-keys % ["artistName" "artistId" "artistViewUrl"])
                                       results))]
            (t/search query artists)))