Created
August 16, 2014 07:28
-
-
Save lynxluna/bade20511bc11225244f to your computer and use it in GitHub Desktop.
Rather Incomplete Github Wrapping Example from kohsuke's Java Github Library
This file contains hidden or 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
;; Depends on | |
;; [org.kohsuke.github-api "1.56"] | |
;; [clj-time "0.8.0"] | |
;; Samples converting kohsuke's GH* objects to clojure map | |
;; may inefficient but it works | |
(ns com.ykode.social.github | |
(:import [org.kohsuke.github GitHub GHMyself GHUser GHRepository] | |
[java.net URL]) | |
(:require [clj-time.format :as tf] | |
[clj-time.coerce :as tc])) | |
(defn client | |
"Creating new client based on Access Token" | |
[access_token] | |
(GitHub/connectUsingOAuth access_token)) | |
(defn- gh->datetime | |
"DateTime String of Github to DateTime object" | |
[^String date-time-str] | |
(tf/parse (tf/formatters :date-time-no-ms) date-time-str)) | |
(defn- repoObj->map [^GHRepository repo] | |
"Repo Object to Clojure Map" | |
{:name (.getName repo) | |
:created_at (tc/from-date (.getCreatedAt repo)) | |
:description (.getDescription repo) | |
:transport_urls (interleave [:git :http :ssh] | |
[(.getGitTransportUrl repo) | |
(.gitHttpTransportUrl repo) | |
(.getSshUrl repo)]) | |
:home_page (.getHomepage repo) | |
:language (.getLanguage repo) | |
:master_branch (.getMasterBranch repo) | |
:network_count (.getNetworkCount repo) | |
:pushed_at (tc/from-date (.getPushedAt repo)) | |
:size (.getSize repo) | |
:subscribers_count (.getSubscribersCount repo) | |
:admin? (.hasAdminAccess repo) | |
:downloads? (.hasDownloads repo) | |
:issues? (.hasIssues repo) | |
:wiki? (.hasWiki repo) | |
:private? (.isPrivate repo) | |
:fork? (.isFork repo)}) | |
(defn- reposObj->map | |
"Repositories collections to map collections" | |
[^java.util.Collections$UnmodifiableMap reposCollections] | |
(let [repoKeys (.keySet reposCollections) | |
repoVals (.values reposCollections)] | |
(interleave (map keyword repoKeys) (map repoObj->map repoVals)))) | |
(defn me | |
"Getting My Data" | |
[^GitHub gh] | |
(let [^GHMyself my (.getMyself gh)] | |
{:avatar_url (URL. (.getAvatarUrl my)) | |
:blog (URL. (.getBlog my)) | |
:company (.getCompany my) | |
:created_at (gh->datetime (.getCreatedAt my)) | |
:email (.getEmail my) | |
:followers_count (.getFollowersCount my) | |
:following_count (.getFollowingCount my) | |
:gravatar_id (.getGravatarId my) | |
:html_url (URL. (.getHtmlUrl my)) | |
:id (.getId my) | |
:location (.getLocation my) | |
:login (.getLogin my) | |
:name (.getName my) | |
:public_repo_count (.getPublicRepoCount my) | |
:public_gist_count (.getPublicGistCount my) | |
:repositories (delay (reposObj->map (.getAllRepositories my)))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment