# Get all gists
## Only getting the 1st file in each gist
library(httr)
library(tidyverse)
library(plyr)
url <- "https://api.github.com"
user <- "cecilialee"
r <- GET(sprintf("%s/users/%s/gists", url, user))
gists <- content(r)
get_gists <- function(gist) {
filename <- gist$files[[1]]$filename
raw_url <- gist$files[[1]]$raw_url
list(filename = filename, raw_url = raw_url)
}
get_content <- function(raw_url) {
r <- GET(as.character(raw_url))
content(r)
}
all_gists <- ldply(lapply(gists, get_gists), data.frame)
scripts <- sapply(all_gists$raw_url, get_content)
all_gists$script <- scripts
# Get a single gist
library(httr)
url <- "https://api.github.com"
user <- "cecilialee"
r <- GET(sprintf("%s/users/%s/gists", url, user))
gists <- content(r)
raw_url <- gists[[1]]$files[[1]]$raw_url
r <- GET(raw_url)
script <- content(r)
cat(script)