View difference between Paste ID: 7q8fv0JA and FmcLrxtT
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
  (-> (client/get
8
        "http://companapi.com/categories/all"
9
        {:query-params {:format "json"}})
10
      :body
11
      (parse-string true)
12
      :categories))
13
14
;; get list of all categories matching query
15
(defn find-categories [query categories]
16
  (let [query' (str/lower-case query)]
17-
    (for [children (:children categories)
17+
    (for [cat categories
18-
          c children
18+
          c (:children cat)
19
	  :when (.contains (str/lower-case (:name c)) query'))
20
      c)))