Skip to content

Instantly share code, notes, and snippets.

@sjolsen
Last active August 29, 2015 14:16
Show Gist options
  • Save sjolsen/62294575580db3ee5408 to your computer and use it in GitHub Desktop.
Save sjolsen/62294575580db3ee5408 to your computer and use it in GitHub Desktop.
(ql:quickload :cl-json)
(ql:quickload :drakma)
(defvar *github-auth* nil)
(defvar *print-columns* nil)
(defun format-repo (*standard-output* repo colon at &rest params)
(declare (ignorable colon at))
(let* ((name (cdr (assoc :NAME repo)))
(lang (cdr (assoc :LANGUAGE repo)))
(indent (1+ (or (first params)
(first *print-columns*)
(length name)))))
(format t "~A~vT~A" name indent lang)))
(defun format-repos (repos)
(let ((*print-columns* (list (loop
for repo in repos
for name = (cdr (assoc :NAME repo))
maximizing (length name)))))
(format t "~{~/format-repo/~%~}" repos)))
(defun api-url (&rest path-components)
(format nil "https://api.github.com~{/~A~}" path-components))
(defun api-get (url)
(let ((json:*json-input* (drakma:http-request url
:want-stream t
:basic-authorization *github-auth*)))
(json:decode-json)))
(defun get-user (username)
(api-get (api-url "users" username)))
(defun get-repos (user)
(api-get (cdr (assoc :REPOS--URL user))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment