Advertisement
Guest User

Untitled

a guest
Aug 12th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
  8.               "http://companapi.com/categories/all"
  9.               { :query-params
  10.                {
  11.                 :format "json"
  12.                 }})
  13.         categories (:categories (parse-string (:body resp) true))]
  14.     categories
  15.     ))
  16.  
  17. ;; get list of all categories matching query
  18. (defn find-categories [query categories]
  19.   (let [subcats (flatten (map (fn [category] (get-in category [:children])) categories))
  20.         query' (str/lower-case query)
  21.         categories' (filter (fn [c] (.contains (str/lower-case (:name c)) query')) subcats)]
  22.     categories'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement