forked from hadley/r-on-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.r
31 lines (26 loc) · 698 Bytes
/
requests.r
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
library(httr)
user <- Sys.getenv("GITHUB_USER")
pwd <- Sys.getenv("GITHUB_PASS")
if (user == "" || pwd == "") {
stop("Set GITHUB_USER and GITHUB_PASS env vars", call. = FALSE)
}
# install_github("rgithub", "cscheid")
base <- "https://api.github.com"
config <- c(
authenticate(user, pwd, type = "basic"),
add_headers(Accept = "application/vnd.github.preview"))
rate_limit <- function() {
content(GET("https://api.github.com/rate_limit", config))
}
github_get <- function(...) {
req <- GET(..., config = config)
c <- content(req)
if (req$status_code != 200) {
if (length(c) == 0) {
stop(req$status)
} else {
stop(c$message, call. = FALSE)
}
}
c
}