Skip to content

Commit

Permalink
Added function osf_ls_preprints to list all preprints associated with…
Browse files Browse the repository at this point in the history
… a user (see https://developer.osf.io/#operation/users_preprints_list). Also added back-end function .osf_user_preprints to make the required API call
  • Loading branch information
saudiwin committed Jan 10, 2025
1 parent 67315ad commit 71be3ba
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions R/api-endpoints-osf.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
48 changes: 48 additions & 0 deletions R/osf_ls_preprints.R
Original file line number Diff line number Diff line change
@@ -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")
}
42 changes: 42 additions & 0 deletions man/osf_ls_preprints.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71be3ba

Please sign in to comment.