 (ns icecap.rest
   "The REST API for icecap."
-  (:require [clojure.core.async :refer [<!! <! go] :as async]
-            [compojure.core :refer [defroutes context GET POST DELETE]]
+  (:require [compojure.core :refer [defroutes context GET POST DELETE]]
             [icecap.codec :refer [safebase64-encode safebase64-decode]]
             [taoensso.timbre :refer [info spy]]
             [icecap.api :refer :all]

(defroutes routes
  (context "/v0/caps" {components :components}
    (POST "/" {plan :body-params :as request}
      (info request)
      (let [ch (create-cap (spy plan) components)
            {:keys [cap error]} (<!! ch)]
        (if cap
          {:status 201
           :body {:cap (cap-url request cap)}}

    (context "/:encoded-cap" [encoded-cap]
      (GET "/" request
        (let [cap (safebase64-decode encoded-cap)]
          (spy @(execute-cap cap components))))
      (DELETE "/" request
        (let [cap (safebase64-decode encoded-cap)]
          (spy @(revoke-cap cap components)))))))

(defn ^:private wrap-components
  "Adds some components to each request map."
