SHOW:
|
|
- or go back to the newest paste.
| 1 | (ns api.core | |
| 2 | (:require [clj-http.client :as client]) | |
| 3 | (:require [cheshire.core :refer :all]) | |
| 4 | (:require [clojure.string :as str])) | |
| 5 | ||
| 6 | (def all-categories | |
| 7 | - | (let [resp (client/get |
| 7 | + | (-> (client/get |
| 8 | - | "http://companapi.com/categories/all" |
| 8 | + | "http://companapi.com/categories/all" |
| 9 | - | { :query-params
|
| 9 | + | {:query-params {:format "json"}})
|
| 10 | - | {
|
| 10 | + | :body |
| 11 | - | :format "json" |
| 11 | + | (parse-string true) |
| 12 | - | }}) |
| 12 | + | :categories)) |
| 13 | - | categories (:categories (parse-string (:body resp) true))] |
| 13 | + | |
| 14 | - | categories |
| 14 | + | |
| 15 | - | )) |
| 15 | + | |
| 16 | (let [query' (str/lower-case query)] | |
| 17 | (for [children (:children categories) | |
| 18 | c children | |
| 19 | - | (let [subcats (flatten (map (fn [category] (get-in category [:children])) categories)) |
| 19 | + | :when (.contains (str/lower-case (:name c)) query')) |
| 20 | - | query' (str/lower-case query) |
| 20 | + | c))) |