Source

dude-remember / src / tropo.clj

Full commit
(ns tropo
  (:gen-class :extends javax.servlet.http.HttpServlet)
  (:use appengine.datastore
        appengine.users 
        clojure.contrib.prxml
        [clojure.contrib.json :only [json-str]]
        [clojure.contrib.io :only [slurp*]]
        compojure.core
        hiccup.core
        hiccup.form-helpers
        hiccup.page-helpers
        ring.util.response
        ring.util.servlet)
  (:require [compojure.route :as route]
            [clojure.contrib.logging :as log]))

(def *title* "Tropo Playground")

(defn header-link []
  (if (nil? (current-user))
    [:a {:href (login-url "/")} "Login"]
    [:a {:href (logout-url "/")} "Logout"]))

(def *jquery-url* 
  "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js")

(defn page [& content]
  (html
    [:head
     (include-css "/static/site.css")
     (include-js *jquery-url*)
     (include-js "/static/site.js")
     [:title *title*]]
    [:body 
     [:div {:class "header"} (header-link)]
     [:h1 *title*]
     content]))


(defn tropo-resonse [& params]
  (json-str {:tropo [{:say [{:value "OMG, it works!"}]} {:hangup nil}]}))

(defn tropo-sms [params]
  (log/info (str "SMS: " params))
  (tropo-resonse))

(defn tropo-voice [params]
  (log/info (str "VOICE: " params))
  (tropo-resonse))

(defn welcome-page []
  (page "Playing with Tropo"))

(defroutes tropo-routes
  (GET "/" [] (welcome-page))

  (POST "/tropo/sms" {params :params} (tropo-sms params))
  (POST "/tropo/voice" {body :body} (tropo-voice (slurp* body)))

; Uncomment these when debugging, *don't* let them slip to production           
;  (GET "/_eval" [] (eval-page "0"))
;  (POST "/_eval" {params :params} (eval-page (params "expr")))

  (route/not-found "Dude! I can't find it."))

(defservice tropo-routes)