   (:require [aleph.http                 :as http]
             [ring.util.codec            :as codec]
             [org.spootnik.cyanite.store :as store]
+            [org.spootnik.cyanite.path  :as path]
             [cheshire.core              :as json]
             [lamina.core                :refer [enqueue]]
             [clojure.string             :refer [lower-case]]

(defn start
  "Start the API, handling each request by parsing parameters and
   routes then handing over to the request processor"
  [{:keys [http store carbon] :as config}]
  (let [handler (fn [chan request]
                  (-> request
                      (assoc-params)
                      (assoc-route)
                      (wrap-process (:rollups carbon) chan store)))]
    (http/start-http-server handler http))
  nil)

  :action)

(defmethod process :paths
  [{{:keys [index query]} :params :as request}]
  (path/search index "" (str query ".*")))

(defmethod process :metrics
  [{{:keys [index from to path agg]} :params :keys [store rollups]}]
  (debug "fetching paths: " path)
  (if-let [{:keys [rollup period]} (find-best-rollup from rollups)]
    (let [to    (if to (Long/parseLong to) (now))
          from  (Long/parseLong from)
          paths (mapcat (partial path/search index "")
                        (if (sequential? path) path [path]))]
      (store/fetch store (or agg "mean") paths "" rollup period from to))
    {:step nil :from nil :to nil :series {}}))

(defmethod process :ping
