(ns lcmap.clownfish.state
  (:require [cheshire.core :as json]
            [clojure.java.io :as io]
            [clojure.string :as str]
            [clojure.tools.logging :as log]
            [lcmap.clownfish.config :refer [config]]
            [mount.core :refer [defstate] :as mount]
            [org.httpkit.client :as http]))

(defmulti retrieve (fn [url]
                     (if (str/starts-with?
                          (str/lower-case url) "http")
                       :http
                       :local)))

(defmethod retrieve :http [url]
  (-> @(http/request {:url url
                      :method :get
                      :headers {"Accept" "application/json"}})
      (:body)))

(defmethod retrieve :local [url]
  (-> url io/resource slurp (json/decode true)))

(defstate tile-specs
  ;:start {:tile_x 10 :tile_y 10 :shift_x 0 :shift_y 0})
  :start (let [url (get-in config [:state :tile-specs-url])]
           (log/debug "Loading tile-specs")
           (try
             (retrieve url)
             (catch Exception e
               (log/errorf e "Could not load tile-specs from: %s" url)
               (throw e)))))

(ns lcmap.clownfish.state
  (:require [cheshire.core :as json]
            [clojure.java.io :as io]
            [clojure.string :as str]
            [clojure.tools.logging :as log]
            [lcmap.clownfish.config :refer [config]]
            [mount.core :refer [defstate] :as mount]
            [org.httpkit.client :as http]))

(defmulti retrieve (fn [url]
                     (if (str/starts-with?
                          (str/lower-case url) "http")
                       :http
                       :local)))

(defmethod retrieve :http [url]
  (-> @(http/request {:url url
                      :method :get
                      :headers {"Accept" "application/json"}})
      (:body)))

(defmethod retrieve :local [url]
  (-> url io/resource slurp))

(defstate tile-specs
  ;:start {:tile_x 10 :tile_y 10 :shift_x 0 :shift_y 0})
  :start (let [url (get-in config [:state :tile-specs-url])]
           (log/debug "Loading tile-specs")
           (try
             (-> url retrieve (json/decode true))
             (catch Exception e
               (log/errorf e "Could not load tile-specs from: %s" url)
               (throw e)))))

Stop horsing around, part 2.
Stop horsing around, part 2.

USGS-EROS/lcmap-changes,USGS-EROS/lcmap-changes,USGS-EROS/lcmap-changes,USGS-EROS/lcmap-changes