Last active
January 12, 2020 09:45
-
-
Save akjetma/1719ae04ba7ce827dfa6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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