# HG changeset patch # User Steve Losh # Date 1317257325 14400 # Node ID 822c779f0d53b8184631d7dd741ebfdeb8fe9ea5 # Parent c4dd32a41ba81ddaafad784244dba2d976ce336e Formatting mostly. diff -r c4dd32a41ba8 -r 822c779f0d53 src/newseasons/templates/main.clj --- a/src/newseasons/templates/main.clj Wed Sep 28 20:41:47 2011 -0400 +++ b/src/newseasons/templates/main.clj Wed Sep 28 20:48:45 2011 -0400 @@ -4,6 +4,8 @@ hiccup.page-helpers hiccup.form-helpers)) + +; Utils ----------------------------------------------------------------------- (defn include-less [href] [:link {:rel "stylesheet/less" :type "text/css" :href href}]) @@ -12,6 +14,7 @@ (fieldfn field-name))) +; Layout ---------------------------------------------------------------------- (defpartial base [& content] (html5 [:head @@ -36,6 +39,8 @@ [:h2.sixteen.columns title] content)) + +; Pages ----------------------------------------------------------------------- (defpartial home [] (base [:div.six.columns @@ -61,6 +66,7 @@ [:div.eight.columns [:p "You're not currently waiting for any shows."]])) + (defpartial result [r] [:li [:h3 (link-to (r "artistViewUrl") (r "artistName"))] diff -r c4dd32a41ba8 -r 822c779f0d53 src/newseasons/views/main.clj --- a/src/newseasons/views/main.clj Wed Sep 28 20:41:47 2011 -0400 +++ b/src/newseasons/views/main.clj Wed Sep 28 20:48:45 2011 -0400 @@ -5,28 +5,39 @@ (:require [clj-http.client :as client]) (:use [cheshire.core :only (parse-string)])) + (def email-regex #"[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}") +; Home ------------------------------------------------------------------------ (defpage [:get "/"] [] (t/home)) (defpage [:post "/"] [] (t/home)) + +; User ------------------------------------------------------------------------ (defpage [:get ["/:email" :email email-regex]] {:keys [email]} (t/user email)) -; TODO: Images. + +; 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]} - (let [results ((parse-string (:body (client/get "http://itunes.apple.com/search" - {:query-params {"term" query - "media" "tvShow" - "entity" "tvSeason" - "attribute" "showTerm"}}))) - "results") + ; TODO: Images. + (let [results (search-itunes query) artists (distinct (map #(select-keys % ["artistName" "artistId" "artistViewUrl"]) results))] (t/search query artists))) + +; Add ------------------------------------------------------------------------- (defpage [:post "/add"] {:as show} (resp/redirect "/"))