Advertisement
Guest User

ClojureScript Hacker News API

a guest
Sep 17th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defonce stories (atom []))
  2.  
  3. (defn handle-story-data [resp]
  4.   (let [{:keys [id title url]} resp]
  5.     (swap! stories conj {:id id :title title :url url})))
  6.  
  7. (defn get-story-data [id]
  8.   (GET (str "https://hacker-news.firebaseio.com/v0/item/" id ".json")
  9.        {:handler handle-story-data
  10.         :response-format :json
  11.         :keywords? true}))
  12.  
  13. (defn handle-story-ids [resp]
  14.   (let [ids (take 30 resp)]
  15.     (doseq [id ids]
  16.       (get-story-data id))))
  17.  
  18. (defn get-story-ids []
  19.   (GET "https://hacker-news.firebaseio.com/v0/topstories.json"
  20.        {:handler handle-story-ids
  21.         :response-format :json}))
  22.  
  23. (get-story-ids)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement