diff --git a/NAMESPACE b/NAMESPACE index 4ef1aa1..ec2c767 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ S3method(osf_ls_files,osf_tbl_file) S3method(osf_ls_files,osf_tbl_node) S3method(osf_ls_nodes,osf_tbl_node) S3method(osf_ls_nodes,osf_tbl_user) +S3method(osf_ls_preprints,osf_tbl_user) S3method(osf_mkdir,osf_tbl_file) S3method(osf_mkdir,osf_tbl_node) S3method(osf_mv,osf_tbl_file) @@ -33,6 +34,7 @@ export(osf_create_project) export(osf_download) export(osf_ls_files) export(osf_ls_nodes) +export(osf_ls_preprints) export(osf_mkdir) export(osf_mv) export(osf_open) diff --git a/R/api-endpoints-osf.R b/R/api-endpoints-osf.R index 9bf941c..1f972fe 100644 --- a/R/api-endpoints-osf.R +++ b/R/api-endpoints-osf.R @@ -121,3 +121,15 @@ path <- sprintf("users/%s/nodes/", id) .osf_paginated_request("get", path, query, n_max = n_max, verbose = verbose) } + +#' List the preprints a user is a contributor to +#' @param id a user's GUID +#' @inheritParams .osf_node_children +#' @return An entity collection with entities sorted by `date_modified` +#' @references +#' https://developer.osf.io/#operation/users_preprints_list +#' @noRd +.osf_user_preprints <- function(id, n_max, query = list(), verbose = FALSE) { + path <- sprintf("users/%s/preprints/", id) + .osf_paginated_request("get", path, query, n_max = n_max, verbose = verbose) +} diff --git a/R/osf_ls_preprints.R b/R/osf_ls_preprints.R new file mode 100644 index 0000000..257c116 --- /dev/null +++ b/R/osf_ls_preprints.R @@ -0,0 +1,48 @@ +#' List preprints from a specific user +#' +#' List the preprints that are associated with a specific user. +#' Note that will return *all* preprints, unlike [osf_ls_nodes()]. +#' +#' @param x one of the following: +#' * An [`osf_tbl_user`] with a single OSF user. +#' @template filter-pattern +#' @template n_max +#' @template verbose +#' +#' @return An [`osf_tbl_node`] with one row for each OSF preprint +#' ordered by modification time. +#' @examples +#' \dontrun{ +#' # List your recent projects and components +#' osf_retrieve_user("me") %>% +#' osf_ls_preprints() +#' } +#' @seealso [`osf_ls_nodes()`] to generate a list of all project components. +#' @export +osf_ls_preprints <- + function(x, + pattern = NULL, + n_max = 10, + verbose = FALSE) { + UseMethod("osf_ls_preprints") +} + +#' @export +osf_ls_preprints.osf_tbl_user <- + function(x, + pattern = NULL, + n_max = 10, + verbose = FALSE) { + + x <- make_single(x) + + out <- .osf_user_preprints( + id = as_id(x), + n_max = n_max, + query = filter_nodes(pattern = pattern), + verbose = verbose + ) + + raise_error(out) + as_osf_tbl(out, "osf_tbl_node") +} diff --git a/man/osf_ls_preprints.Rd b/man/osf_ls_preprints.Rd new file mode 100644 index 0000000..2383ade --- /dev/null +++ b/man/osf_ls_preprints.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/osf_ls_preprints.R +\name{osf_ls_preprints} +\alias{osf_ls_preprints} +\title{List preprints from a specific user} +\usage{ +osf_ls_preprints(x, pattern = NULL, n_max = 10, verbose = FALSE) +} +\arguments{ +\item{x}{one of the following: +\itemize{ +\item An \code{\link{osf_tbl_user}} with a single OSF user. +}} + +\item{pattern}{Character string used to filter for results that contain the +substring \code{"pattern"} in their name. \emph{Note:} this is a fixed, case-insensitive +search.} + +\item{n_max}{Maximum number of results to return from OSF (default is 10). +Set to \code{Inf} to return \emph{all} results.} + +\item{verbose}{Logical, indicating whether to print informative messages +about interactions with the OSF API (default \code{FALSE}).} +} +\value{ +An \code{\link{osf_tbl_node}} with one row for each OSF preprint +ordered by modification time. +} +\description{ +List the preprints that are associated with a specific user. +Note that will return \emph{all} preprints, unlike \code{\link[=osf_ls_nodes]{osf_ls_nodes()}}. +} +\examples{ +\dontrun{ +# List your recent projects and components +osf_retrieve_user("me") \%>\% + osf_ls_preprints() +} +} +\seealso{ +\code{\link[=osf_ls_nodes]{osf_ls_nodes()}} to generate a list of all project components. +}