-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bindings to list registered directories.
- Loading branch information
Showing
7 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#' List registered directories | ||
#' | ||
#' List the directories that were registered in SewerRat. | ||
#' | ||
#' @param url String containing the URL of the SewerRat REST API. | ||
#' @param user String containing the name of a user. | ||
#' If supplied, results are filtered to directories registered by this user. | ||
#' If \code{TRUE}, this is set to the current user. | ||
#' | ||
#' @author Aaron Lun | ||
#' | ||
#' @return List of named lists, where each inner list corresponds to a registered directory and contains: | ||
#' \itemize{ | ||
#' \item \code{path}, string containing a path to the directory. | ||
#' \item \code{user}, string containing the name of the user who registered this directory. | ||
#' \item \code{time}, numeric scalar specifying the the Unix epoch time when this directory was registered. | ||
#' \item \code{names}, a character vector containing the base names of the JSON files to be indexed. | ||
#' } | ||
#' | ||
#' @examples | ||
#' # Starting up an example SewerRat service: | ||
#' info <- startSewerRat() | ||
#' | ||
#' # Mocking up a directory of stuff to query. | ||
#' mydir <- tempfile() | ||
#' dir.create(mydir) | ||
#' write(file=file.path(mydir, "metadata.json"), '{ "first": "Aaron", "last": "Lun" }') | ||
#' dir.create(file.path(mydir, "diet")) | ||
#' write(file=file.path(mydir, "diet", "metadata.json"), | ||
#' '{ "meal": "lunch", "ingredients": "water" }') | ||
#' | ||
#' # Registering it: | ||
#' register(mydir, "metadata.json", url=info$url) | ||
#' | ||
#' # List the registered directories: | ||
#' listRegisteredDirectories(url=info$url) | ||
#' listRegisteredDirectories(url=info$url, user=TRUE) | ||
#' | ||
#' @export | ||
#' @import httr2 | ||
listRegisteredDirectories <- function(url, user=NULL) { | ||
url <- paste0(url, "/registered") | ||
|
||
if (isTRUE(user)) { | ||
user <- Sys.info()["user"] | ||
} | ||
if (!is.null(user) && !isFALSE(user)) { | ||
url <- paste0(url, "?user=", user) | ||
} | ||
req <- request(url) | ||
req <- handle_error(req) | ||
res <- req_perform(req) | ||
resp_body_json(res) | ||
} | ||
|
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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