Last active
December 28, 2015 21:19
-
-
Save richhollis/7563637 to your computer and use it in GitHub Desktop.
Clojure GitHub API Homework
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
(ns crash-course-github | |
(:require [clj-http.client :as http] | |
[cheshire.core :refer [parse-string]] | |
[clojure.pprint :refer [pprint]])) | |
(use 'crash-course-github) | |
(defn query-github | |
"Run an arbitrary query against Github API." | |
[query] | |
(parse-string (:body (http/get "https://api.github.com/users/richhollis/repos" | |
{:query-params {:q query}})) | |
true)) | |
(def github-data | |
(query-github nil) | |
;(eval (read-string (slurp "/home/rich/ACrashCourseInClojure/src/crash_course_clojure/github-data"))) ; load map from text file or comment out and use above line | |
) | |
(def github-data-mapped | |
(map (fn [repo] { | |
:name (repo :name) | |
:stargazers_count (repo :stargazers_count) | |
:language (repo :language) | |
}) github-data) | |
) | |
(def reverse-list-map | |
(reverse (sort-by :stargazers_count github-data-mapped)) | |
) | |
; Ruby repos sorted by stargazer count | |
(filter (fn[x] (= "JavaScript" (x :language))) reverse-list-map) |
Author
richhollis
commented
Nov 20, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment