/
github_helper.clj
72 lines (54 loc) · 2.08 KB
/
github_helper.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(ns pinkgorilla.explore.github-helper
(:require
[clojure.string]
[tentacles.repos]
[tentacles.gists]
[tentacles.search]
[tentacles.core :only [api-call no-content?]]
[tentacles.data]
[tentacles.oauth]
[tentacles.users]
[throttler.core :refer [throttle-chan throttle-fn fn-throttler]]
[clojure.pprint]))
;; gist url format:
;; https://gist.github.com/santisbon/2e1e9c69b58bdf4c9624219a44d40d83
;; SEARCH ON GITHUB;
;; The github api requires to SPECIFY A REPO or a USER.
;; https://api.github.com/search/code?q=addClass+in:file+language:js+repo:jquery/jquery"
;; The UI allows to search without specifying a REPO or USER:
;; https://github.com/search?l=Clojure&q=gorilla-repl+fileformat&type=Code
;; https://developer.github.com/v3/rate_limit/
;; https://developer.github.com/apps/building-github-apps/understanding-rate-limits-for-github-apps/
; requests/hour
; REST SEARCH
; authenticated 5000 30
; unauthenticated 60 10
; Override raw github fetch functions with throttled versions
(def throttle? false)
(if throttle?
(do
(def throttler-rest (fn-throttler 50 :hour))
(def throttler-search (fn-throttler 8 :hour))
; REPO Throttling
(def user-repos (throttler-rest tentacles.repos/user-repos))
(def tags (throttler-rest tentacles.repos/tags))
; GIST Throttling
(def user-gists (throttler-rest tentacles.gists/user-gists))
(def specific-gist (throttler-rest tentacles.gists/specific-gist))
; SEARCH Throttling
(def search-code (throttler-search tentacles.search/search-code)))
(do ; UNTHROTTLED
; REPO
(def user-repos tentacles.repos/user-repos)
(def tags tentacles.repos/tags)
; GIST
(def user-gists tentacles.gists/user-gists)
(def specific-gist tentacles.gists/specific-gist)
; SEARCH
(def search-code tentacles.search/search-code)
; OAUTH
(def me tentacles.users/me)))
(defn username [token]
(:login (me {:oauth-token token})))
; For oauth use :oauth-token <token>
; for oauth2, include :client-id <client_id> :client-token <client_token> in the options map.