Skip to content

Instantly share code, notes, and snippets.

@akjetma
Last active January 12, 2020 09:45
Show Gist options
  • Save akjetma/1719ae04ba7ce827dfa6 to your computer and use it in GitHub Desktop.
Save akjetma/1719ae04ba7ce827dfa6 to your computer and use it in GitHub Desktop.
(require '[org.httpkit.client :as h]
'[clojure.data.json :as json]
'[clojure.string :as string])
(def base-url "http://challenge.shopcurbside.com")
(def session-url (str base-url "/get-session"))
(defn get-session
[]
@(h/get session-url))
(defn get-clue
[session leaf]
@(h/get (str base-url "/" leaf)
{:headers {"Session" session}}))
(defn parse-clue
[clue]
(json/read-str
(:body clue)
:key-fn (comp keyword string/lower-case)))
(defn traverse
([] (apply str (traverse "start")))
([leaf]
(let [session (:body (get-session))
clue (get-clue session leaf)
{:keys [depth secret next]} (parse-clue clue)]
(cond
(not (empty? secret)) [secret]
(sequential? next) (apply concat (pmap traverse next))
(string? next) (traverse next)
:else []))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment