# DEVELOP FUNCTIONS TO:
# dir_ls
# browse
# download
# read
# view
# TODO: Adapt the api to behave as fs::dir_ls()
gh_dir <- function(owner, repo = NULL, path = NULL) {
if (is.null(repo)) {
path_request <- glue::glue("/users/{owner}/repos")
out <- fs::path(owner, purrr::map_chr(gh::gh(path_request), "name"))
return(gh_url(out))
}
if (is.null(path)) {
path_request <- glue::glue("/repos/{owner}/{repo}/contents/")
out <- fs::path(owner, repo, purrr::map_chr(gh::gh(path_request), "name"))
return(gh_url(out))
}
path_request <- glue::glue("/repos/{owner}/{repo}/contents/{path}")
out <- fs::path(
owner,
repo,
"tree/master/",
path,
purrr::map_chr(gh::gh(path_request), "name")
)
gh_url(out)
}
gh_url <- function(x) {
paste0("https://github.com/", x)
}
gh_dir("forestgeo")
gh_dir("forestgeo", "fgeo.biomass")
gh_dir("forestgeo", "fgeo.biomass", "R")
gh_dir("forestgeo", "fgeo.x", "revdep/checks/fgeo.analyze")
gh_dir("forestgeo", "Climate", "Met_Station_Data/SCBI/ForestGEO_met_station-SCBI/")